Skip to content

Commit

Permalink
Add region to create export sink (#367)
Browse files Browse the repository at this point in the history
* Add region to create export sink

* update flag description

* fix test

* flag to sinkregion

* Make variable

---------

Co-authored-by: alice-yin <[email protected]>
  • Loading branch information
david049 and alice-yin authored Jul 15, 2024
1 parent 579383f commit cde1a73
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
22 changes: 17 additions & 5 deletions app/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
codecEndpointFlagName = "endpoint"
codecPassAccessTokenFlagName = "pass-access-token"
codecIncludeCredentialsFlagName = "include-credentials"
sinkRegionFlagName = "region"
)

const (
Expand Down Expand Up @@ -137,6 +138,12 @@ var (
Name: "gcs-bucket",
Usage: "GCS bucket of the sink",
}
sinkRegionFlag = &cli.StringFlag{
Name: sinkRegionFlagName,
Usage: "The region to use for the request, if not set the server will use the namespace's region",
Aliases: []string{"re"},
Required: false,
}
)

type NamespaceClient struct {
Expand Down Expand Up @@ -1535,6 +1542,7 @@ func NewNamespaceCommand(getNamespaceClientFn GetNamespaceClientFn) (CommandOut,
s3BucketFlagRequired,
RequestIDFlag,
kmsArnFlag,
sinkRegionFlag,
},
Action: func(ctx *cli.Context) error {
awsAccountID, roleName, err := parseAssumedRole(ctx.String(sinkAssumedRoleFlagRequired.Name))
Expand All @@ -1543,9 +1551,14 @@ func NewNamespaceCommand(getNamespaceClientFn GetNamespaceClientFn) (CommandOut,
}

namespace := ctx.String(NamespaceFlagName)
ns, err := c.getNamespace(namespace)
if err != nil {
return fmt.Errorf("unable to get namespace: %v", err)
region := ctx.String(sinkRegionFlagName)

if len(region) == 0 {
ns, err := c.getNamespace(namespace)
if err != nil {
return fmt.Errorf("unable to get namespace: %v", err)
}
region = ns.Spec.Region
}

request := &namespaceservice.CreateExportSinkRequest{
Expand All @@ -1557,7 +1570,7 @@ func NewNamespaceCommand(getNamespaceClientFn GetNamespaceClientFn) (CommandOut,
S3Sink: &sink.S3Spec{
RoleName: roleName,
BucketName: ctx.String(s3BucketFlagRequired.Name),
Region: ns.Spec.Region,
Region: region,
KmsArn: ctx.String(kmsArnFlag.Name),
AwsAccountId: awsAccountID,
},
Expand Down Expand Up @@ -1674,7 +1687,6 @@ func NewNamespaceCommand(getNamespaceClientFn GetNamespaceClientFn) (CommandOut,
if c.isS3BucketChange(ctx, sink) {
sink.Spec.S3Sink.BucketName = ctx.String(s3BucketFlagOptional.Name)
}

request := &namespaceservice.UpdateExportSinkRequest{
Namespace: ctx.String(NamespaceFlagName),
Spec: sink.Spec,
Expand Down
18 changes: 18 additions & 0 deletions app/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1696,6 +1696,24 @@ func (s *NamespaceTestSuite) TestCreateExportS3Sink() {
expectErr: true,
expectErrMsg: "unable to get namespace: invalid namespace returned by server",
},
{
name: "uses region when provided as arg",
args: []string{"namespace", "es", "s3", "create", "--namespace", ns, "--sink-name", "sink1", "--role-arn", "arn:aws:iam::123456789012:role/TestRole", "--s3-bucket-name", "testBucket", "--region", "us-east-1"},
expectRequest: func(r *namespaceservice.CreateExportSinkRequest) {
r.Namespace = ns
r.Spec = &sink.ExportSinkSpec{
Name: "sink1",
Enabled: true,
DestinationType: sink.EXPORT_DESTINATION_TYPE_S3,
S3Sink: &sink.S3Spec{
RoleName: "TestRole",
BucketName: "testBucket",
Region: "us-east-1",
AwsAccountId: "123456789012",
},
}
},
},
}

for _, tc := range tests {
Expand Down

0 comments on commit cde1a73

Please sign in to comment.