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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 6 additions & 2 deletions
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

Lines changed: 13 additions & 5 deletions
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

Lines changed: 8 additions & 16 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 114 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 32 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

0 commit comments

Comments
 (0)