Skip to content

Commit 5ed622d

Browse files
KevinPikeKevin Pikeomkhegde
authored
Regenerate github example (#164)
* Regenerate github example. Add go test and build to precommit * Update buildspec to go1.14 Co-authored-by: Kevin Pike <[email protected]> Co-authored-by: Omkar Hegde <[email protected]>
1 parent 3340980 commit 5ed622d

File tree

11 files changed

+193
-29
lines changed

11 files changed

+193
-29
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ pre-commit run --all-files
4545
pre-commit run pytest-local
4646
```
4747

48+
Use `./generate-examples.sh` to run install `cloudformation-cli-go-plugin` locally and run `cfn generate` in each example.
49+
4850
Getting started
4951
---------------
5052

examples/github-repo/.rpdk-config

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
22
"typeName": "Example::GitHub::Repo",
3-
"language": "golang",
3+
"language": "go",
44
"runtime": "go1.x",
55
"entrypoint": "handler",
66
"testEntrypoint": "handler",
77
"settings": {
8-
"importpath": "github.com/aws-cloudformation/cloudformation-cli-go-plugin/examples/github-repo"
8+
"import_path": "github.com/aws-cloudformation/cloudformation-cli-go-plugin/examples/github-repo",
9+
"protocolVersion": "2.0.0",
10+
"pluginVersion": "2.0.0"
911
}
1012
}

examples/github-repo/Makefile

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
.PHONY: build clean deploy
1+
.PHONY: build test clean
22

33
build:
4-
cfn-cli generate
4+
cfn generate
5+
env GOOS=linux go build -ldflags="-s -w" -tags="logging" -o bin/handler cmd/main.go
6+
7+
test:
8+
cfn generate
59
env GOOS=linux go build -ldflags="-s -w" -o bin/handler cmd/main.go
610

711
clean:

examples/github-repo/cmd/main.go

+13-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/github-repo/cmd/resource/model.go

+8-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/github-repo/cmd/resource/resource.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
7777
return handler.ProgressEvent{}, fmt.Errorf("Status Code: %d, Status: %v", resp.StatusCode, resp.Status)
7878
}
7979

80-
currentModel.Name = aws.String(*repo.Name)
81-
currentModel.Owner = aws.String(*repo.Owner.Name)
82-
currentModel.Description = aws.String(*repo.Description)
83-
currentModel.Homepage = aws.String(*repo.Homepage)
80+
currentModel.Name = repo.Name
81+
currentModel.Owner = repo.Owner.Name
82+
currentModel.Description = repo.Description
83+
currentModel.Homepage = repo.Homepage
8484

8585
return handler.ProgressEvent{
8686
OperationStatus: handler.Success,

examples/github-repo/docs/README.md

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Example::GitHub::Repo
2+
3+
Manages a GitHub Repo
4+
5+
## Syntax
6+
7+
To declare this entity in your AWS CloudFormation template, use the following syntax:
8+
9+
### JSON
10+
11+
<pre>
12+
{
13+
"Type" : "Example::GitHub::Repo",
14+
"Properties" : {
15+
"<a href="#name" title="Name">Name</a>" : <i>String</i>,
16+
"<a href="#owner" title="Owner">Owner</a>" : <i>String</i>,
17+
"<a href="#description" title="Description">Description</a>" : <i>String</i>,
18+
"<a href="#homepage" title="Homepage">Homepage</a>" : <i>String</i>,
19+
"<a href="#oauthtoken" title="OauthToken">OauthToken</a>" : <i>String</i>,
20+
}
21+
}
22+
</pre>
23+
24+
### YAML
25+
26+
<pre>
27+
Type: Example::GitHub::Repo
28+
Properties:
29+
<a href="#name" title="Name">Name</a>: <i>String</i>
30+
<a href="#owner" title="Owner">Owner</a>: <i>String</i>
31+
<a href="#description" title="Description">Description</a>: <i>String</i>
32+
<a href="#homepage" title="Homepage">Homepage</a>: <i>String</i>
33+
<a href="#oauthtoken" title="OauthToken">OauthToken</a>: <i>String</i>
34+
</pre>
35+
36+
## Properties
37+
38+
#### Name
39+
40+
Name of the repository on GitHub
41+
42+
_Required_: Yes
43+
44+
_Type_: String
45+
46+
_Minimum_: <code>1</code>
47+
48+
_Maximum_: <code>50</code>
49+
50+
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
51+
52+
#### Owner
53+
54+
Where to create the repository, either a user or an organization
55+
56+
_Required_: Yes
57+
58+
_Type_: String
59+
60+
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
61+
62+
#### Description
63+
64+
The title of the TPS report is a mandatory element.
65+
66+
_Required_: No
67+
68+
_Type_: String
69+
70+
_Minimum_: <code>20</code>
71+
72+
_Maximum_: <code>250</code>
73+
74+
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
75+
76+
#### Homepage
77+
78+
Homepage of the project
79+
80+
_Required_: No
81+
82+
_Type_: String
83+
84+
_Minimum_: <code>20</code>
85+
86+
_Maximum_: <code>250</code>
87+
88+
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
89+
90+
#### OauthToken
91+
92+
OAuth token from GitHub
93+
94+
_Required_: Yes
95+
96+
_Type_: String
97+
98+
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
99+
100+
## Return Values
101+
102+
### Ref
103+
104+
When you pass the logical ID of this resource to the intrinsic `Ref` function, Ref returns the URL.
105+
106+
### Fn::GetAtt
107+
108+
The `Fn::GetAtt` intrinsic function returns a value for a specified attribute of this type. The following are the available attributes and sample return values.
109+
110+
For more information about using the `Fn::GetAtt` intrinsic function, see [Fn::GetAtt](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html).
111+
112+
#### URL
113+
114+
URL to the repository

examples/github-repo/resource-role.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ Resources:
2020
- PolicyName: ResourceTypePolicy
2121
PolicyDocument:
2222
Version: '2012-10-17'
23+
Statement:
24+
- Effect: Deny
25+
Action:
26+
- "*"
27+
Resource: "*"
2328
Outputs:
2429
ExecutionRoleArn:
2530
Value:

generate-examples.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
if [ ! -d "env" ]; then
4+
python3 -m venv env
5+
fi
6+
7+
function deactivateEnv {
8+
rv=$?
9+
deactivate
10+
exit $?
11+
}
12+
13+
trap "deactivateEnv" EXIT
14+
15+
source env/bin/activate
16+
17+
# uninstall cloudformation-cli-go-plugin if it exists
18+
pip3 show cloudformation-cli-go-plugin
19+
SHOW_RV=$?
20+
21+
if [ "$SHOW_RV" == "0" ]; then
22+
pip3 uninstall -y cloudformation-cli-go-plugin
23+
fi
24+
25+
pip3 install -e .
26+
27+
EXAMPLES=( github-repo )
28+
for EXAMPLE in "${EXAMPLES[@]}"
29+
do
30+
cd examples/$EXAMPLE
31+
cfn generate
32+
done

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/aws-cloudformation/cloudformation-cli-go-plugin
33
go 1.13
44

55
require (
6+
github.com/avast/retry-go v2.6.0+incompatible
67
github.com/aws/aws-lambda-go v1.13.3
78
github.com/aws/aws-sdk-go v1.25.37
89
github.com/google/go-cmp v0.3.1

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
22
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3+
github.com/avast/retry-go v2.6.0+incompatible h1:FelcMrm7Bxacr1/RM8+/eqkDkmVN7tjlsy51dOzB3LI=
4+
github.com/avast/retry-go v2.6.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
35
github.com/aws/aws-lambda-go v1.13.3 h1:SuCy7H3NLyp+1Mrfp+m80jcbi9KYWAs9/BXwppwRDzY=
46
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
57
github.com/aws/aws-sdk-go v1.25.37 h1:gBtB/F3dophWpsUQKN/Kni+JzYEH2mGHF4hWNtfED1w=
68
github.com/aws/aws-sdk-go v1.25.37/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
79
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
810
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
911
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
12+
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
1013
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
1114
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
1215
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
@@ -35,6 +38,7 @@ golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BG
3538
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
3639
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
3740
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
41+
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
3842
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
3943
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
4044
gopkg.in/validator.v2 v2.0.0-20191107172027-c3144fdedc21 h1:2QQcyaEBdpfjjYkF0MXc69jZbHb4IOYuXz2UwsmVM8k=

0 commit comments

Comments
 (0)