@@ -4,24 +4,70 @@ A tool to read and modify Base64 encoded JSON to use configurations JSON-files f
4
4
## To install
5
5
[ Go] ( https://golang.org/dl/ ) has to be installed.
6
6
``` shell
7
- go get github.com/palchukovsky/json-env
7
+ go get github.com/palchukovsky/json-env
8
8
```
9
9
## Examples
10
10
### Set value
11
11
``` shell
12
- json-env -source eyJmIjoidmFsMiIsIngiOnsieSI6eyJ6IjoidmFsMSJ9fX0 -write " x/y/z=1 2 3" z=valX
12
+ json-env -source eyJmIjoidmFsMiIsIngiOnsieSI6eyJ6IjoidmFsMSJ9fX0 -write " x/y/z=1 2 3" z=valX
13
13
```
14
14
### Read value
15
15
``` shell
16
- json-env -source eyJmIjoidmFsMiIsIngiOnsieSI6eyJ6IjoiMSAyIDMifX0sInoiOiJ2YWxYIn0 -read x/y/z
17
- json-env -source eyJmIjoidmFsMiIsIngiOnsieSI6eyJ6IjoiMSAyIDMifX0sInoiOiJ2YWxYIn0 -read z
18
- json-env -source eyJmIjoidmFsMiIsIngiOnsieSI6eyJ6IjoiMSAyIDMifX0sInoiOiJ2YWxYIn0 -read zz -default " is not existent"
16
+ json-env -source eyJmIjoidmFsMiIsIngiOnsieSI6eyJ6IjoiMSAyIDMifX0sInoiOiJ2YWxYIn0 -read x/y/z
17
+ json-env -source eyJmIjoidmFsMiIsIngiOnsieSI6eyJ6IjoiMSAyIDMifX0sInoiOiJ2YWxYIn0 -read z
18
+ json-env -source eyJmIjoidmFsMiIsIngiOnsieSI6eyJ6IjoiMSAyIDMifX0sInoiOiJ2YWxYIn0 -read zz -default " is not existent"
19
19
```
20
20
### Export source
21
21
``` shell
22
- json-env -source eyJmIjoidmFsMiIsIngiOnsieSI6eyJ6IjoiMSAyIDMifX0sInoiOiJ2YWxYIn0 -export
22
+ json-env -source eyJmIjoidmFsMiIsIngiOnsieSI6eyJ6IjoiMSAyIDMifX0sInoiOiJ2YWxYIn0 -export
23
23
```
24
24
### Encode JSON-file to Base64
25
25
``` shell
26
- json-env -encode_file /path/config.json
26
+ json-env -encode_file /path/config.json
27
+ ```
28
+ ### Use-case example
29
+ ``` Makefile
30
+ CONFIG ?= $(shell json-env -encode_file ./.config.json)
31
+ AWS_APP_GATEWAY_ID := $(shell json-env -source ${CONFIG} -read service/aws/gateway/app/id)
32
+ AWS_REGION := $(shell json-env -source ${CONFIG} -read service/aws/region)
33
+ CONFIG := $(shell json-env -source ${CONFIG} -write \
34
+ "build/version=${VERSION}" \
35
+ "build/commit=${COMMIT}" \
36
+ "build/id=${BUILD}" \
37
+ "build/builder=${BUILDER}" \
38
+ "build/maintainer=${MAINTAINER}" \
39
+ "service/aws/gateway/app/endpoint=${AWS_APP_GATEWAY_ID}.execute-api.${AWS_REGION}.amazonaws.com/${VERSION}")
40
+ AWS_ACCESS_KEY_ID := $(shell json-env -source ${CONFIG} -read builder/aws/accessKey/id)
41
+ AWS_SECRET_ACCESS_KEY := $(shell json-env -source ${CONFIG} -read builder/aws/accessKey/secret)
42
+ AWS_ACCOUNT_ID := $(shell json-env -source ${CONFIG} -read service/aws/accountId)
43
+ AWS_AUTH_GATEWAY_ID := $(shell json-env -source ${CONFIG} -read service/aws/gateway/auth/id)
44
+
45
+ define create-config-file
46
+ -mkdir -p ${1}
47
+ @echo "json-env -source CONFIG -export > ${1}config.json"
48
+ @json-env -source ${CONFIG} -export > "${1}config.json"
49
+ endef
50
+ ```
51
+ ``` go
52
+ func newService (projectPackage string ) service {
53
+ name := os.Args [0 ]
54
+
55
+ var config Config
56
+ {
57
+ file , err := ioutil.ReadFile (" ./lambda_config.json" )
58
+ if err != nil {
59
+ log.Fatalf (` Failed to read config file: "%v".` , err)
60
+ }
61
+ if err := json.Unmarshal (file, &config); err != nil {
62
+ log.Fatalf (` Failed to parse config file: "%v".` , err)
63
+ }
64
+ }
65
+
66
+ return service{
67
+ name: name,
68
+ log: newProductLog (projectPackage, name, config),
69
+ config: config.Service ,
70
+ build: config.Build ,
71
+ }
72
+ }
27
73
```
0 commit comments