Skip to content

Commit 03b4b07

Browse files
Merge pull request #1123 from dbsystel/fix/invalid-arn
fix: invalid arn
2 parents 68744f1 + 1a97f88 commit 03b4b07

File tree

8 files changed

+28
-24
lines changed

8 files changed

+28
-24
lines changed

lambda/internal/event/event.go

+4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ func FromCfnEvent(event cfn.Event) (*SopsSyncResourcePropertys, error) {
9999
return &props, nil
100100
}
101101

102+
func GenerateTempPhysicalResourceId() string {
103+
return fmt.Sprintf("%s:%s:%s", "arn:custom:sopssync:", "temp", "temp")
104+
}
105+
102106
func (p *SopsSyncResourcePropertys) GeneratePhysicalResourceId() string {
103107
return fmt.Sprintf("%s:%s:%s", "arn:custom:sopssync:", p.ResourceType, p.Target)
104108
}

lambda/main.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ func HandleRequestWithClients(clients client.AwsClient, e cfn.Event) (physicalRe
1717

1818
// If it's a delete request, we don't have to do anything
1919
if e.RequestType == cfn.RequestDelete {
20-
return "", nil, nil
20+
return event.GenerateTempPhysicalResourceId(), nil, nil
2121
}
2222
// We have to run this code only, if it is a CloudFormation Create or Update request
2323
if e.RequestType != cfn.RequestCreate && e.RequestType != cfn.RequestUpdate {
24-
return "", nil, fmt.Errorf("requestType '%s' not supported", e.RequestType)
24+
return event.GenerateTempPhysicalResourceId(), nil, fmt.Errorf("requestType '%s' not supported", e.RequestType)
2525
}
2626

2727
// Get the event input from the cloudformation event
@@ -33,19 +33,19 @@ func HandleRequestWithClients(clients client.AwsClient, e cfn.Event) (physicalRe
3333
// Get the encrypted secret input provided by the user
3434
secretEncrypted, secretEncryptedErr := props.GetEncryptedSopsSecret(clients)
3535
if secretEncryptedErr != nil {
36-
return "", nil, secretEncryptedErr
36+
return props.GeneratePhysicalResourceId(), nil, secretEncryptedErr
3737
}
3838

3939
// Decrypt the secret input with sops
4040
secretDecrypted, secretDecryptedErr := secretEncrypted.Decrypt()
4141
if secretDecryptedErr != nil {
42-
return "", nil, secretDecryptedErr
42+
return props.GeneratePhysicalResourceId(), nil, secretDecryptedErr
4343
}
4444

4545
// Generate a data object by parsing the decrypted secret depending on the data input type
4646
secretDecryptedData, secretDecryptedDataErr := secretDecrypted.ToData()
4747
if secretDecryptedDataErr != nil {
48-
return "", nil, secretDecryptedDataErr
48+
return props.GeneratePhysicalResourceId(), nil, secretDecryptedDataErr
4949
}
5050

5151
baseProps := BaseProps{
@@ -63,7 +63,7 @@ func HandleRequestWithClients(clients client.AwsClient, e cfn.Event) (physicalRe
6363
case event.PARAMETER:
6464
return handleParameter(baseProps)
6565
default:
66-
return "", nil, fmt.Errorf("unsupported resource type %s", props.ResourceType)
66+
return props.GeneratePhysicalResourceId(), nil, fmt.Errorf("unsupported resource type %s", props.ResourceType)
6767
}
6868
}
6969

test/PARAMETER.integ.snapshot/PARAMETER.assets.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
{
22
"version": "39.0.0",
33
"files": {
4-
"25761e14c3e98ba78192ce29ad629b6c4e047b2fb5ab49f2847927584e942738": {
4+
"0018ac2cf82d6fd6a6a41fbcdabd1b5b7afc589b4d9f7b9b6ababf4b0a822447": {
55
"source": {
6-
"path": "asset.25761e14c3e98ba78192ce29ad629b6c4e047b2fb5ab49f2847927584e942738.zip",
6+
"path": "asset.0018ac2cf82d6fd6a6a41fbcdabd1b5b7afc589b4d9f7b9b6ababf4b0a822447.zip",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "25761e14c3e98ba78192ce29ad629b6c4e047b2fb5ab49f2847927584e942738.zip",
12+
"objectKey": "0018ac2cf82d6fd6a6a41fbcdabd1b5b7afc589b4d9f7b9b6ababf4b0a822447.zip",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}
1616
},
17-
"37def6adf4558bddf4723ee9abf52e10ead2d79b4b47a9bf5a833adf267f6067": {
17+
"d9c7c4b954f7da502041c1cffcce93337f268b1dcf0bcd8c35bd0f0c0450e98c": {
1818
"source": {
1919
"path": "PARAMETER.template.json",
2020
"packaging": "file"
2121
},
2222
"destinations": {
2323
"current_account-current_region": {
2424
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
25-
"objectKey": "37def6adf4558bddf4723ee9abf52e10ead2d79b4b47a9bf5a833adf267f6067.json",
25+
"objectKey": "d9c7c4b954f7da502041c1cffcce93337f268b1dcf0bcd8c35bd0f0c0450e98c.json",
2626
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
2727
}
2828
}

test/PARAMETER.integ.snapshot/PARAMETER.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
"S3Bucket": {
140140
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
141141
},
142-
"S3Key": "25761e14c3e98ba78192ce29ad629b6c4e047b2fb5ab49f2847927584e942738.zip"
142+
"S3Key": "0018ac2cf82d6fd6a6a41fbcdabd1b5b7afc589b4d9f7b9b6ababf4b0a822447.zip"
143143
},
144144
"Environment": {
145145
"Variables": {

test/PARAMETER_MULTI.integ.snapshot/PARAMETERMULTI.assets.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
{
22
"version": "39.0.0",
33
"files": {
4-
"25761e14c3e98ba78192ce29ad629b6c4e047b2fb5ab49f2847927584e942738": {
4+
"0018ac2cf82d6fd6a6a41fbcdabd1b5b7afc589b4d9f7b9b6ababf4b0a822447": {
55
"source": {
6-
"path": "asset.25761e14c3e98ba78192ce29ad629b6c4e047b2fb5ab49f2847927584e942738.zip",
6+
"path": "asset.0018ac2cf82d6fd6a6a41fbcdabd1b5b7afc589b4d9f7b9b6ababf4b0a822447.zip",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "25761e14c3e98ba78192ce29ad629b6c4e047b2fb5ab49f2847927584e942738.zip",
12+
"objectKey": "0018ac2cf82d6fd6a6a41fbcdabd1b5b7afc589b4d9f7b9b6ababf4b0a822447.zip",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}
1616
},
17-
"28d288317e12002ccd1278a63d361d7f2d9e4a56c5adcc0d811cce75635e03a0": {
17+
"e8dc3019fbf8aefef0b7995dde54188dd2edff6b5d0019db69f128b8bbe9b250": {
1818
"source": {
1919
"path": "PARAMETERMULTI.template.json",
2020
"packaging": "file"
2121
},
2222
"destinations": {
2323
"current_account-current_region": {
2424
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
25-
"objectKey": "28d288317e12002ccd1278a63d361d7f2d9e4a56c5adcc0d811cce75635e03a0.json",
25+
"objectKey": "e8dc3019fbf8aefef0b7995dde54188dd2edff6b5d0019db69f128b8bbe9b250.json",
2626
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
2727
}
2828
}

test/PARAMETER_MULTI.integ.snapshot/PARAMETERMULTI.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@
535535
"S3Bucket": {
536536
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
537537
},
538-
"S3Key": "25761e14c3e98ba78192ce29ad629b6c4e047b2fb5ab49f2847927584e942738.zip"
538+
"S3Key": "0018ac2cf82d6fd6a6a41fbcdabd1b5b7afc589b4d9f7b9b6ababf4b0a822447.zip"
539539
},
540540
"Environment": {
541541
"Variables": {

test/SECRET.integ.snapshot/SECRET.assets.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
{
22
"version": "39.0.0",
33
"files": {
4-
"25761e14c3e98ba78192ce29ad629b6c4e047b2fb5ab49f2847927584e942738": {
4+
"0018ac2cf82d6fd6a6a41fbcdabd1b5b7afc589b4d9f7b9b6ababf4b0a822447": {
55
"source": {
6-
"path": "asset.25761e14c3e98ba78192ce29ad629b6c4e047b2fb5ab49f2847927584e942738.zip",
6+
"path": "asset.0018ac2cf82d6fd6a6a41fbcdabd1b5b7afc589b4d9f7b9b6ababf4b0a822447.zip",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "25761e14c3e98ba78192ce29ad629b6c4e047b2fb5ab49f2847927584e942738.zip",
12+
"objectKey": "0018ac2cf82d6fd6a6a41fbcdabd1b5b7afc589b4d9f7b9b6ababf4b0a822447.zip",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}
1616
},
17-
"1fae4d4a87802ffd6cca4899703d4ae019cfd8704e4af190094d36f8ff05aa36": {
17+
"fcc5e01c0551c6c15cff589d93154f4e1323b8306560170d7585f4f783aed6f5": {
1818
"source": {
1919
"path": "SECRET.template.json",
2020
"packaging": "file"
2121
},
2222
"destinations": {
2323
"current_account-current_region": {
2424
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
25-
"objectKey": "1fae4d4a87802ffd6cca4899703d4ae019cfd8704e4af190094d36f8ff05aa36.json",
25+
"objectKey": "fcc5e01c0551c6c15cff589d93154f4e1323b8306560170d7585f4f783aed6f5.json",
2626
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
2727
}
2828
}

test/SECRET.integ.snapshot/SECRET.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
"S3Bucket": {
167167
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
168168
},
169-
"S3Key": "25761e14c3e98ba78192ce29ad629b6c4e047b2fb5ab49f2847927584e942738.zip"
169+
"S3Key": "0018ac2cf82d6fd6a6a41fbcdabd1b5b7afc589b4d9f7b9b6ababf4b0a822447.zip"
170170
},
171171
"Environment": {
172172
"Variables": {

0 commit comments

Comments
 (0)