Skip to content

Commit 3c42c79

Browse files
committed
chore: put sdkRead Permissions logic in setAdditionalFields func
1 parent 18985be commit 3c42c79

File tree

4 files changed

+36
-49
lines changed

4 files changed

+36
-49
lines changed

apis/v1alpha1/ack-generate-metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ack_generate_info:
2-
build_date: "2023-12-29T17:15:23Z"
2+
build_date: "2023-12-29T17:25:08Z"
33
build_hash: 994d9abdb629dd34b9c5afe4db42b05ff0eca9f1
44
go_version: go1.21.5
55
version: 994d9ab

pkg/resource/vpc_endpoint_service_configuration/hooks.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
svcapitypes "github.com/aws-controllers-k8s/ec2-controller/apis/v1alpha1"
2323
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
24+
ackerr "github.com/aws-controllers-k8s/runtime/pkg/errors"
2425
ackrequeue "github.com/aws-controllers-k8s/runtime/pkg/requeue"
2526
ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log"
2627

@@ -126,6 +127,38 @@ func (rm *resourceManager) syncAllowedPrincipals(
126127
return desired, nil
127128
}
128129

130+
// Sets additional fields (not covered by CREATE Op) on the resource's object
131+
func (rm *resourceManager) setAdditionalFields(
132+
ctx context.Context,
133+
ko *svcapitypes.VPCEndpointServiceConfiguration,
134+
) (latest *resource, err error) {
135+
136+
permInput := &svcsdk.DescribeVpcEndpointServicePermissionsInput{
137+
ServiceId: ko.Status.ServiceID,
138+
}
139+
var permResp *svcsdk.DescribeVpcEndpointServicePermissionsOutput
140+
permResp, err = rm.sdkapi.DescribeVpcEndpointServicePermissionsWithContext(ctx, permInput)
141+
rm.metrics.RecordAPICall("READ_MANY", "DescribeVpcEndpointServicePermissions", err)
142+
if err != nil {
143+
if awsErr, ok := ackerr.AWSError(err); ok && awsErr.Code() == "UNKNOWN" {
144+
return nil, ackerr.NotFound
145+
}
146+
return nil, err
147+
}
148+
149+
if permResp.AllowedPrincipals != nil {
150+
f0 := []*string{}
151+
for _, elem := range permResp.AllowedPrincipals {
152+
if elem.Principal != nil {
153+
f0 = append(f0, elem.Principal)
154+
}
155+
}
156+
ko.Spec.AllowedPrincipals = f0
157+
} else {
158+
ko.Spec.AllowedPrincipals = nil
159+
}
160+
}
161+
129162
// syncTags used to keep tags in sync by calling Create and Delete API's
130163
func (rm *resourceManager) syncTags(
131164
ctx context.Context,

pkg/resource/vpc_endpoint_service_configuration/sdk.go

Lines changed: 1 addition & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,2 @@
11

2-
permInput := &svcsdk.DescribeVpcEndpointServicePermissionsInput{
3-
ServiceId: ko.Status.ServiceID,
4-
}
5-
var permResp *svcsdk.DescribeVpcEndpointServicePermissionsOutput
6-
permResp, err = rm.sdkapi.DescribeVpcEndpointServicePermissionsWithContext(ctx, permInput)
7-
rm.metrics.RecordAPICall("READ_MANY", "DescribeVpcEndpointServicePermissions", err)
8-
if err != nil {
9-
if awsErr, ok := ackerr.AWSError(err); ok && awsErr.Code() == "UNKNOWN" {
10-
return nil, ackerr.NotFound
11-
}
12-
return nil, err
13-
}
14-
15-
if permResp.AllowedPrincipals != nil {
16-
f0 := []*string{}
17-
for _, elem := range permResp.AllowedPrincipals {
18-
if elem.Principal != nil {
19-
f0 = append(f0, elem.Principal)
20-
}
21-
}
22-
ko.Spec.AllowedPrincipals = f0
23-
} else {
24-
ko.Spec.AllowedPrincipals = nil
25-
}
2+
rm.setAdditionalFields(ctx, ko)

0 commit comments

Comments
 (0)