forked from itsdalmo/ssm-sh
/
document-description.go
95 lines (84 loc) · 2.76 KB
/
document-description.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package manager
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ssm"
"strings"
)
// NewDocumentDescription creates a new Document from ssm.DocumentIdentifier.
func NewDocumentDescription(ssmDocument *ssm.DocumentDescription) *DocumentDescription {
var parameters []*DocumentParameter
for _, parameter := range ssmDocument.Parameters {
parameters = append(parameters, &DocumentParameter{
aws.StringValue(parameter.Name),
aws.StringValue(parameter.Description),
aws.StringValue(parameter.DefaultValue),
aws.StringValue(parameter.Type),
})
}
return &DocumentDescription{
Name: aws.StringValue(ssmDocument.Name),
Description: aws.StringValue(ssmDocument.Description),
Owner: aws.StringValue(ssmDocument.Owner),
DocumentVersion: aws.StringValue(ssmDocument.DocumentVersion),
DocumentFormat: aws.StringValue(ssmDocument.DocumentFormat),
DocumentType: aws.StringValue(ssmDocument.DocumentType),
SchemaVersion: aws.StringValue(ssmDocument.SchemaVersion),
TargetType: aws.StringValue(ssmDocument.TargetType),
Parameters: parameters,
}
}
// DocumentDescription describes relevant information about a SSM Document
type DocumentDescription struct {
Name string `json:"name"`
Description string `json:"description"`
Owner string `json:"owner"`
DocumentVersion string `json:"documentVersion"`
DocumentFormat string `json:"documentFormat"`
DocumentType string `json:"documentType"`
SchemaVersion string `json:"schemaVersion"`
TargetType string `json:"targetType"`
Parameters []*DocumentParameter
}
// DocumentParameter describes relevant information about a SSM Document Parameter
type DocumentParameter struct {
Name string
Description string
DefaultValue string
Type string
}
// ParametersTabString returns all parameter values separated by "\t|\t" for
// an document. Use with tabwriter to output a table of parameters.
func (d *DocumentDescription) ParametersTabString() string {
var del = "|"
var tab = "\t"
var newLine = "\n"
var fields []string
var line []string
for _, parameter := range d.Parameters {
line = []string{
parameter.Name,
parameter.Type,
parameter.DefaultValue,
parameter.Description,
}
fields = append(fields, strings.Join(line, tab+del+tab))
}
return strings.Join(fields, newLine)
}
// TabString returns all field values separated by "\t|\t" for
// an document. Use with tabwriter to output a table of documents.
func (d *DocumentDescription) TabString() string {
var del = "|"
var tab = "\t"
fields := []string{
d.Name,
d.Description,
d.Owner,
d.DocumentVersion,
d.DocumentFormat,
d.DocumentType,
d.SchemaVersion,
d.TargetType,
}
return strings.Join(fields, tab+del+tab)
}