Skip to content

Commit 41ee038

Browse files
committed
ARN field mapping
1 parent b2c902d commit 41ee038

File tree

6 files changed

+25354
-0
lines changed

6 files changed

+25354
-0
lines changed

pkg/generate/config/field.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ type FieldConfig struct {
147147
// that owns the resource. This is a special field that we direct to
148148
// storage in the common `Status.ACKResourceMetadata.OwnerAccountID` field.
149149
IsOwnerAccountID bool `json:"is_owner_account_id"`
150+
// IsARN indicates the field represents the ARN for the resource.
151+
// This allows the generator config to override the
152+
// default behaviour of considering a field called "Arn" or
153+
// "{Resource}Arn" (case in-sensitive) as the "ARN field" for the resource.
154+
IsARN bool `json:"is_arn"`
150155
// IsSecret instructs the code generator that this field should be a
151156
// SecretKeyReference.
152157
IsSecret bool `json:"is_secret"`

pkg/generate/sagemaker_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package generate_test
15+
16+
import (
17+
"testing"
18+
19+
"github.com/stretchr/testify/assert"
20+
"github.com/stretchr/testify/require"
21+
22+
"github.com/aws-controllers-k8s/code-generator/pkg/testutil"
23+
)
24+
25+
func TestSageMaker_ARN_Field_Override(t *testing.T) {
26+
assert := assert.New(t)
27+
require := require.New(t)
28+
29+
g := testutil.NewGeneratorForService(t, "sagemaker")
30+
31+
crds, err := g.GetCRDs()
32+
require.Nil(err)
33+
34+
crd := getCRDByName("DataQualityJobDefinition", crds)
35+
require.NotNil(crd)
36+
37+
// The CreateDataQualityJobDefinition has the following definition:
38+
//
39+
// "CreateDataQualityJobDefinition":{
40+
// "name":"CreateDataQualityJobDefinition",
41+
// "http":{
42+
// "method":"POST",
43+
// "requestUri":"/"
44+
// },
45+
// "input":{"shape":"CreateDataQualityJobDefinitionRequest"},
46+
// "output":{"shape":"CreateDataQualityJobDefinitionResponse"},
47+
// "errors":[
48+
// {"shape":"ResourceLimitExceeded"},
49+
// {"shape":"ResourceInUse"}
50+
// ]
51+
// }
52+
//
53+
// Where the CreateDataQualityJobDefinitionResponse shape looks like this:
54+
//
55+
// "CreateDataQualityJobDefinitionResponse":{
56+
// "type":"structure",
57+
// "required":["JobDefinitionArn"],
58+
// "members":{
59+
// "JobDefinitionArn":{"shape":"MonitoringJobDefinitionArn"}
60+
// }
61+
// }
62+
//
63+
// So, we expect that the logic in crd.IsPrimaryARNField() parses through
64+
// field config and identifies the JobDefinitionArn as the primaryARNField
65+
// for the resource
66+
assert.Equal(true, crd.IsPrimaryARNField("JobDefinitionArn"))
67+
68+
}

0 commit comments

Comments
 (0)