Skip to content

Commit

Permalink
Package Archives:
Browse files Browse the repository at this point in the history
- fix security arbitrary path
- fix linter

Package AWS:
- implement resolver v2

Package Cobra:
- fix linter

Package Config/component:
- fix linter

Package Context/Config:
- Add function to set context

Package Database/KV...:
- Fix error
- Fix collision pointer
- Fix models
- Fix circular dependencies
- Add function Delete on driver, table and item
- Add function new on drvier to prevent collision data when create item on table get / walk

Package Duration:
- Add type Duration based on time.Duration to allow transform duration to string instead of int64 nanosecond
- Add function to parse in json, yaml, toml, text, cbor
- Add function to allow convert type into mapstructure (spf13 viper, cobra...)

Package File/Perm:
- Add type Perm based on os.FileMode to allow marshall / unmashall it into octal form instead of string representation (-rwxrwxrwx)
- Add function to marshall / unmarshall in json, yaml, toml, text, cbor
- Add function to allow convert type into mapstructure (spf13 viper, cobra...)

Package File/progress:
- Fix linter

Package HTTPServer :
- Fix linter
- Fix security by adding a default value if not set on config

Package ioutils:
- Fix Linter

Package LDAP:
- Add Clone function

Package logger/hookfile:
- Fix linter

Package nats:
- Fix linter

Package Network/Protocol:
- Fix bug with quote / Dbl Quote on unmarshall

Package Password:
- Replace password with crypto rand instead of math rand

Package Size:
- Fix potential overflow
- Add function to format value into Int32, Int, Uint32, Uint, Float32
- Add function to parse Float64 into type Size

Package Socket:
- change config uint32 to golib Size, time.Duration to golib Duration
- add TLS managment to server TCP, discard for UDP & Unix file Local Domain
- add function Info Server to print information of server when listen is starting
  • Loading branch information
nabbar committed Nov 21, 2023
1 parent b07fafb commit 97e70d0
Show file tree
Hide file tree
Showing 69 changed files with 1,633 additions and 435 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,17 @@ jobs:
continue-on-error: false
run: |
IGNORE_BUILD=$(sed '/^[[:space:]]*$/d' "build.$(go env | grep GOARCH | cut -d'=' -f2 | tr -d '"' | tr -d "'")" | tr '\n' '|')
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 GOAMD64=v4 go build -a -v -race -installsuffix cgo -ldflags "-w -s -extldflags '-static' " $(go list ./... | grep -vPi ${IGNORE_BUILD::-1})
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 GOAMD64=v4 go build -a -race -installsuffix cgo -ldflags "-w -s -extldflags '-static' " $(go list ./... | grep -vPi ${IGNORE_BUILD::-1})
- name: Test Build Windows/amd64 with CGO
continue-on-error: false
run: |
IGNORE_BUILD=$(sed '/^[[:space:]]*$/d' "build.$(go env | grep GOARCH | cut -d'=' -f2 | tr -d '"' | tr -d "'")" | tr '\n' '|')
CC=/usr/bin/x86_64-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows GOARCH=amd64 GOAMD64=v4 go build -a -v -ldflags "-w -s -extldflags '-static' " $(go list ./... | grep -vPi ${IGNORE_BUILD::-1})
CC=/usr/bin/x86_64-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows GOARCH=amd64 GOAMD64=v4 go build -a -ldflags "-w -s -extldflags '-static' " $(go list ./... | grep -vPi ${IGNORE_BUILD::-1})
- name: Test Build Darwin/arm64 with suffix/CGO
continue-on-error: false
run: |
IGNORE_BUILD=$(sed '/^[[:space:]]*$/d' "build.$(go env | grep GOARCH | cut -d'=' -f2 | tr -d '"' | tr -d "'")" | tr '\n' '|')
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 GOAMD64=v1 go build -a -v -ldflags "-w -s -extldflags '-static' " $(go list ./... | grep -vPi ${IGNORE_BUILD::-1})
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 GOAMD64=v1 go build -a -ldflags "-w -s -extldflags '-static' " $(go list ./... | grep -vPi ${IGNORE_BUILD::-1})
7 changes: 4 additions & 3 deletions archive/bz2/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ func GetFile(src io.ReadSeeker, dst io.WriteSeeker) errors.Error {

r := bzip2.NewReader(src)

//nolint #nosec
/* #nosec */
if _, e := io.Copy(dst, r); e != nil {
// #nosec
_, e := io.Copy(dst, r)

if e != nil {
return ErrorIOCopy.Error(e)
} else if _, e = dst.Seek(0, io.SeekStart); e != nil {
return ErrorFileSeek.Error(e)
Expand Down
11 changes: 6 additions & 5 deletions archive/gzip/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ import (
gz "compress/gzip"
"io"

libfpg "github.com/nabbar/golib/file/progress"

"github.com/nabbar/golib/errors"
libfpg "github.com/nabbar/golib/file/progress"
)

func GetFile(src io.ReadSeeker, dst io.WriteSeeker) errors.Error {
Expand All @@ -50,9 +49,10 @@ func GetFile(src io.ReadSeeker, dst io.WriteSeeker) errors.Error {
_ = r.Close()
}()

//nolint #nosec
/* #nosec */
if _, e = io.Copy(dst, r); e != nil {
// #nosec
_, e = io.Copy(dst, r)

if e != nil {
return ErrorIOCopy.Error(e)
} else if _, e = dst.Seek(0, io.SeekStart); e != nil {
return ErrorFileSeek.Error(e)
Expand Down Expand Up @@ -88,6 +88,7 @@ func GetGunZipSize(src io.ReadSeeker) int64 {
}

var n int64
// #nosec
n, e = io.Copy(io.Discard, r)

if e != nil {
Expand Down
7 changes: 4 additions & 3 deletions archive/tar/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ import (
"runtime"
"strings"

libfpg "github.com/nabbar/golib/file/progress"

libarc "github.com/nabbar/golib/archive/archive"
liberr "github.com/nabbar/golib/errors"
libfpg "github.com/nabbar/golib/file/progress"
)

func GetFile(src, dst libfpg.Progress, filenameContain, filenameRegex string) liberr.Error {
Expand Down Expand Up @@ -93,9 +92,11 @@ func GetAll(src io.ReadSeeker, outputFolder string, defaultDirPerm os.FileMode)
return ErrorTarNext.Error(e)
}

dst := filepath.Join(outputFolder, libarc.CleanPath(strings.Replace(h.Name, ".."+string(filepath.Separator), "", -1)))

//nolint #nosec
/* #nosec */
if err := writeContent(r, h, filepath.Join(outputFolder, libarc.CleanPath(h.Name)), defaultDirPerm); err != nil {
if err := writeContent(r, h, dst, defaultDirPerm); err != nil {
return err
}
}
Expand Down
18 changes: 10 additions & 8 deletions archive/zip/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import (
"io"
"os"
"path/filepath"

libfpg "github.com/nabbar/golib/file/progress"
"strings"

arcmod "github.com/nabbar/golib/archive/archive"
liberr "github.com/nabbar/golib/errors"
libfpg "github.com/nabbar/golib/file/progress"
)

func GetFile(src, dst libfpg.Progress, filenameContain, filenameRegex string) liberr.Error {
Expand Down Expand Up @@ -119,9 +119,10 @@ func GetAll(src libfpg.Progress, outputFolder string, defaultDirPerm os.FileMode
continue
}

//nolint #nosec
/* #nosec */
if err := writeContent(f, filepath.Join(outputFolder, arcmod.CleanPath(f.Name)), defaultDirPerm); err != nil {
dst := filepath.Join(outputFolder, arcmod.CleanPath(strings.Replace(f.Name, ".."+string(filepath.Separator), "..", -1)))

// #nosec
if err := writeContent(f, dst, defaultDirPerm); err != nil {
return err
}
}
Expand Down Expand Up @@ -175,9 +176,10 @@ func writeContent(f *zip.File, out string, defaultDirPerm os.FileMode) (err libe
return ErrorZipFileOpen.Error(e)
}

//nolint #nosec
/* #nosec */
if _, e = io.Copy(dst, r); e != nil {
// #nosec
_, e = io.Copy(dst, r)

if e != nil {
return ErrorIOCopy.Error(e)
} else if e = dst.Close(); e != nil {
return ErrorFileClose.Error(e)
Expand Down
5 changes: 4 additions & 1 deletion aws/bucket/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ package bucket
import (
"fmt"

sdkaws "github.com/aws/aws-sdk-go-v2/aws"
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
sdkstp "github.com/aws/aws-sdk-go-v2/service/s3/types"
libhlp "github.com/nabbar/golib/aws/helper"
Expand Down Expand Up @@ -64,10 +65,12 @@ func (cli *client) _create(RegionConstraint string, lockEnable bool) error {

if RegionConstraint != "" {
in.CreateBucketConfiguration.LocationConstraint = sdkstp.BucketLocationConstraint(RegionConstraint)
} else {
in.CreateBucketConfiguration.LocationConstraint = sdkstp.BucketLocationConstraint(cli.GetRegion())
}

if lockEnable {
in.ObjectLockEnabledForBucket = true
in.ObjectLockEnabledForBucket = sdkaws.Bool(true)
}

out, err := cli.s3.CreateBucket(cli.GetContext(), in)
Expand Down
26 changes: 15 additions & 11 deletions aws/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ func (c *client) _NewClientIAM(ctx context.Context, httpClient *http.Client) (*s
EndpointOptions: sdkiam.EndpointResolverOptions{
DisableHTTPS: !c.c.IsHTTPs(),
},
EndpointResolver: c._NewIAMResolver(cfg),
HTTPSignerV4: sig,
Region: cfg.Region,
Retryer: ret,
HTTPClient: httpClient,
BaseEndpoint: sdkaws.String(c.c.GetEndpoint().String()),
EndpointResolver: c._NewIAMResolver(cfg),
EndpointResolverV2: c._NewIAMResolverV2(c.c),
HTTPSignerV4: sig,
Region: cfg.Region,
Retryer: ret,
HTTPClient: httpClient,
})

return iam, nil
Expand Down Expand Up @@ -161,12 +163,14 @@ func (c *client) _NewClientS3(ctx context.Context, httpClient *http.Client) (*sd
EndpointOptions: sdksss.EndpointResolverOptions{
DisableHTTPS: !c.c.IsHTTPs(),
},
EndpointResolver: c._NewS3Resolver(cfg),
HTTPSignerV4: sig,
Region: cfg.Region,
Retryer: ret,
HTTPClient: httpClient,
UsePathStyle: c.p,
BaseEndpoint: sdkaws.String(c.c.GetEndpoint().String()),
EndpointResolver: c._NewS3Resolver(cfg),
EndpointResolverV2: c._NewS3ResolverV2(c.c),
HTTPSignerV4: sig,
Region: cfg.Region,
Retryer: ret,
HTTPClient: httpClient,
UsePathStyle: c.p,
})

return sss, nil
Expand Down
6 changes: 4 additions & 2 deletions aws/multipart/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (m *mpu) Copy(fromBucket, fromObject, fromVersionId string) error {
Bucket: sdkaws.String(bck),
CopySource: sdkaws.String(src),
Key: sdkaws.String(obj),
PartNumber: m.Counter() + 1,
PartNumber: sdkaws.Int32(m.Counter() + 1),
UploadId: sdkaws.String(mid),
CopySourceRange: sdkaws.String("bytes=" + p),
RequestPayer: sdktyp.RequestPayerRequester,
Expand Down Expand Up @@ -121,7 +121,9 @@ func (m *mpu) getCopyPart(fromBucket, fromObject, fromVersionId string) []string
return res
} else if hdo == nil || hdo.ETag == nil || len(*hdo.ETag) < 1 {
return res
} else if size := hdo.ContentLength; size < 1 {
} else if s := hdo.ContentLength; s == nil {
return res
} else if size := *s; size < 1 {
return res
} else {
var i int64 = 0
Expand Down
6 changes: 3 additions & 3 deletions aws/multipart/part.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (m *mpu) RegisterPart(etag string) {
m.n++
m.l = append(m.l, sdktyp.CompletedPart{
ETag: sdkaws.String(strings.Replace(etag, "\"", "", -1)),
PartNumber: m.n,
PartNumber: sdkaws.Int32(m.n),
})
}

Expand Down Expand Up @@ -154,8 +154,8 @@ func (m *mpu) AddPart(r io.Reader) (n int64, e error) {
Bucket: sdkaws.String(bck),
Key: sdkaws.String(obj),
UploadId: sdkaws.String(mid),
PartNumber: m.Counter() + 1,
ContentLength: n,
PartNumber: sdkaws.Int32(m.Counter() + 1),
ContentLength: sdkaws.Int64(n),
Body: tmp,
RequestPayer: sdktyp.RequestPayerRequester,
ContentMD5: sdkaws.String(hss),
Expand Down
2 changes: 1 addition & 1 deletion aws/object/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (cli *client) SetRetention(object, version string, bypass bool, until time.
}

if bypass {
in.BypassGovernanceRetention = true
in.BypassGovernanceRetention = sdkaws.Bool(true)
}

switch {
Expand Down
15 changes: 11 additions & 4 deletions aws/object/multipart.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
func (cli *client) MultipartList(keyMarker, markerId string) (uploads []sdktyp.MultipartUpload, nextKeyMarker string, nextIdMarker string, count int64, e error) {
in := &sdksss.ListMultipartUploadsInput{
Bucket: sdkaws.String(cli.GetBucketName()),
MaxUploads: 1000,
MaxUploads: sdkaws.Int32(1000),
}

if keyMarker != "" && markerId != "" {
Expand All @@ -54,10 +54,17 @@ func (cli *client) MultipartList(keyMarker, markerId string) (uploads []sdktyp.M

if err != nil {
return nil, "", "", 0, cli.GetError(err)
} else if out.IsTruncated {
return out.Uploads, *out.NextKeyMarker, *out.NextUploadIdMarker, int64(out.MaxUploads), nil
}

var maxKeys int32
if out != nil && out.MaxUploads != nil {
maxKeys = *out.MaxUploads
}

if out != nil && out.IsTruncated != nil && *out.IsTruncated {
return out.Uploads, *out.NextKeyMarker, *out.NextUploadIdMarker, int64(maxKeys), nil
} else {
return out.Uploads, "", "", int64(out.MaxUploads), nil
return out.Uploads, "", "", int64(maxKeys), nil
}
}

Expand Down
18 changes: 12 additions & 6 deletions aws/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ import (
"mime"
"path/filepath"

sdksss "github.com/aws/aws-sdk-go-v2/service/s3"

sdkaws "github.com/aws/aws-sdk-go-v2/aws"
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
sdktps "github.com/aws/aws-sdk-go-v2/service/s3/types"
libhlp "github.com/nabbar/golib/aws/helper"
)
Expand All @@ -58,10 +57,17 @@ func (cli *client) ListPrefix(continuationToken string, prefix string) ([]sdktps

if err != nil {
return nil, "", 0, cli.GetError(err)
} else if out.IsTruncated {
return out.Contents, *out.NextContinuationToken, int64(out.KeyCount), nil
}

var maxKeys int32
if out != nil && out.MaxKeys != nil {
maxKeys = *out.MaxKeys
}

if out != nil && out.IsTruncated != nil && *out.IsTruncated {
return out.Contents, *out.NextContinuationToken, int64(maxKeys), nil
} else {
return out.Contents, "", int64(out.KeyCount), nil
return out.Contents, "", int64(maxKeys), nil
}
}

Expand Down Expand Up @@ -104,7 +110,7 @@ func (cli *client) WalkPrefix(prefix string, f WalkFunc) error {
}
}

if out.IsTruncated {
if out != nil && out.IsTruncated != nil && *out.IsTruncated {
t = out.NextContinuationToken
} else {
return e
Expand Down
25 changes: 17 additions & 8 deletions aws/object/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
func (cli *client) VersionList(prefix, keyMarker, markerId string) (version []sdktps.ObjectVersion, delMarker []sdktps.DeleteMarkerEntry, nextKeyMarker, nextMarkerId string, count int64, err error) {
in := sdksss.ListObjectVersionsInput{
Bucket: cli.GetBucketAws(),
MaxKeys: 1000,
MaxKeys: sdkaws.Int32(1000),
}

if prefix != "" {
Expand All @@ -54,10 +54,17 @@ func (cli *client) VersionList(prefix, keyMarker, markerId string) (version []sd

if e != nil {
return nil, nil, "", "", 0, cli.GetError(e)
} else if out.IsTruncated {
return out.Versions, out.DeleteMarkers, *out.NextKeyMarker, *out.NextVersionIdMarker, int64(out.MaxKeys), nil
}

var maxKeys int32
if out != nil && out.MaxKeys != nil {
maxKeys = *out.MaxKeys
}

if out != nil && out.IsTruncated != nil && *out.IsTruncated {
return out.Versions, out.DeleteMarkers, *out.NextKeyMarker, *out.NextVersionIdMarker, int64(maxKeys), nil
} else {
return out.Versions, out.DeleteMarkers, "", "", int64(out.MaxKeys), nil
return out.Versions, out.DeleteMarkers, "", "", int64(maxKeys), nil
}
}

Expand All @@ -68,7 +75,7 @@ func (cli *client) VersionWalk(fv VersionWalkFunc, fd DelMakWalkFunc) error {
func (cli *client) VersionWalkPrefix(prefix string, fv VersionWalkFunc, fd DelMakWalkFunc) error {
in := sdksss.ListObjectVersionsInput{
Bucket: cli.GetBucketAws(),
MaxKeys: 1000,
MaxKeys: sdkaws.Int32(1000),
}

if prefix != "" {
Expand Down Expand Up @@ -117,7 +124,7 @@ func (cli *client) VersionWalkPrefix(prefix string, fv VersionWalkFunc, fd DelMa
}
}

if out.IsTruncated {
if out != nil && out.IsTruncated != nil && *out.IsTruncated {
km = out.NextKeyMarker
mi = out.NextVersionIdMarker
} else {
Expand Down Expand Up @@ -181,8 +188,10 @@ func (cli *client) VersionSize(object, version string) (size int64, err error) {

if h, err = cli.VersionHead(object, version); err != nil {
return
} else if h != nil && h.ContentLength != nil {
return *h.ContentLength, nil
} else {
return h.ContentLength, nil
return 0, nil
}
}

Expand All @@ -207,7 +216,7 @@ func (cli *client) VersionDeleteLock(check bool, object, version string, byPassG
}

if byPassGovernance {
in.BypassGovernanceRetention = true
in.BypassGovernanceRetention = sdkaws.Bool(true)
}

_, err := cli.s3.DeleteObject(cli.GetContext(), &in)
Expand Down
Loading

0 comments on commit 97e70d0

Please sign in to comment.