├── .gitignore ├── .gometalinter.json ├── .goreleaser.yml ├── .travis.yml ├── Gopkg.lock ├── Gopkg.toml ├── LICENSE ├── Makefile ├── README.md ├── cmd └── json2ssm │ └── main.go ├── mocks └── SSMAPI.go └── pkg ├── source ├── source.go ├── source_test.go ├── sourcejson.go └── testdata │ ├── mapinslice.json │ ├── simplemap.json │ └── simpleslice.json └── storage ├── storage.go ├── storage_test.go └── testdata └── colors.json /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | vendor/ -------------------------------------------------------------------------------- /.gometalinter.json: -------------------------------------------------------------------------------- 1 | { 2 | "EnableGC": true, 3 | "Deadline": "2m", 4 | "DisableAll": true, 5 | "Enable": [ 6 | "deadcode", 7 | "gocyclo", 8 | "gofmt", 9 | "goimports", 10 | "golint", 11 | "gosimple", 12 | "ineffassign", 13 | "interfacer", 14 | "lll", 15 | "misspell", 16 | "unconvert", 17 | "unparam", 18 | "unused", 19 | "vet" 20 | ], 21 | "Exclude": [ 22 | "pkg/source/source_test.go", 23 | "pkg/storage/storage_test.go", 24 | "vendor", 25 | "mocks" 26 | ], 27 | "Cyclo": 20, 28 | "LineLength": 220 29 | } -------------------------------------------------------------------------------- /.goreleaser.yml: -------------------------------------------------------------------------------- 1 | build: 2 | main: ./cmd/json2ssm 3 | binary: json2ssm 4 | goos: 5 | - darwin 6 | - linux 7 | - windows 8 | goarch: 9 | - amd64 10 | brew: 11 | github: 12 | owner: b-b3rn4rd 13 | name: homebrew-tap 14 | folder: Formula -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - "1.10" 4 | deploy: 5 | - provider: script 6 | skip_cleanup: true 7 | script: curl -sL http://git.io/goreleaser | bash 8 | on: 9 | tags: true 10 | condition: $TRAVIS_OS_NAME = linux -------------------------------------------------------------------------------- /Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | name = "github.com/alecthomas/kingpin" 6 | packages = ["."] 7 | revision = "947dcec5ba9c011838740e680966fd7087a71d0d" 8 | version = "v2.2.6" 9 | 10 | [[projects]] 11 | branch = "master" 12 | name = "github.com/alecthomas/template" 13 | packages = [ 14 | ".", 15 | "parse" 16 | ] 17 | revision = "a0175ee3bccc567396460bf5acd36800cb10c49c" 18 | 19 | [[projects]] 20 | branch = "master" 21 | name = "github.com/alecthomas/units" 22 | packages = ["."] 23 | revision = "2efee857e7cfd4f3d0138cc3cbb1b4966962b93a" 24 | 25 | [[projects]] 26 | name = "github.com/aws/aws-sdk-go" 27 | packages = [ 28 | "aws", 29 | "aws/awserr", 30 | "aws/awsutil", 31 | "aws/client", 32 | "aws/client/metadata", 33 | "aws/corehandlers", 34 | "aws/credentials", 35 | "aws/credentials/ec2rolecreds", 36 | "aws/credentials/endpointcreds", 37 | "aws/credentials/stscreds", 38 | "aws/defaults", 39 | "aws/ec2metadata", 40 | "aws/endpoints", 41 | "aws/request", 42 | "aws/session", 43 | "aws/signer/v4", 44 | "internal/sdkio", 45 | "internal/sdkrand", 46 | "internal/shareddefaults", 47 | "private/protocol", 48 | "private/protocol/json/jsonutil", 49 | "private/protocol/jsonrpc", 50 | "private/protocol/query", 51 | "private/protocol/query/queryutil", 52 | "private/protocol/rest", 53 | "private/protocol/xml/xmlutil", 54 | "service/ssm", 55 | "service/ssm/ssmiface", 56 | "service/sts" 57 | ] 58 | revision = "31a85efbe3bc741eb539d6310c8e66030b7c5cb7" 59 | version = "v1.13.47" 60 | 61 | [[projects]] 62 | name = "github.com/davecgh/go-spew" 63 | packages = ["spew"] 64 | revision = "346938d642f2ec3594ed81d874461961cd0faa76" 65 | version = "v1.1.0" 66 | 67 | [[projects]] 68 | name = "github.com/go-ini/ini" 69 | packages = ["."] 70 | revision = "6529cf7c58879c08d927016dde4477f18a0634cb" 71 | version = "v1.36.0" 72 | 73 | [[projects]] 74 | name = "github.com/jmespath/go-jmespath" 75 | packages = ["."] 76 | revision = "0b12d6b5" 77 | 78 | [[projects]] 79 | name = "github.com/mattn/go-runewidth" 80 | packages = ["."] 81 | revision = "9e777a8366cce605130a531d2cd6363d07ad7317" 82 | version = "v0.0.2" 83 | 84 | [[projects]] 85 | branch = "master" 86 | name = "github.com/nytlabs/gojsonexplode" 87 | packages = ["."] 88 | revision = "0f3fe6bb573f445e686ebae5579d064484ec1819" 89 | 90 | [[projects]] 91 | name = "github.com/pmezard/go-difflib" 92 | packages = ["difflib"] 93 | revision = "792786c7400a136282c1664665ae0a8db921c6c2" 94 | version = "v1.0.0" 95 | 96 | [[projects]] 97 | name = "github.com/sirupsen/logrus" 98 | packages = [ 99 | ".", 100 | "hooks/test" 101 | ] 102 | revision = "c155da19408a8799da419ed3eeb0cb5db0ad5dbc" 103 | version = "v1.0.5" 104 | 105 | [[projects]] 106 | name = "github.com/stretchr/objx" 107 | packages = ["."] 108 | revision = "facf9a85c22f48d2f52f2380e4efce1768749a89" 109 | version = "v0.1" 110 | 111 | [[projects]] 112 | name = "github.com/stretchr/testify" 113 | packages = [ 114 | "assert", 115 | "mock" 116 | ] 117 | revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71" 118 | version = "v1.2.1" 119 | 120 | [[projects]] 121 | branch = "master" 122 | name = "golang.org/x/crypto" 123 | packages = ["ssh/terminal"] 124 | revision = "94e3fad7f1b4eed4ec147751ad6b4c4d33f00611" 125 | 126 | [[projects]] 127 | branch = "master" 128 | name = "golang.org/x/sys" 129 | packages = [ 130 | "unix", 131 | "windows" 132 | ] 133 | revision = "d0faeb539838e250bd0a9db4182d48d4a1915181" 134 | 135 | [[projects]] 136 | name = "gopkg.in/cheggaaa/pb.v1" 137 | packages = ["."] 138 | revision = "1f7f140e48255d0e448ec06de47d4545b8ec1f85" 139 | version = "v1.0.24" 140 | 141 | [solve-meta] 142 | analyzer-name = "dep" 143 | analyzer-version = 1 144 | inputs-digest = "1d0e8e653c99ba1d4ed15bf66d81095f065d3bdeba3566c8cd6c1818b6d607ff" 145 | solver-name = "gps-cdcl" 146 | solver-version = 1 147 | -------------------------------------------------------------------------------- /Gopkg.toml: -------------------------------------------------------------------------------- 1 | # Gopkg.toml example 2 | # 3 | # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md 4 | # for detailed Gopkg.toml documentation. 5 | # 6 | # required = ["github.com/user/thing/cmd/thing"] 7 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] 8 | # 9 | # [[constraint]] 10 | # name = "github.com/user/project" 11 | # version = "1.0.0" 12 | # 13 | # [[constraint]] 14 | # name = "github.com/user/project2" 15 | # branch = "dev" 16 | # source = "github.com/myfork/project2" 17 | # 18 | # [[override]] 19 | # name = "github.com/x/y" 20 | # version = "2.4.0" 21 | # 22 | # [prune] 23 | # non-go = false 24 | # go-tests = true 25 | # unused-packages = true 26 | 27 | 28 | [[constraint]] 29 | name = "github.com/alecthomas/kingpin" 30 | version = "2.2.6" 31 | 32 | [[constraint]] 33 | name = "github.com/aws/aws-sdk-go" 34 | version = "1.13.47" 35 | 36 | [[constraint]] 37 | branch = "master" 38 | name = "github.com/nytlabs/gojsonexplode" 39 | 40 | [[constraint]] 41 | name = "github.com/sirupsen/logrus" 42 | version = "1.0.5" 43 | 44 | [[constraint]] 45 | name = "github.com/stretchr/testify" 46 | version = "1.2.1" 47 | 48 | [[constraint]] 49 | name = "gopkg.in/cheggaaa/pb.v1" 50 | version = "1.0.24" 51 | 52 | [prune] 53 | go-tests = true 54 | unused-packages = true 55 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2018 Bernard Baltrusaitis 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .DEFAULT_GOAL := ci 2 | 3 | ci: install lint test 4 | 5 | install: 6 | go get -u github.com/golang/dep/cmd/dep 7 | dep ensure 8 | go get -u gopkg.in/alecthomas/gometalinter.v2 9 | gometalinter.v2 --install 10 | go get github.com/axw/gocov/... 11 | go get github.com/mattn/goveralls 12 | .PHONY: install 13 | 14 | lint: 15 | gometalinter.v2 ./... | grep -v -E "(should have comment or be unexported|comment on exported method)" || true 16 | gometalinter.v2 ./... --errors 17 | .PHONY: lint 18 | 19 | test: 20 | go test -v ./... 21 | goveralls -service=travis-ci 22 | .PHONY: test 23 | 24 | release: 25 | goreleaser --rm-dist --config=.goreleaser.yml 26 | .PHONY: release -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Go Report Card](https://goreportcard.com/badge/github.com/b-b3rn4rd/json2ssm)](https://goreportcard.com/report/github.com/b-b3rn4rd/json2ssm) [![Build Status](https://travis-ci.org/b-b3rn4rd/gocfn.svg?branch=master)](https://travis-ci.org/b-b3rn4rd/json2ssm) JSON import/export functions with AWS SSM Parameter Store 2 | ================================================ 3 | *json2ssm* - provides JSON import, export and delete functionality when working with AWS SSM parameter store while keeping original data types. 4 | 5 | Motivation 6 | -------------- 7 | AWS SSM Parameter Store is a great service for centrally storing and managing application parameters and secrets. 8 | However, seeding parameters often becomes an adhoc process when parameters are added manually 9 | or provisioned from different scripts which makes it difficult to promote applications between environments. 10 | 11 | Using `json2ssm` parameters can be imported from a single or multiple JSON source files, additionally, it also provides export function to recursively retrieve parameters in JSON format for scenarios 12 | when it's easier to work with JSON structure, for example with Jenkins pipelines or inside ansible playbooks. 13 | 14 | Examples 15 | ---------------- 16 | 17 | Let's start with an example and import following file into SSM parameter store: 18 | 19 | ```bash 20 | $ cat ../../pkg/storage/testdata/colors.json 21 | { 22 | "colors": [ 23 | { 24 | "color": "black", 25 | "category": "hue", 26 | "type": "primary", 27 | "code": { 28 | "rgba": [255,255,255,1], 29 | "hex": "#000" 30 | } 31 | }, 32 | { 33 | "color": "white", 34 | "category": "value", 35 | "code": { 36 | "rgba": [0,0,0,1], 37 | "hex": "#FFF" 38 | } 39 | }, 40 | { 41 | "color": "red", 42 | "category": "hue", 43 | "type": "primary", 44 | "code": { 45 | "rgba": [255,0,0,1], 46 | "hex": "#FF0" 47 | } 48 | }, 49 | { 50 | "color": "blue", 51 | "category": "hue", 52 | "type": "primary", 53 | "code": { 54 | "rgba": [0,0,255,1], 55 | "hex": "#00F" 56 | } 57 | }, 58 | { 59 | "color": "yellow", 60 | "category": "hue", 61 | "type": "primary", 62 | "code": { 63 | "rgba": [255,255,0,1], 64 | "hex": "#FF0" 65 | } 66 | }, 67 | { 68 | "color": "green", 69 | "category": "hue", 70 | "type": "secondary", 71 | "code": { 72 | "rgba": [0,255,0,1], 73 | "hex": "#0F0" 74 | } 75 | } 76 | ] 77 | } 78 | ``` 79 | 80 | ```bash 81 | $ json2ssm put-json --json-file ../../pkg/storage/testdata/colors.json 82 | 47 / 47 [=============================================================================>] 100% 83 | Import has successfully finished, 47 parameters have been (over)written to SSM parameter store. 84 | ``` 85 | 86 | Retrieve the first color: 87 | 88 | ```bash 89 | $ json2ssm get-json --path "/colors/0" 90 | 8 / 8 [==============================================================================] 8s 91 | { 92 | "category": "hue", 93 | "code": { 94 | "hex": "#000", 95 | "rgba": [ 96 | 255, 97 | 255, 98 | 255, 99 | 1 100 | ] 101 | }, 102 | "color": "black", 103 | "type": "primary" 104 | } 105 | ``` 106 | 107 | Retrieve the first color's `rgba` value and store it in a file: 108 | ```bash 109 | $ json2ssm get-json --path "/colors/0/code/rgba" > rgba.son 110 | 4 / 4 [==============================================================================] 2s 111 | $ cat rgba.json 112 | [ 113 | 255, 114 | 255, 115 | 255, 116 | 1 117 | ] 118 | ``` 119 | 120 | Installation 121 | ============= 122 | ```bash 123 | brew tap b-b3rn4rd/homebrew-tap 124 | brew install json2ssm 125 | ``` 126 | 127 | *Using go get* 128 | 129 | ```bash 130 | go get github.com/b-b3rn4rd/json2ssm 131 | ``` 132 | 133 | Usage 134 | ============= 135 | ```bash 136 | $ json2ssm --help 137 | usage: json2ssm [] [ ...] 138 | 139 | Flags: 140 | --help Show context-sensitive help (also try --help-long and 141 | --help-man). 142 | -d, --debug Enable debug logging. 143 | --version Show application version. 144 | 145 | Commands: 146 | help [...] 147 | Show help. 148 | 149 | put-json --json-file=JSON-FILE --encrypt [] 150 | Creates SSM parameters from the specified JSON file. 151 | 152 | get-json --path=PATH --decrypt 153 | Retrieves JSON document from SSM parameter store using given path (prefix). 154 | 155 | del-json --json-file=JSON-FILE 156 | Deletes parameters from SSM parameter store based on the specified JSON 157 | file. 158 | 159 | ``` -------------------------------------------------------------------------------- /cmd/json2ssm/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | 6 | "encoding/json" 7 | "fmt" 8 | 9 | "github.com/alecthomas/kingpin" 10 | "github.com/aws/aws-sdk-go/aws/session" 11 | "github.com/aws/aws-sdk-go/service/ssm" 12 | "github.com/b-b3rn4rd/json2ssm/pkg/source" 13 | "github.com/b-b3rn4rd/json2ssm/pkg/storage" 14 | "github.com/sirupsen/logrus" 15 | ) 16 | 17 | var ( 18 | putJSON = kingpin.Command("put-json", "Creates SSM parameters from the specified JSON file.") 19 | getJSON = kingpin.Command("get-json", "Retrieves JSON document from SSM parameter store using given path (prefix).") 20 | delJSON = kingpin.Command("del-json", "Deletes parameters from SSM parameter store based on the specified JSON file.") 21 | getPath = getJSON.Flag("path", "SSM parameter store path (prefix)").Required().String() 22 | getDecrypt = getJSON.Flag("decrypt", "Decrypt secure strings").Default("false").Bool() 23 | putJSONFile = putJSON.Flag("json-file", "The path where your JSON file is located.").Required().ExistingFile() 24 | putJSONMsg = putJSON.Flag("message", "The additional message used as parameters description.").Short('m').Default("").String() 25 | putEncrypt = putJSON.Flag("encrypt", "Encrypt all values with Secure String").Default("false").Bool() 26 | delJSONFile = delJSON.Flag("json-file", "The path where your JSON file is located.").Required().ExistingFile() 27 | version = "master" 28 | debug = kingpin.Flag("debug", "Enable debug logging.").Short('d').Bool() 29 | logger = logrus.New() 30 | writer = os.Stdout 31 | ) 32 | 33 | func main() { 34 | kingpin.Version(version) 35 | cmd := kingpin.Parse() 36 | 37 | if *debug { 38 | logrus.SetLevel(logrus.DebugLevel) 39 | logger.SetLevel(logrus.DebugLevel) 40 | } 41 | 42 | logger.Formatter = &logrus.JSONFormatter{} 43 | 44 | sess := session.Must(session.NewSessionWithOptions(session.Options{ 45 | SharedConfigState: session.SharedConfigEnable, 46 | })) 47 | 48 | strg := storage.New(ssm.New(sess), logger) 49 | 50 | switch cmd { 51 | 52 | case "del-json": 53 | j := source.JSON{} 54 | r, err := os.Open(*delJSONFile) 55 | if err != nil { 56 | logrus.WithError(err).Fatal("error while opening file") 57 | } 58 | defer r.Close() 59 | 60 | body, err := j.Flatten(r) 61 | if err != nil { 62 | logrus.WithError(err).Fatal("error while flattering") 63 | } 64 | 65 | total, err := strg.Delete(body) 66 | if err != nil { 67 | logger.WithError(err).Fatal("error while deleting") 68 | } 69 | 70 | fmt.Fprintf(writer, "\nDeletion has successfully finished, %d parameters have been removed from SSM parameter store. \n", total) 71 | 72 | case "get-json": 73 | values, err := strg.Export(*getPath, *getDecrypt) 74 | if err != nil { 75 | logrus.WithError(err).Fatal("error while exporting") 76 | } 77 | raw, _ := json.MarshalIndent(values, "", " ") 78 | fmt.Fprint(writer, string(raw)) 79 | 80 | case "put-json": 81 | j := source.JSON{} 82 | r, err := os.Open(*putJSONFile) 83 | if err != nil { 84 | logrus.WithError(err).Fatal("error while opening file") 85 | } 86 | defer r.Close() 87 | 88 | body, err := j.Flatten(r) 89 | if err != nil { 90 | logrus.WithError(err).Fatal("error while flattering") 91 | } 92 | 93 | total, err := strg.Import(body, *putJSONMsg, *putEncrypt) 94 | if err != nil { 95 | logrus.WithError(err).Fatal("error while importing") 96 | } 97 | 98 | fmt.Fprintf(writer, "\nImport has successfully finished, %d parameters have been (over)written to SSM parameter store. \n", total) 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /pkg/source/source.go: -------------------------------------------------------------------------------- 1 | package source 2 | 3 | import "io" 4 | 5 | type Flattener interface { 6 | Flatten(io.Reader) (map[string]interface{}, error) 7 | } 8 | -------------------------------------------------------------------------------- /pkg/source/source_test.go: -------------------------------------------------------------------------------- 1 | package source_test 2 | 3 | import ( 4 | "io" 5 | "testing" 6 | 7 | "os" 8 | 9 | "github.com/b-b3rn4rd/json2ssm/pkg/source" 10 | "github.com/stretchr/testify/assert" 11 | ) 12 | 13 | func TestSourceJson(t *testing.T) { 14 | tests := map[string]struct { 15 | r io.Reader 16 | response map[string]interface{} 17 | err error 18 | }{ 19 | "simplemap": { 20 | r: func() io.Reader { r, _ := os.Open("testdata/simplemap.json"); return r }(), 21 | response: map[string]interface{}{ 22 | "name": "bernard", 23 | "address/city": "melbourne", 24 | "address/code": float64(3000), 25 | "address/address/street": "flinders", 26 | "address/address/number": float64(1), 27 | }, 28 | }, 29 | "simpleslice": { 30 | r: func() io.Reader { r, _ := os.Open("testdata/simpleslice.json"); return r }(), 31 | response: map[string]interface{}{ 32 | "0/name": "bernard", 33 | "1/name": "keith", 34 | }, 35 | }, 36 | "mapinslice": { 37 | r: func() io.Reader { r, _ := os.Open("testdata/mapinslice.json"); return r }(), 38 | response: map[string]interface{}{ 39 | "0/name": "bernard", 40 | "0/colors/0": "red", 41 | "0/colors/1": "blue", 42 | "1/name": "keith", 43 | "1/colors/0": "black", 44 | "1/colors/1": "white", 45 | }, 46 | }, 47 | } 48 | 49 | for name, test := range tests { 50 | t.Run(name, func(t *testing.T) { 51 | s := source.JSON{} 52 | r, err := s.Flatten(test.r) 53 | assert.Equal(t, test.response, r) 54 | if err != nil { 55 | assert.Error(t, err, test.err) 56 | } 57 | }) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /pkg/source/sourcejson.go: -------------------------------------------------------------------------------- 1 | package source 2 | 3 | import ( 4 | "encoding/json" 5 | "io" 6 | 7 | "io/ioutil" 8 | 9 | "github.com/nytlabs/gojsonexplode" 10 | ) 11 | 12 | type JSON struct{} 13 | 14 | func (j *JSON) Flatten(r io.Reader) (map[string]interface{}, error) { 15 | raw, err := ioutil.ReadAll(r) 16 | if err != nil { 17 | return nil, err 18 | } 19 | 20 | jsonRaw, err := gojsonexplode.Explodejson(raw, "/") 21 | if err != nil { 22 | return nil, err 23 | } 24 | 25 | var v map[string]interface{} 26 | 27 | err = json.Unmarshal(jsonRaw, &v) 28 | if err != nil { 29 | return nil, err 30 | } 31 | 32 | return v, nil 33 | } 34 | -------------------------------------------------------------------------------- /pkg/source/testdata/mapinslice.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "bernard", 4 | "colors": ["red", "blue"] 5 | }, 6 | { 7 | "name": "keith", 8 | "colors": ["black", "white"] 9 | } 10 | ] -------------------------------------------------------------------------------- /pkg/source/testdata/simplemap.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bernard", 3 | "address": { 4 | "city": "melbourne", 5 | "code": 3000, 6 | "address": { 7 | "street": "flinders", 8 | "number": 1 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /pkg/source/testdata/simpleslice.json: -------------------------------------------------------------------------------- 1 | [ 2 | {"name": "bernard"}, 3 | {"name": "keith"} 4 | ] -------------------------------------------------------------------------------- /pkg/storage/storage.go: -------------------------------------------------------------------------------- 1 | package storage 2 | 3 | import ( 4 | "sync" 5 | 6 | "fmt" 7 | 8 | "strings" 9 | 10 | "reflect" 11 | 12 | "strconv" 13 | 14 | "time" 15 | 16 | "os" 17 | 18 | "github.com/aws/aws-sdk-go/aws" 19 | "github.com/aws/aws-sdk-go/service/ssm" 20 | "github.com/aws/aws-sdk-go/service/ssm/ssmiface" 21 | "github.com/sirupsen/logrus" 22 | "gopkg.in/cheggaaa/pb.v1" 23 | ) 24 | 25 | type Storage interface { 26 | Import(map[string]interface{}) (int16, error) 27 | Export(string) (interface{}, error) 28 | Delete(map[string]interface{}) (int16, error) 29 | } 30 | 31 | type SSMStorage struct { 32 | svc ssmiface.SSMAPI 33 | logger *logrus.Logger 34 | sleep int 35 | } 36 | 37 | func New(svc ssmiface.SSMAPI, logger *logrus.Logger) *SSMStorage { 38 | return &SSMStorage{ 39 | svc: svc, 40 | logger: logger, 41 | sleep: 10, 42 | } 43 | } 44 | 45 | func (s *SSMStorage) Export(path string, decrypt bool) (interface{}, error) { 46 | values := map[string]interface{}{} 47 | mx := sync.Mutex{} 48 | s.logger.WithField("path", path).Debug("get parameters by path") 49 | 50 | var wg sync.WaitGroup 51 | var i uint32 52 | 53 | bar := pb.New(0) 54 | bar.Output = os.Stderr 55 | bar.Start() 56 | 57 | err := s.svc.GetParametersByPathPages(&ssm.GetParametersByPathInput{ 58 | Path: aws.String(path), 59 | Recursive: aws.Bool(true), 60 | WithDecryption: aws.Bool(decrypt), 61 | }, func(page *ssm.GetParametersByPathOutput, lastPage bool) bool { 62 | bar.SetTotal(int(bar.Total) + len(page.Parameters)) 63 | 64 | for _, p := range page.Parameters { 65 | wg.Add(1) 66 | 67 | if i%20 == 0 && i > 0 { 68 | s.logger.Debugf("sleep for a %d seconds", s.sleep) 69 | time.Sleep(time.Duration(s.sleep) * time.Second) 70 | } 71 | 72 | i++ 73 | go func(name string, value string) { 74 | defer func() { 75 | bar.Increment() 76 | wg.Done() 77 | }() 78 | 79 | s.logger.WithField("name", name).Debug("getting parameter type") 80 | resp, err := s.svc.ListTagsForResource(&ssm.ListTagsForResourceInput{ 81 | ResourceType: aws.String(ssm.ResourceTypeForTaggingParameter), 82 | ResourceId: aws.String(name), 83 | }) 84 | 85 | if err != nil { 86 | s.logger.WithField("name", name).WithError(err).Info("can't get parameter type use string") 87 | mx.Lock() 88 | values[name] = value 89 | mx.Unlock() 90 | } 91 | 92 | vType := func() string { 93 | for _, tag := range resp.TagList { 94 | if *tag.Key == "type" { 95 | return aws.StringValue(tag.Value) 96 | } 97 | } 98 | 99 | return "string" 100 | }() 101 | 102 | s.logger.WithField("name", name).Debugf("converting to %s", vType) 103 | 104 | mx.Lock() 105 | switch vType { 106 | case "bool": 107 | values[name], _ = strconv.ParseBool(value) 108 | case "float64": 109 | values[name], _ = strconv.ParseFloat(value, 64) 110 | case "nil": 111 | values[name] = nil 112 | default: 113 | values[name] = value 114 | } 115 | mx.Unlock() 116 | 117 | }(aws.StringValue(p.Name), aws.StringValue(p.Value)) 118 | } 119 | 120 | return !lastPage 121 | }) 122 | if err != nil { 123 | return nil, err 124 | } 125 | 126 | wg.Wait() 127 | bar.Finish() 128 | 129 | tree := make(map[string]interface{}) 130 | 131 | for k, v := range values { 132 | tree[strings.TrimPrefix(k, path)] = v 133 | } 134 | 135 | return s.unflattern(tree) 136 | } 137 | 138 | func (s *SSMStorage) unflattern(params map[string]interface{}) (interface{}, error) { 139 | var mergeMaps func(m1 interface{}, m2 interface{}) interface{} 140 | mergeMaps = func(m1 interface{}, m2 interface{}) interface{} { 141 | 142 | switch m2 := m2.(type) { 143 | case string: 144 | return m2 145 | case float64: 146 | return m2 147 | case nil: 148 | return m2 149 | case []interface{}: 150 | m1, _ := m1.([]interface{}) 151 | for i2, v2 := range m2 { 152 | if v2 == nil { 153 | continue 154 | } 155 | for { 156 | if len(m1) >= (i2 + 1) { 157 | break 158 | } 159 | m1 = append(m1, "") 160 | } 161 | m1[i2] = mergeMaps(m1[i2], v2) 162 | 163 | } 164 | return m1 165 | case map[string]interface{}: 166 | 167 | m1, ok := m1.(map[string]interface{}) 168 | if !ok { 169 | 170 | return m2 171 | } 172 | for k2, v2 := range m2 { 173 | if v1, ok := m1[k2]; ok { 174 | 175 | m1[k2] = mergeMaps(v1, v2) 176 | 177 | } else { 178 | m1[k2] = v2 179 | } 180 | } 181 | } 182 | 183 | return m1 184 | } 185 | 186 | var tree interface{} 187 | 188 | for k, v := range params { 189 | ks := strings.Split(strings.TrimPrefix(k, "/"), "/") 190 | ksr := make([]string, len(ks)) 191 | for ksi, ksv := range ks { 192 | ksr[len(ks)-(ksi+1)] = ksv 193 | } 194 | 195 | for _, kv := range ksr { 196 | if ik, err := strconv.Atoi(kv); err == nil { 197 | 198 | tmp := make([]interface{}, (ik + 1)) 199 | tmp[ik] = v 200 | v = tmp 201 | continue 202 | } 203 | v = map[string]interface{}{kv: v} 204 | } 205 | tree = mergeMaps(tree, v) 206 | } 207 | 208 | return tree, nil 209 | } 210 | 211 | func (s *SSMStorage) Delete(values map[string]interface{}) (int, error) { 212 | var wg sync.WaitGroup 213 | var delParamError error 214 | var i uint32 215 | 216 | total := len(values) 217 | bar := pb.New(total) 218 | bar.Output = os.Stderr 219 | bar.Start() 220 | 221 | for k := range values { 222 | wg.Add(1) 223 | 224 | if i%20 == 0 && i > 0 { 225 | s.logger.Debugf("sleep for a %d seconds", s.sleep) 226 | time.Sleep(time.Duration(s.sleep) * time.Second) 227 | } 228 | 229 | i++ 230 | 231 | go func(k string) { 232 | defer func() { 233 | bar.Increment() 234 | wg.Done() 235 | }() 236 | 237 | k = fmt.Sprintf("/%s", k) 238 | s.logger.WithField("name", k).Debug("deleting ssm parameter") 239 | 240 | _, err := s.svc.DeleteParameter(&ssm.DeleteParameterInput{ 241 | Name: aws.String(k), 242 | }) 243 | if err != nil { 244 | delParamError = err 245 | } 246 | 247 | s.logger.WithField("name", k).Debug("deleting metadata for ssm parameter") 248 | 249 | s.svc.RemoveTagsFromResource(&ssm.RemoveTagsFromResourceInput{ 250 | ResourceId: aws.String(k), 251 | }) 252 | 253 | }(k) 254 | } 255 | 256 | wg.Wait() 257 | bar.Finish() 258 | 259 | return total, delParamError 260 | } 261 | 262 | func (s *SSMStorage) Import(values map[string]interface{}, msg string, encrypt bool) (int, error) { 263 | var wg sync.WaitGroup 264 | var putParamError error 265 | var i uint32 266 | var paramType string 267 | 268 | if encrypt { 269 | paramType = ssm.ParameterTypeSecureString 270 | } else { 271 | paramType = ssm.ParameterTypeString 272 | } 273 | 274 | total := len(values) 275 | 276 | bar := pb.StartNew(total) 277 | bar.Output = os.Stderr 278 | 279 | for k, v := range values { 280 | wg.Add(1) 281 | 282 | if i%10 == 0 && i > 0 { 283 | s.logger.Debugf("sleep for a %d seconds", s.sleep) 284 | time.Sleep(time.Duration(s.sleep) * time.Second) 285 | } 286 | 287 | i++ 288 | 289 | go func(k string, v interface{}) { 290 | defer func() { 291 | bar.Increment() 292 | wg.Done() 293 | }() 294 | k = fmt.Sprintf("/%s", k) 295 | s.logger.WithField("name", k).Debug("putting ssm parameter") 296 | 297 | _, err := s.svc.PutParameter(&ssm.PutParameterInput{ 298 | Name: aws.String(k), 299 | Value: aws.String(fmt.Sprint(v)), 300 | Type: aws.String(paramType), 301 | Overwrite: aws.Bool(true), 302 | Description: aws.String(msg), 303 | }) 304 | if err != nil { 305 | putParamError = err 306 | return 307 | } 308 | 309 | _, err = s.svc.AddTagsToResource(&ssm.AddTagsToResourceInput{ 310 | ResourceId: aws.String(k), 311 | ResourceType: aws.String(ssm.ResourceTypeForTaggingParameter), 312 | Tags: []*ssm.Tag{&ssm.Tag{ 313 | Key: aws.String("type"), 314 | Value: aws.String(reflect.TypeOf(v).Kind().String()), 315 | }}, 316 | }) 317 | if err != nil { 318 | putParamError = err 319 | } 320 | 321 | }(k, v) 322 | } 323 | 324 | wg.Wait() 325 | bar.Finish() 326 | 327 | return total, putParamError 328 | } 329 | -------------------------------------------------------------------------------- /pkg/storage/storage_test.go: -------------------------------------------------------------------------------- 1 | package storage_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/aws/aws-sdk-go/aws" 7 | "github.com/aws/aws-sdk-go/service/ssm" 8 | "github.com/aws/aws-sdk-go/service/ssm/ssmiface" 9 | "github.com/b-b3rn4rd/json2ssm/mocks" 10 | "github.com/b-b3rn4rd/json2ssm/pkg/storage" 11 | "github.com/sirupsen/logrus/hooks/test" 12 | "github.com/stretchr/testify/assert" 13 | "github.com/stretchr/testify/mock" 14 | ) 15 | 16 | type SSMMock struct { 17 | ssmiface.SSMAPI 18 | output *ssm.GetParametersByPathOutput 19 | listTagsForResourceOutput *ssm.ListTagsForResourceOutput 20 | } 21 | 22 | func (s *SSMMock) GetParametersByPathPages(input *ssm.GetParametersByPathInput, cb func(*ssm.GetParametersByPathOutput, bool) bool) error { 23 | cb(s.output, true) 24 | return nil 25 | } 26 | func (s *SSMMock) ListTagsForResource(input *ssm.ListTagsForResourceInput) (*ssm.ListTagsForResourceOutput, error) { 27 | return s.listTagsForResourceOutput, nil 28 | } 29 | 30 | func TestDelete(t *testing.T) { 31 | values := map[string]interface{}{ 32 | "0/name": "bernard", 33 | "0/address/work": "1 flinders", 34 | "0/address/home": "1 st kilda rd", 35 | "1/name": "keith", 36 | "1/address/work": "2 flinders", 37 | "1/address/home": "2 st kilda rd", 38 | } 39 | s := &mocks.SSMAPI{} 40 | 41 | deleteParameterExpectedInput := map[string]*ssm.DeleteParameterInput{ 42 | "/0/name": { 43 | Name: aws.String("/0/name"), 44 | }, 45 | "/0/address/work": { 46 | Name: aws.String("/0/address/work"), 47 | }, 48 | "/0/address/home": { 49 | Name: aws.String("/0/address/home"), 50 | }, 51 | "/1/name": { 52 | Name: aws.String("/1/name"), 53 | }, 54 | "/1/address/work": { 55 | Name: aws.String("/1/address/work"), 56 | }, 57 | "/1/address/home": { 58 | Name: aws.String("/1/address/home"), 59 | }, 60 | } 61 | 62 | removeTagsToResourceExpectedInput := map[string]*ssm.RemoveTagsFromResourceInput{ 63 | "/0/name": { 64 | ResourceId: aws.String("/0/name"), 65 | }, 66 | "/0/address/work": { 67 | ResourceId: aws.String("/0/address/work"), 68 | }, 69 | "/0/address/home": { 70 | ResourceId: aws.String("/0/address/home"), 71 | }, 72 | "/1/name": { 73 | ResourceId: aws.String("/1/name"), 74 | }, 75 | "/1/address/work": { 76 | ResourceId: aws.String("/1/address/work"), 77 | }, 78 | "/1/address/home": { 79 | ResourceId: aws.String("/1/address/home"), 80 | }, 81 | } 82 | deleteParameterExpectedOutput := &ssm.DeleteParameterOutput{} 83 | removeTagsToResourceExpectedOutput := &ssm.RemoveTagsFromResourceOutput{} 84 | 85 | s.On("DeleteParameter", mock.MatchedBy(func(input *ssm.DeleteParameterInput) bool { 86 | v := deleteParameterExpectedInput[aws.StringValue(input.Name)] 87 | return assert.Equal(t, v, input) 88 | })).Return(deleteParameterExpectedOutput, nil) 89 | 90 | s.On("RemoveTagsFromResource", mock.MatchedBy(func(input *ssm.RemoveTagsFromResourceInput) bool { 91 | v := removeTagsToResourceExpectedInput[aws.StringValue(input.ResourceId)] 92 | return assert.Equal(t, v, input) 93 | })).Return(removeTagsToResourceExpectedOutput, nil) 94 | 95 | logger, _ := test.NewNullLogger() 96 | str := storage.New(s, logger) 97 | str.Delete(values) 98 | 99 | s.AssertNumberOfCalls(t, "DeleteParameter", 6) 100 | s.AssertNumberOfCalls(t, "RemoveTagsFromResource", 6) 101 | } 102 | 103 | func TestExport(t *testing.T) { 104 | s := &SSMMock{} 105 | s.output = &ssm.GetParametersByPathOutput{ 106 | Parameters: []*ssm.Parameter{ 107 | { 108 | Name: aws.String("/0/name"), 109 | Type: aws.String(ssm.ParameterTypeString), 110 | Value: aws.String("bernard"), 111 | }, 112 | { 113 | Name: aws.String("/0/address/work"), 114 | Type: aws.String(ssm.ParameterTypeString), 115 | Value: aws.String("1 flinders"), 116 | }, 117 | { 118 | Name: aws.String("/0/address/home"), 119 | Type: aws.String(ssm.ParameterTypeString), 120 | Value: aws.String("1 st kilda rd"), 121 | }, 122 | }, 123 | } 124 | s.listTagsForResourceOutput = &ssm.ListTagsForResourceOutput{TagList: []*ssm.Tag{ 125 | { 126 | Key: aws.String("type"), 127 | Value: aws.String("string"), 128 | }, 129 | }} 130 | 131 | logger, _ := test.NewNullLogger() 132 | str := storage.New(s, logger) 133 | r, _ := str.Export("/0", false) 134 | 135 | expected := map[string]interface{}{ 136 | "name": "bernard", 137 | "address": map[string]interface{}{ 138 | "home": "1 st kilda rd", 139 | "work": "1 flinders", 140 | }, 141 | } 142 | 143 | assert.Equal(t, expected, r) 144 | } 145 | 146 | func TestImport(t *testing.T) { 147 | values := map[string]interface{}{ 148 | "0/name": "bernard", 149 | "0/address/work": "1 flinders", 150 | "0/address/home": "1 st kilda rd", 151 | "1/name": "keith", 152 | "1/address/work": "2 flinders", 153 | "1/address/home": "2 st kilda rd", 154 | } 155 | 156 | msg := "hello world" 157 | 158 | s := &mocks.SSMAPI{} 159 | 160 | putParameterExpectedInput := map[string]*ssm.PutParameterInput{ 161 | "/0/name": { 162 | Name: aws.String("/0/name"), 163 | Value: aws.String("bernard"), 164 | Type: aws.String(ssm.ParameterTypeString), 165 | Overwrite: aws.Bool(true), 166 | Description: aws.String(msg), 167 | }, 168 | "/0/address/work": { 169 | Name: aws.String("/0/address/work"), 170 | Value: aws.String("1 flinders"), 171 | Type: aws.String(ssm.ParameterTypeString), 172 | Overwrite: aws.Bool(true), 173 | Description: aws.String(msg), 174 | }, 175 | "/0/address/home": { 176 | Name: aws.String("/0/address/home"), 177 | Value: aws.String("1 st kilda rd"), 178 | Type: aws.String(ssm.ParameterTypeString), 179 | Overwrite: aws.Bool(true), 180 | Description: aws.String(msg), 181 | }, 182 | "/1/name": { 183 | Name: aws.String("/1/name"), 184 | Value: aws.String("keith"), 185 | Type: aws.String(ssm.ParameterTypeString), 186 | Overwrite: aws.Bool(true), 187 | Description: aws.String(msg), 188 | }, 189 | "/1/address/work": { 190 | Name: aws.String("/1/address/work"), 191 | Value: aws.String("2 flinders"), 192 | Type: aws.String(ssm.ParameterTypeString), 193 | Overwrite: aws.Bool(true), 194 | Description: aws.String(msg), 195 | }, 196 | "/1/address/home": { 197 | Name: aws.String("/1/address/home"), 198 | Value: aws.String("2 st kilda rd"), 199 | Type: aws.String(ssm.ParameterTypeString), 200 | Overwrite: aws.Bool(true), 201 | Description: aws.String(msg), 202 | }, 203 | } 204 | 205 | addTagsToResourceExpectedInput := map[string]*ssm.AddTagsToResourceInput{ 206 | "/0/name": { 207 | ResourceId: aws.String("/0/name"), 208 | ResourceType: aws.String(ssm.ResourceTypeForTaggingParameter), 209 | Tags: []*ssm.Tag{&ssm.Tag{ 210 | Key: aws.String("type"), 211 | Value: aws.String("string"), 212 | }}, 213 | }, 214 | "/0/address/work": { 215 | ResourceId: aws.String("/0/address/work"), 216 | ResourceType: aws.String(ssm.ResourceTypeForTaggingParameter), 217 | Tags: []*ssm.Tag{&ssm.Tag{ 218 | Key: aws.String("type"), 219 | Value: aws.String("string"), 220 | }}, 221 | }, 222 | "/0/address/home": { 223 | ResourceId: aws.String("/0/address/home"), 224 | ResourceType: aws.String(ssm.ResourceTypeForTaggingParameter), 225 | Tags: []*ssm.Tag{&ssm.Tag{ 226 | Key: aws.String("type"), 227 | Value: aws.String("string"), 228 | }}, 229 | }, 230 | "/1/name": { 231 | ResourceId: aws.String("/1/name"), 232 | ResourceType: aws.String(ssm.ResourceTypeForTaggingParameter), 233 | Tags: []*ssm.Tag{&ssm.Tag{ 234 | Key: aws.String("type"), 235 | Value: aws.String("string"), 236 | }}, 237 | }, 238 | "/1/address/work": { 239 | ResourceId: aws.String("/1/address/work"), 240 | ResourceType: aws.String(ssm.ResourceTypeForTaggingParameter), 241 | Tags: []*ssm.Tag{&ssm.Tag{ 242 | Key: aws.String("type"), 243 | Value: aws.String("string"), 244 | }}, 245 | }, 246 | "/1/address/home": { 247 | ResourceId: aws.String("/1/address/home"), 248 | ResourceType: aws.String(ssm.ResourceTypeForTaggingParameter), 249 | Tags: []*ssm.Tag{&ssm.Tag{ 250 | Key: aws.String("type"), 251 | Value: aws.String("string"), 252 | }}, 253 | }, 254 | } 255 | putParameterExpectedOutput := &ssm.PutParameterOutput{} 256 | addTagsToResourceExpectedOutput := &ssm.AddTagsToResourceOutput{} 257 | 258 | s.On("PutParameter", mock.MatchedBy(func(input *ssm.PutParameterInput) bool { 259 | v := putParameterExpectedInput[aws.StringValue(input.Name)] 260 | return assert.Equal(t, v, input) 261 | })).Return(putParameterExpectedOutput, nil) 262 | 263 | s.On("AddTagsToResource", mock.MatchedBy(func(input *ssm.AddTagsToResourceInput) bool { 264 | v := addTagsToResourceExpectedInput[aws.StringValue(input.ResourceId)] 265 | return assert.Equal(t, v, input) 266 | })).Return(addTagsToResourceExpectedOutput, nil) 267 | 268 | logger, _ := test.NewNullLogger() 269 | str := storage.New(s, logger) 270 | str.Import(values, msg, false) 271 | 272 | s.AssertNumberOfCalls(t, "PutParameter", 6) 273 | s.AssertNumberOfCalls(t, "AddTagsToResource", 6) 274 | } 275 | -------------------------------------------------------------------------------- /pkg/storage/testdata/colors.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors": [ 3 | { 4 | "color": "black", 5 | "category": "hue", 6 | "type": "primary", 7 | "code": { 8 | "rgba": [255,255,255,1], 9 | "hex": "#000" 10 | } 11 | }, 12 | { 13 | "color": "white", 14 | "category": "value", 15 | "code": { 16 | "rgba": [0,0,0,1], 17 | "hex": "#FFF" 18 | } 19 | }, 20 | { 21 | "color": "red", 22 | "category": "hue", 23 | "type": "primary", 24 | "code": { 25 | "rgba": [255,0,0,1], 26 | "hex": "#FF0" 27 | } 28 | }, 29 | { 30 | "color": "blue", 31 | "category": "hue", 32 | "type": "primary", 33 | "code": { 34 | "rgba": [0,0,255,1], 35 | "hex": "#00F" 36 | } 37 | }, 38 | { 39 | "color": "yellow", 40 | "category": "hue", 41 | "type": "primary", 42 | "code": { 43 | "rgba": [255,255,0,1], 44 | "hex": "#FF0" 45 | } 46 | }, 47 | { 48 | "color": "green", 49 | "category": "hue", 50 | "type": "secondary", 51 | "code": { 52 | "rgba": [0,255,0,1], 53 | "hex": "#0F0" 54 | } 55 | } 56 | ] 57 | } --------------------------------------------------------------------------------