-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from nabbar/aws_cors_website
Package AWS : Ajout configuration + bump ginkgo v2 Package Logger : bump ginkgo v2 Bump dependancies
- Loading branch information
Showing
17 changed files
with
297 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.