Skip to content

Commit

Permalink
Merge pull request #67 from nabbar/bump_aws_sdk
Browse files Browse the repository at this point in the history
Bump sdk-aws-go-v2 at release 0.26.0
  • Loading branch information
Nicolas JUHEL authored Oct 2, 2020
2 parents 47dc7f3 + 3671701 commit df92899
Show file tree
Hide file tree
Showing 69 changed files with 2,028 additions and 756 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ jobs:
continue-on-error: true
run: ./scripts/ci_format

- name: Check Missing License
continue-on-error: true
run: |
for PKG in $(find . -type f -name "*.go" | grep -v 'vendor/' | grep -v 'version/license_.*.go');
do
if [ "$(head -n 25 $PKG | grep -c -P '[*\s]*MIT License')" != 1 ];
then
echo "Missing Licence: $PKG";
fi;
done;
- name: Check goLinter
continue-on-error: true
run: ./scripts/ci_linter
Expand All @@ -62,7 +73,13 @@ jobs:

- name: Check tests
continue-on-error: true
run: ginkgo -cover ./...
run: |
for PKG in $(find $(pwd) -type f -name "*_suite_test.go" | sort -u );
do
cd $(dirname $PKG);
echo "testing >>> $(basename $(dirname $PKG))";
ginkgo -cover .
done
env:
GOOS: linux
CGO_ENABLED: 0
Expand Down
3 changes: 2 additions & 1 deletion archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ func ExtractAll(src ioutils.FileProgress, originalName, outputPath string, defau

logger.DebugLevel.Log("prepare output...")
if i, e := os.Stat(outputPath); e != nil && os.IsNotExist(e) {
//nolint #nosec //nosec
//nolint #nosec
/* #nosec */
if e := os.MkdirAll(outputPath, 0775); e != nil {
return ErrorDirCreate.ErrorParent(e)
}
Expand Down
3 changes: 2 additions & 1 deletion archive/bz2/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ func GetFile(src io.ReadSeeker, dst io.WriteSeeker) errors.Error {

r := bzip2.NewReader(src)

// #nosec
//nolint #nosec
/* #nosec */
if _, e := io.Copy(dst, r); e != nil {
return ErrorIOCopy.ErrorParent(e)
} else if _, e = dst.Seek(0, io.SeekStart); e != nil {
Expand Down
3 changes: 2 additions & 1 deletion archive/gzip/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func GetFile(src io.ReadSeeker, dst io.WriteSeeker) errors.Error {
_ = r.Close()
}()

// #nosec
//nolint #nosec
/* #nosec */
if _, e = io.Copy(dst, r); e != nil {
return ErrorIOCopy.ErrorParent(e)
} else if _, e := dst.Seek(0, io.SeekStart); e != nil {
Expand Down
5 changes: 4 additions & 1 deletion archive/tar/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ func GetFile(src, dst ioutils.FileProgress, filenameContain, filenameRegex strin

f := archive.NewFileFullPath(h.Name)

// #nosec
//nolint #nosec
/* #nosec */
if f.MatchingFullPath(filenameContain) || f.RegexFullPath(filenameRegex) {
if _, e := dst.ReadFrom(r); e != nil {
return ErrorIOCopy.ErrorParent(e)
Expand Down Expand Up @@ -89,6 +90,8 @@ func GetAll(src io.ReadSeeker, outputFolder string, defaultDirPerm os.FileMode)
return ErrorTarNext.ErrorParent(e)
}

//nolint #nosec
/* #nosec */
if err := writeContent(r, h, path.Join(outputFolder, h.Name), defaultDirPerm); err != nil {
return err
}
Expand Down
8 changes: 6 additions & 2 deletions archive/zip/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ func GetFile(src, dst ioutils.FileProgress, filenameContain, filenameRegex strin
_ = r.Close()
}()

// #nosec
//nolint #nosec
/* #nosec */
if _, e = dst.ReadFrom(r); e != nil {
//logger.ErrorLevel.LogErrorCtx(logger.DebugLevel, "copy buffer from archive reader", err)
return ErrorIOCopy.ErrorParent(e)
Expand Down Expand Up @@ -116,6 +117,8 @@ func GetAll(src ioutils.FileProgress, outputFolder string, defaultDirPerm os.Fil
continue
}

//nolint #nosec
/* #nosec */
if err := writeContent(f, path.Join(outputFolder, f.Name), defaultDirPerm); err != nil {
return err
}
Expand Down Expand Up @@ -164,7 +167,8 @@ func writeContent(f *zip.File, out string, defaultDirPerm os.FileMode) (err erro
return ErrorZipFileOpen.ErrorParent(e)
}

//#nosec
//nolint #nosec
/* #nosec */
if _, e := io.Copy(dst, r); e != nil {
return ErrorIOCopy.ErrorParent(e)
} else if e = dst.Close(); e != nil {
Expand Down
3 changes: 3 additions & 0 deletions artifact/s3aws/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const (
ErrorS3AWSNewVers
ErrorS3AWSNotFound
ErrorS3AWSDownloadError
ErrorS3AWSIOReaderError
)

var (
Expand Down Expand Up @@ -85,6 +86,8 @@ func getMessage(code errors.CodeError) (message string) {
return "requested version is not found"
case ErrorS3AWSDownloadError:
return "download object requested occurs error"
case ErrorS3AWSIOReaderError:
return "return io reader is empty"
}

return ""
Expand Down
21 changes: 8 additions & 13 deletions artifact/s3aws/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"regexp"
"strings"

"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/hashicorp/go-version"
"github.com/nabbar/golib/artifact"
"github.com/nabbar/golib/artifact/client"
Expand Down Expand Up @@ -196,23 +197,15 @@ func (s *s3awsModel) Download(dst ioutils.FileProgress, containName string, rege

func (s *s3awsModel) downloadObject(dst ioutils.FileProgress, object string) errors.Error {
var (
r io.ReadCloser
c []io.Closer
r *s3.GetObjectOutput
e errors.Error
i os.FileInfo
j int64
)

defer func() {
if len(c) > 0 {
for _, b := range c {
if b != nil {
_ = b.Close()
}
}
}
if r != nil {
_ = r.Close()
if r != nil && r.Body != nil {
_ = r.Body.Close()
}
}()

Expand All @@ -226,11 +219,13 @@ func (s *s3awsModel) downloadObject(dst ioutils.FileProgress, object string) err

dst.ResetMax(j)

if r, c, e = s.c.Object().Get(object); e != nil {
if r, e = s.c.Object().Get(object); e != nil {
err := ErrorS3AWSDownloadError.ErrorParent(getError(errObject, object))
err.AddParentError(e)
return err
} else if _, err := io.Copy(dst, r); err != nil {
} else if r.Body == nil {
return ErrorS3AWSIOReaderError.ErrorParent(getError(errObject, object))
} else if _, err := io.Copy(dst, r.Body); err != nil {
return ErrorS3AWSDownloadError.ErrorParent(getError(errObject, object), err)
} else if i, e = dst.FileStat(); e != nil {
err := ErrorS3AWSDownloadError.ErrorParent(getError(errObject, object))
Expand Down
8 changes: 6 additions & 2 deletions artifact/s3aws/s3aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ func NewS3AWS(ctx context.Context, cfg aws.Config, httpcli *http.Client, forceMo
}

if forceModePath {
c.ForcePathStyle(true)
e = c.ForcePathStyle(true)
} else {
c.ForcePathStyle(false)
e = c.ForcePathStyle(false)
}

if e != nil {
return nil, e
}

o := &s3awsModel{
Expand Down
49 changes: 48 additions & 1 deletion aws/aws_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
/*
* MIT License
*
* Copyright (c) 2020 Nicolas JUHEL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

package aws_test

import (
"bytes"
"context"
"crypto/rand"
"errors"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/url"
"os"
"os/exec"
Expand All @@ -18,6 +46,7 @@ import (
"github.com/hashicorp/go-uuid"
"github.com/nabbar/golib/aws"
"github.com/nabbar/golib/aws/configCustom"
"github.com/nabbar/golib/httpcli"
"github.com/nabbar/golib/password"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -46,6 +75,7 @@ var _ = BeforeSuite(func() {
var (
err error
name string
htp *http.Client
)

ctx, cnl = context.WithCancel(context.Background())
Expand All @@ -61,7 +91,11 @@ var _ = BeforeSuite(func() {
secretKey = password.Generate(64)
)

htp = httpcli.GetClient(uri.Hostname())
Expect(htp).NotTo(BeNil())

cfg = configCustom.NewConfig("", accessKey, secretKey, uri, "us-east-1")
Expect(cfg).NotTo(BeNil())

cfg.SetRegion("us-east-1")
err = cfg.RegisterRegionAws(nil)
Expand All @@ -75,10 +109,11 @@ var _ = BeforeSuite(func() {
time.Sleep(10 * time.Second)
}

time.Sleep(10 * time.Second)
println("Minio is waiting on : " + uri.Host)
}

cli, err = aws.New(ctx, cfg, nil)
cli, err = aws.New(ctx, cfg, htp)
Expect(err).NotTo(HaveOccurred())
Expect(cli).NotTo(BeNil())

Expand Down Expand Up @@ -201,3 +236,15 @@ func WaitMinio(host string) bool {

return err == nil
}

func randContent(size int) *bytes.Buffer {
p := make([]byte, size)

_, err := rand.Read(p)

if err != nil {
panic(err)
}

return bytes.NewBuffer(p)
}
Loading

0 comments on commit df92899

Please sign in to comment.