Skip to content

Commit 6f6f73e

Browse files
committed
first implementation
1 parent 7aad3d2 commit 6f6f73e

18 files changed

+1128
-0
lines changed

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
11
# Yashiro
22

33
Yashiro is a templating engine with the external stores.
4+
5+
## Service
6+
7+
AWS
8+
9+
* [Systems Manager Parameter Store](https://docs.aws.amazon.com/systems-manager/)
10+
* [Secrets Manager](https://docs.aws.amazon.com/secretsmanager/)
11+
12+
## Usage
13+
14+
See [Godoc](https://pkg.go.dev/github.com/dwango/yashiro).
15+
16+
```sh
17+
go get github.com/dwango/yashiro
18+
```
19+
20+
## CLI Tool
21+
22+
### Install
23+
24+
Download binary from [release page](https://github.com/dwango/yashiro/releases).
25+
26+
### Example
27+
28+
See [example](./example/).

alias.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright 2023 DWANGO Co., Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package yashiro
18+
19+
import (
20+
"github.com/dwango/yashiro/pkg/config"
21+
"github.com/dwango/yashiro/pkg/engine"
22+
)
23+
24+
// Engine initializes external store client and template.
25+
type Engine = engine.Engine
26+
27+
var (
28+
// NewConfigFromFile returns a new Config from file.
29+
NewConfigFromFile = config.NewFromFile
30+
31+
// NewEngine returns a new Engine.
32+
NewEngine = engine.New
33+
)

cmd/ysr/main.go

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright 2023 DWANGO Co., Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"context"
21+
"fmt"
22+
"os"
23+
"os/signal"
24+
25+
"github.com/dwango/yashiro/internal/cmd"
26+
)
27+
28+
func main() {
29+
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
30+
defer cancel()
31+
32+
if err := cmd.New().ExecuteContext(ctx); err != nil {
33+
fmt.Fprintln(os.Stderr, err)
34+
cancel()
35+
os.Exit(1)
36+
}
37+
}

example/README.md

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# CLI Example
2+
3+
Example of using AWS Systems Parameter Store.
4+
5+
## Requires
6+
7+
* aws account
8+
* aws cli
9+
* `ysr` binary
10+
11+
## Setup
12+
13+
```sh
14+
$ export AWS_PROFILE=$profile_name # if need
15+
$ aws ssm put-parameter --name '/yashiro/example' --value '{"imageTag": "latest", "roleArn": "arn:aws:iam::012345678901:role/PodRole29A92600-1NSKGEZRCWPNU"}' --type String
16+
{
17+
"Version": 1,
18+
"Tier": "Standard"
19+
}
20+
$ aws ssm put-parameter --name '/yashiro/example/secure' --value 'password' --type SecureString
21+
{
22+
"Version": 1,
23+
"Tier": "Standard"
24+
}
25+
```
26+
27+
## Execute
28+
29+
```sh
30+
$ ysr template -c ./yashiro.yaml example.yaml.tmpl
31+
---
32+
apiVersion: v1
33+
kind: Secret
34+
metadata:
35+
name: example
36+
labels:
37+
app: example
38+
data:
39+
db_password: cGFzc3dvcmQ=
40+
---
41+
apiVersion: v1
42+
kind: ServiceAccount
43+
metadata:
44+
name: example
45+
annotations:
46+
eks.amazonaws.com/role-arn: arn:aws:iam::012345678901:role/PodRole29A92600-1NSKGEZRCWPNU
47+
labels:
48+
app: example
49+
---
50+
apiVersion: apps/v1
51+
kind: Deployment
52+
metadata:
53+
name: example
54+
spec:
55+
selector:
56+
matchLabels:
57+
app: example
58+
template:
59+
metadata:
60+
labels:
61+
app: example
62+
spec:
63+
serviceAccountName: example
64+
containers:
65+
- name: hello-world
66+
image: hello-world:latest
67+
resources:
68+
limits:
69+
memory: "128Mi"
70+
cpu: "500m"
71+
```
72+
73+
## Teardown
74+
75+
```sh
76+
aws ssm delete-parameter --name '/yashiro/example'
77+
aws ssm delete-parameter --name '/yashiro/example/secure'
78+
```

example/example.yaml.tmpl

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: example
6+
labels:
7+
app: example
8+
data:
9+
db_password: {{ .exampleSecure | b64enc }}
10+
---
11+
apiVersion: v1
12+
kind: ServiceAccount
13+
metadata:
14+
name: example
15+
annotations:
16+
eks.amazonaws.com/role-arn: {{ .example.roleArn }}
17+
labels:
18+
app: example
19+
---
20+
apiVersion: apps/v1
21+
kind: Deployment
22+
metadata:
23+
name: example
24+
spec:
25+
selector:
26+
matchLabels:
27+
app: example
28+
template:
29+
metadata:
30+
labels:
31+
app: example
32+
spec:
33+
serviceAccountName: example
34+
containers:
35+
- name: hello-world
36+
image: hello-world:{{ .example.imageTag }}
37+
resources:
38+
limits:
39+
memory: "128Mi"
40+
cpu: "500m"

example/yashiro.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
aws:
3+
parameter_store:
4+
- name: /yashiro/example
5+
ref: example
6+
is_json: true
7+
- name: /yashiro/example/secure
8+
ref: exampleSecure
9+
decryption: true

example_test.go

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Copyright 2023 DWANGO Co., Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package yashiro_test
18+
19+
import (
20+
"context"
21+
"log"
22+
"os"
23+
24+
awsconfig "github.com/aws/aws-sdk-go-v2/config"
25+
"github.com/dwango/yashiro"
26+
"github.com/dwango/yashiro/pkg/config"
27+
)
28+
29+
func Example() {
30+
ctx := context.TODO()
31+
32+
sdkConfig, err := awsconfig.LoadDefaultConfig(ctx)
33+
if err != nil {
34+
log.Fatalf("failed to load config: %s", err)
35+
}
36+
37+
refName := "example"
38+
cfg := &config.Config{
39+
Aws: &config.AwsConfig{
40+
ParameterStoreValues: []config.AwsParameterStoreValueConfig{
41+
{
42+
ValueConfig: config.ValueConfig{
43+
Name: "/example",
44+
Ref: &refName,
45+
IsJSON: true,
46+
},
47+
},
48+
},
49+
SdkConfig: &sdkConfig,
50+
},
51+
}
52+
53+
eng, err := yashiro.NewEngine(cfg)
54+
if err != nil {
55+
log.Fatalf("failed to create engine: %s", err)
56+
}
57+
58+
text := `This is example code. The message is {{ .example.message }}.`
59+
60+
if err := eng.Render(ctx, text, os.Stdout); err != nil {
61+
log.Fatalf("failed to render text: %s", err)
62+
}
63+
}

go.mod

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module github.com/dwango/yashiro
2+
3+
go 1.21
4+
5+
require (
6+
github.com/Masterminds/sprig/v3 v3.2.3
7+
github.com/aws/aws-sdk-go-v2 v1.22.1
8+
github.com/aws/aws-sdk-go-v2/config v1.22.1
9+
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.23.0
10+
github.com/aws/aws-sdk-go-v2/service/ssm v1.42.0
11+
github.com/spf13/cobra v1.8.0
12+
sigs.k8s.io/yaml v1.4.0
13+
)
14+
15+
require (
16+
github.com/Masterminds/goutils v1.1.1 // indirect
17+
github.com/Masterminds/semver/v3 v3.2.0 // indirect
18+
github.com/aws/aws-sdk-go-v2/credentials v1.15.1 // indirect
19+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.2 // indirect
20+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.1 // indirect
21+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.1 // indirect
22+
github.com/aws/aws-sdk-go-v2/internal/ini v1.5.0 // indirect
23+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.1 // indirect
24+
github.com/aws/aws-sdk-go-v2/service/sso v1.17.0 // indirect
25+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.19.0 // indirect
26+
github.com/aws/aws-sdk-go-v2/service/sts v1.25.0 // indirect
27+
github.com/aws/smithy-go v1.16.0 // indirect
28+
github.com/google/uuid v1.1.1 // indirect
29+
github.com/huandu/xstrings v1.3.3 // indirect
30+
github.com/imdario/mergo v0.3.11 // indirect
31+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
32+
github.com/jmespath/go-jmespath v0.4.0 // indirect
33+
github.com/mitchellh/copystructure v1.0.0 // indirect
34+
github.com/mitchellh/reflectwalk v1.0.0 // indirect
35+
github.com/shopspring/decimal v1.2.0 // indirect
36+
github.com/spf13/cast v1.3.1 // indirect
37+
github.com/spf13/pflag v1.0.5 // indirect
38+
golang.org/x/crypto v0.3.0 // indirect
39+
gopkg.in/yaml.v2 v2.4.0 // indirect
40+
)

0 commit comments

Comments
 (0)