diff --git a/tier-s3.go b/tier-s3.go index 06c2a8c..1f08741 100644 --- a/tier-s3.go +++ b/tier-s3.go @@ -23,14 +23,17 @@ package madmin // TierS3 represents the remote tier configuration for AWS S3 compatible backend. type TierS3 struct { - Endpoint string `json:",omitempty"` - AccessKey string `json:",omitempty"` - SecretKey string `json:",omitempty"` - Bucket string `json:",omitempty"` - Prefix string `json:",omitempty"` - Region string `json:",omitempty"` - StorageClass string `json:",omitempty"` - AWSRole bool `json:",omitempty"` + Endpoint string `json:",omitempty"` + AccessKey string `json:",omitempty"` + SecretKey string `json:",omitempty"` + Bucket string `json:",omitempty"` + Prefix string `json:",omitempty"` + Region string `json:",omitempty"` + StorageClass string `json:",omitempty"` + AWSRole bool `json:",omitempty"` + AWSRoleARN string `json:",omitempty"` + AWSRoleSessionName string `json:",omitempty"` + DurationSeconds int `json:",omitempty"` } // S3Options supports NewTierS3 to take variadic options @@ -76,6 +79,22 @@ func S3AWSRole() func(s3 *TierS3) error { } } +// S3AWSRoleARN helper to use optional AWS RoleARN to NewTierS3 +func S3AWSRoleARN(roleARN string) func(s3 *TierS3) error { + return func(s3 *TierS3) error { + s3.AWSRoleARN = roleARN + return nil + } +} + +// S3AWSRoleSessionName helper to use optional AWS RoleSessionName to NewTierS3 +func S3AWSRoleSessionName(roleSessionName string) func(s3 *TierS3) error { + return func(s3 *TierS3) error { + s3.AWSRoleSessionName = roleSessionName + return nil + } +} + // NewTierS3 returns a TierConfig of S3 type. Returns error if the given // parameters are invalid like name is empty etc. func NewTierS3(name, accessKey, secretKey, bucket string, options ...S3Options) (*TierConfig, error) { diff --git a/tier-s3_gen.go b/tier-s3_gen.go index 420b348..3246e40 100644 --- a/tier-s3_gen.go +++ b/tier-s3_gen.go @@ -72,6 +72,24 @@ func (z *TierS3) DecodeMsg(dc *msgp.Reader) (err error) { err = msgp.WrapError(err, "AWSRole") return } + case "AWSRoleARN": + z.AWSRoleARN, err = dc.ReadString() + if err != nil { + err = msgp.WrapError(err, "AWSRoleARN") + return + } + case "AWSRoleSessionName": + z.AWSRoleSessionName, err = dc.ReadString() + if err != nil { + err = msgp.WrapError(err, "AWSRoleSessionName") + return + } + case "DurationSeconds": + z.DurationSeconds, err = dc.ReadInt() + if err != nil { + err = msgp.WrapError(err, "DurationSeconds") + return + } default: err = dc.Skip() if err != nil { @@ -85,9 +103,9 @@ func (z *TierS3) DecodeMsg(dc *msgp.Reader) (err error) { // EncodeMsg implements msgp.Encodable func (z *TierS3) EncodeMsg(en *msgp.Writer) (err error) { - // map header, size 8 + // map header, size 11 // write "Endpoint" - err = en.Append(0x88, 0xa8, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74) + err = en.Append(0x8b, 0xa8, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74) if err != nil { return } @@ -166,15 +184,45 @@ func (z *TierS3) EncodeMsg(en *msgp.Writer) (err error) { err = msgp.WrapError(err, "AWSRole") return } + // write "AWSRoleARN" + err = en.Append(0xaa, 0x41, 0x57, 0x53, 0x52, 0x6f, 0x6c, 0x65, 0x41, 0x52, 0x4e) + if err != nil { + return + } + err = en.WriteString(z.AWSRoleARN) + if err != nil { + err = msgp.WrapError(err, "AWSRoleARN") + return + } + // write "AWSRoleSessionName" + err = en.Append(0xb2, 0x41, 0x57, 0x53, 0x52, 0x6f, 0x6c, 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x4e, 0x61, 0x6d, 0x65) + if err != nil { + return + } + err = en.WriteString(z.AWSRoleSessionName) + if err != nil { + err = msgp.WrapError(err, "AWSRoleSessionName") + return + } + // write "DurationSeconds" + err = en.Append(0xaf, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73) + if err != nil { + return + } + err = en.WriteInt(z.DurationSeconds) + if err != nil { + err = msgp.WrapError(err, "DurationSeconds") + return + } return } // MarshalMsg implements msgp.Marshaler func (z *TierS3) MarshalMsg(b []byte) (o []byte, err error) { o = msgp.Require(b, z.Msgsize()) - // map header, size 8 + // map header, size 11 // string "Endpoint" - o = append(o, 0x88, 0xa8, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74) + o = append(o, 0x8b, 0xa8, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74) o = msgp.AppendString(o, z.Endpoint) // string "AccessKey" o = append(o, 0xa9, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x4b, 0x65, 0x79) @@ -197,6 +245,15 @@ func (z *TierS3) MarshalMsg(b []byte) (o []byte, err error) { // string "AWSRole" o = append(o, 0xa7, 0x41, 0x57, 0x53, 0x52, 0x6f, 0x6c, 0x65) o = msgp.AppendBool(o, z.AWSRole) + // string "AWSRoleARN" + o = append(o, 0xaa, 0x41, 0x57, 0x53, 0x52, 0x6f, 0x6c, 0x65, 0x41, 0x52, 0x4e) + o = msgp.AppendString(o, z.AWSRoleARN) + // string "AWSRoleSessionName" + o = append(o, 0xb2, 0x41, 0x57, 0x53, 0x52, 0x6f, 0x6c, 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x4e, 0x61, 0x6d, 0x65) + o = msgp.AppendString(o, z.AWSRoleSessionName) + // string "DurationSeconds" + o = append(o, 0xaf, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73) + o = msgp.AppendInt(o, z.DurationSeconds) return } @@ -266,6 +323,24 @@ func (z *TierS3) UnmarshalMsg(bts []byte) (o []byte, err error) { err = msgp.WrapError(err, "AWSRole") return } + case "AWSRoleARN": + z.AWSRoleARN, bts, err = msgp.ReadStringBytes(bts) + if err != nil { + err = msgp.WrapError(err, "AWSRoleARN") + return + } + case "AWSRoleSessionName": + z.AWSRoleSessionName, bts, err = msgp.ReadStringBytes(bts) + if err != nil { + err = msgp.WrapError(err, "AWSRoleSessionName") + return + } + case "DurationSeconds": + z.DurationSeconds, bts, err = msgp.ReadIntBytes(bts) + if err != nil { + err = msgp.WrapError(err, "DurationSeconds") + return + } default: bts, err = msgp.Skip(bts) if err != nil { @@ -280,6 +355,6 @@ func (z *TierS3) UnmarshalMsg(bts []byte) (o []byte, err error) { // Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message func (z *TierS3) Msgsize() (s int) { - s = 1 + 9 + msgp.StringPrefixSize + len(z.Endpoint) + 10 + msgp.StringPrefixSize + len(z.AccessKey) + 10 + msgp.StringPrefixSize + len(z.SecretKey) + 7 + msgp.StringPrefixSize + len(z.Bucket) + 7 + msgp.StringPrefixSize + len(z.Prefix) + 7 + msgp.StringPrefixSize + len(z.Region) + 13 + msgp.StringPrefixSize + len(z.StorageClass) + 8 + msgp.BoolSize + s = 1 + 9 + msgp.StringPrefixSize + len(z.Endpoint) + 10 + msgp.StringPrefixSize + len(z.AccessKey) + 10 + msgp.StringPrefixSize + len(z.SecretKey) + 7 + msgp.StringPrefixSize + len(z.Bucket) + 7 + msgp.StringPrefixSize + len(z.Prefix) + 7 + msgp.StringPrefixSize + len(z.Region) + 13 + msgp.StringPrefixSize + len(z.StorageClass) + 8 + msgp.BoolSize + 11 + msgp.StringPrefixSize + len(z.AWSRoleARN) + 19 + msgp.StringPrefixSize + len(z.AWSRoleSessionName) + 16 + msgp.IntSize return }