Skip to content

Commit

Permalink
Merge pull request #114 from nabbar/aws_cors_website
Browse files Browse the repository at this point in the history
Package AWS : Ajout configuration + bump ginkgo v2
Package Logger :  bump ginkgo v2
Bump dependancies
  • Loading branch information
Nicolas JUHEL authored Jan 13, 2022
2 parents e4a2af6 + 032ddb3 commit 726807c
Show file tree
Hide file tree
Showing 17 changed files with 297 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
do
cd $(dirname $PKG);
echo "testing >>> $(basename $(dirname $PKG))";
ginkgo -cover .
ginkgo run --cover .
done
env:
GOOS: linux
Expand Down
2 changes: 1 addition & 1 deletion aws/aws_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import (
"github.com/nabbar/golib/aws/configCustom"
"github.com/nabbar/golib/httpcli"
"github.com/nabbar/golib/password"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

Expand Down
62 changes: 0 additions & 62 deletions aws/bucket/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ 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 @@ -91,64 +90,3 @@ func (cli *client) List() ([]sdkstp.Bucket, liberr.Error) {

return out.Buckets, nil
}

func (cli *client) SetVersioning(state bool) liberr.Error {
var status sdkstp.BucketVersioningStatus = libhlp.STATE_ENABLED
if !state {
status = libhlp.STATE_SUSPENDED
}

_, err := cli.s3.PutBucketVersioning(cli.GetContext(), &sdksss.PutBucketVersioningInput{
Bucket: cli.GetBucketAws(),
VersioningConfiguration: &sdkstp.VersioningConfiguration{
Status: status,
},
})

return cli.GetError(err)
}

func (cli *client) GetVersioning() (string, liberr.Error) {
out, err := cli.s3.GetBucketVersioning(cli.GetContext(), &sdksss.GetBucketVersioningInput{
Bucket: cli.GetBucketAws(),
})

if err != nil {
return "", cli.GetError(err)
} else if out == nil {
return "", libhlp.ErrorResponse.Error(nil)
}

// MarshalValue always return error as nil
return string(out.Status), nil
}

func (cli *client) EnableReplication(srcRoleARN, dstRoleARN, dstBucketName string) liberr.Error {
var status sdkstp.ReplicationRuleStatus = libhlp.STATE_ENABLED

_, err := cli.s3.PutBucketReplication(cli.GetContext(), &sdksss.PutBucketReplicationInput{
Bucket: cli.GetBucketAws(),
ReplicationConfiguration: &sdkstp.ReplicationConfiguration{
Role: sdkaws.String(srcRoleARN + "," + dstRoleARN),
Rules: []sdkstp.ReplicationRule{
{
Destination: &sdkstp.Destination{
Bucket: sdkaws.String("arn:aws:s3:::" + dstBucketName),
},
Status: status,
Prefix: sdkaws.String(""),
},
},
},
})

return cli.GetError(err)
}

func (cli *client) DeleteReplication() liberr.Error {
_, err := cli.s3.DeleteBucketReplication(cli.GetContext(), &sdksss.DeleteBucketReplicationInput{
Bucket: cli.GetBucketAws(),
})

return cli.GetError(err)
}
61 changes: 61 additions & 0 deletions aws/bucket/cors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* MIT License
*
* Copyright (c) 2022 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 bucket

import (
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"
liberr "github.com/nabbar/golib/errors"
)

func (cli *client) GetCORS() ([]sdkstp.CORSRule, liberr.Error) {
out, err := cli.s3.GetBucketCors(cli.GetContext(), &sdksss.GetBucketCorsInput{
Bucket: cli.GetBucketAws(),
})

if err != nil {
return nil, cli.GetError(err)
} else if out == nil {
return nil, libhlp.ErrorResponse.Error(nil)
} else if out.CORSRules == nil || len(out.CORSRules) < 1 {
return make([]sdkstp.CORSRule, 0), nil
}

// MarshalValue always return error as nil
return out.CORSRules, nil
}

func (cli *client) SetCORS(cors []sdkstp.CORSRule) liberr.Error {
_, err := cli.s3.PutBucketCors(cli.GetContext(), &sdksss.PutBucketCorsInput{
Bucket: cli.GetBucketAws(),
CORSConfiguration: &sdkstp.CORSConfiguration{
CORSRules: cors,
},
})

return cli.GetError(err)
}
7 changes: 7 additions & 0 deletions aws/bucket/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
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"
liberr "github.com/nabbar/golib/errors"
ligerr "github.com/nabbar/golib/errors"
)

Expand All @@ -55,6 +56,12 @@ type Bucket interface {

EnableReplication(srcRoleARN, dstRoleARN, dstBucketName string) ligerr.Error
DeleteReplication() ligerr.Error

PutWebsite(index, error string) liberr.Error
GetWebsite() (*sdksss.GetBucketWebsiteOutput, liberr.Error)

SetCORS(cors []sdkstp.CORSRule) liberr.Error
GetCORS() ([]sdkstp.CORSRule, liberr.Error)
}

func New(ctx context.Context, bucket, region string, iam *sdkiam.Client, s3 *sdksss.Client) Bucket {
Expand Down
64 changes: 64 additions & 0 deletions aws/bucket/replication.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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 bucket

import (
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"
liberr "github.com/nabbar/golib/errors"
)

func (cli *client) EnableReplication(srcRoleARN, dstRoleARN, dstBucketName string) liberr.Error {
var status sdkstp.ReplicationRuleStatus = libhlp.STATE_ENABLED

_, err := cli.s3.PutBucketReplication(cli.GetContext(), &sdksss.PutBucketReplicationInput{
Bucket: cli.GetBucketAws(),
ReplicationConfiguration: &sdkstp.ReplicationConfiguration{
Role: sdkaws.String(srcRoleARN + "," + dstRoleARN),
Rules: []sdkstp.ReplicationRule{
{
Destination: &sdkstp.Destination{
Bucket: sdkaws.String("arn:aws:s3:::" + dstBucketName),
},
Status: status,
Prefix: sdkaws.String(""),
},
},
},
})

return cli.GetError(err)
}

func (cli *client) DeleteReplication() liberr.Error {
_, err := cli.s3.DeleteBucketReplication(cli.GetContext(), &sdksss.DeleteBucketReplicationInput{
Bucket: cli.GetBucketAws(),
})

return cli.GetError(err)
}
64 changes: 64 additions & 0 deletions aws/bucket/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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 bucket

import (
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"
liberr "github.com/nabbar/golib/errors"
)

func (cli *client) SetVersioning(state bool) liberr.Error {
var status sdkstp.BucketVersioningStatus = libhlp.STATE_ENABLED
if !state {
status = libhlp.STATE_SUSPENDED
}

_, err := cli.s3.PutBucketVersioning(cli.GetContext(), &sdksss.PutBucketVersioningInput{
Bucket: cli.GetBucketAws(),
VersioningConfiguration: &sdkstp.VersioningConfiguration{
Status: status,
},
})

return cli.GetError(err)
}

func (cli *client) GetVersioning() (string, liberr.Error) {
out, err := cli.s3.GetBucketVersioning(cli.GetContext(), &sdksss.GetBucketVersioningInput{
Bucket: cli.GetBucketAws(),
})

if err != nil {
return "", cli.GetError(err)
} else if out == nil {
return "", libhlp.ErrorResponse.Error(nil)
}

// MarshalValue always return error as nil
return string(out.Status), nil
}
65 changes: 65 additions & 0 deletions aws/bucket/website.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* MIT License
*
* Copyright (c) 2022 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 bucket

import (
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"
liberr "github.com/nabbar/golib/errors"
)

func (cli *client) PutWebsite(index, error string) liberr.Error {
_, err := cli.s3.PutBucketWebsite(cli.GetContext(), &sdksss.PutBucketWebsiteInput{
Bucket: cli.GetBucketAws(),
WebsiteConfiguration: &sdkstp.WebsiteConfiguration{
ErrorDocument: &sdkstp.ErrorDocument{
Key: sdkaws.String(error),
},
IndexDocument: &sdkstp.IndexDocument{
Suffix: sdkaws.String(index),
},
},
})

return cli.GetError(err)
}

func (cli *client) GetWebsite() (*sdksss.GetBucketWebsiteOutput, liberr.Error) {
out, err := cli.s3.GetBucketWebsite(cli.GetContext(), &sdksss.GetBucketWebsiteInput{
Bucket: cli.GetBucketAws(),
})

if err != nil {
return nil, cli.GetError(err)
} else if out == nil {
return nil, libhlp.ErrorResponse.Error(nil)
}

// MarshalValue always return error as nil
return out, nil
}
2 changes: 1 addition & 1 deletion aws/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
package aws_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

Expand Down
2 changes: 1 addition & 1 deletion aws/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ package aws_test
import (
"fmt"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

Expand Down
2 changes: 1 addition & 1 deletion aws/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ package aws_test
import (
"bytes"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

Expand Down
Loading

0 comments on commit 726807c

Please sign in to comment.