Skip to content

Commit

Permalink
added info about template structs in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Toffia committed May 12, 2020
1 parent 28ae3ac commit 582e372
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ You may use reporting and generation of CDK artifacts for Cloud Formation deploy
s := NewSsmSerializer("dev", "test-service")
objs, json, err := s.ReportWithOpts(&ctx, NoFilter, true)
```
The above will cereate a _JSON_ report format that can be used to generate CDK classes. Example output
The above will cereate a _JSON_ report format that can be used to generate CDK classes. Example output for [ssm-cdk-generator](https://www.npmjs.com/package/ssm-cdk-generator)

```typescript
import * as cdk from '@aws-cdk/core';
import * as asm from '@aws-cdk/aws-secretsmanager';
Expand Down Expand Up @@ -130,6 +131,47 @@ import * as cdk from '@aws-cdk/core';
}
}
```
There are a few templates for _Secrets Manager_ included in the library to make it more simpler
to handle standard credentials to e.g. PostgresSQL
```go
type MyServiceContext struct {
DbCtx support.SecretsManagerRDSPostgreSQLRotationSingleUser `asm:"dbctx, strkey=password"`
Settings struct {
BatchSize int `json:"batchsize"`
Signer string `json:"signer,omitempty"`
} `pms:"settings"`
}
```
If this is reported it may output something like this
```json
{
"type": "secrets-manager",
"fqname": "/prod/test-service/dbctx",
"keyid": "",
"description": "",
"tags": {},
"details": {
"strkey": "password"
},
"value": "{\"engine\":\"postgres\",\"host\":\"pgsql-17.toffia.se\",\"username\":\"gördis\",\"dbname\":\"mydb\"}",
"valuetype": "SecureString"
},
{
"type": "parameter-store",
"fqname": "/prod/test-service/settings",
"keyid": "",
"description": "",
"tags": {},
"details": {
"pattern": "",
"tier": "Standard"
},
"value": "{\"batchsize\":77,\"signer\":\"mto\"}",
"valuetype": "String"
}
```

This may then be used to generate CDK artifacts (as above) using [ssm-cdk-generator](https://www.npmjs.com/package/ssm-cdk-generator) to generate passwords and the secrets using Cloud Formation deployment.

# Standard Usage

Expand Down
11 changes: 11 additions & 0 deletions internal/testsupport/teststructs.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package testsupport

import "github.com/mariotoffia/ssm.git/support"

// SingleStringPmsStruct with single string
type SingleStringPmsStruct struct {
Name string `pms:"test, prefix=simple,tag1=nanna banna panna"`
Expand Down Expand Up @@ -58,3 +60,12 @@ type MyDbServiceConfigAsm struct {
Timeout int `json:"timeout"`
} `asm:"bubbibobbo, strkey=password"`
}

// MyContextPostgresSQL demo context
type MyContextPostgresSQL struct {
DbCtx support.SecretsManagerRDSPostgreSQLRotationSingleUser `asm:"dbctx, strkey=password"`
Settings struct {
BatchSize int `json:"batchsize"`
Signer string `json:"signer,omitempty"`
} `pms:"settings"`
}
31 changes: 31 additions & 0 deletions report/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/aws/aws-sdk-go-v2/service/ssm"
"github.com/mariotoffia/ssm.git/internal/asm"
"github.com/mariotoffia/ssm.git/internal/pms"
"github.com/mariotoffia/ssm.git/internal/testsupport"
"github.com/mariotoffia/ssm.git/parser"
"github.com/mariotoffia/ssm.git/support"
Expand Down Expand Up @@ -117,3 +118,33 @@ func TestReportSingleAsmSecretSubJsonNilStruct(t *testing.T) {
assert.Contains(t, buff, `"fqname": "/prod/test-service/bubbibobbo"`)
fmt.Println(buff)
}

func TestReportPostgresSQLTemplateStruct(t *testing.T) {
test := testsupport.MyContextPostgresSQL{}
test.DbCtx.DbName = "mydb"
test.DbCtx.Engine = support.PostgresDBEngine
test.DbCtx.Host = "pgsql-17.toffia.se"
test.DbCtx.Username = "gördis"
test.Settings.BatchSize = 77
test.Settings.Signer = "mto"

tp := reflect.ValueOf(&test)

node, err := parser.New("test-service", "prod", "").
RegisterTagParser("asm", asm.NewTagParser()).
RegisterTagParser("pms", pms.NewTagParser()).
Parse(tp)

if err != nil {
assert.Equal(t, nil, err)
}

reporter := NewWithTier(ssm.ParameterTierStandard)
report, buff, err := reporter.RenderReport(node, &support.FieldFilters{}, true)
if err != nil {
assert.Equal(t, nil, err)
}

assert.Equal(t, 2, len(report.Parameters))
fmt.Println(buff)
}

0 comments on commit 582e372

Please sign in to comment.