Skip to content

Commit

Permalink
Fixes extraneous space in multiline inputs, plus other minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
bwhaley committed Mar 10, 2020
1 parent f40751e commit 96efdaa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
1 change: 1 addition & 0 deletions commands/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func decrypt(c *ishell.Context) {
v, err := strconv.ParseBool(c.Args[0])
if err != nil {
shell.Println(decryptError)
return
}

switch v {
Expand Down
11 changes: 6 additions & 5 deletions commands/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ NoChangeNotification(After=90,Unit=days)
See https://docs.aws.amazon.com/systems-manager/latest/userguide/parameter-store-policies.html
`

const ExpirationPolicy = "Expiration"
const ExpirationNotificationPolicy = "ExpirationNotification"
const NoChangeNotificationPolicy = "NoChangeNotification"

const layout = "2006-01-02T15:04:05Z"
const (
ExpirationPolicy = "Expiration"
ExpirationNotificationPolicy = "ExpirationNotification"
NoChangeNotificationPolicy = "NoChangeNotification"
layout = "2006-01-02T15:04:05Z"
)

var policies = map[string]parameterPolicies{}

Expand Down
27 changes: 20 additions & 7 deletions commands/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Example of inline put:
Example of multiline put:
/>put
... name=/House/Lannister/Cersei
... value="Queen"
... type="String"
... description="Queen of the Seven Kingdoms"
... value=Queen
... type=String
... description=Queen of the Seven Kingdoms
... key=arn:aws:kms:us-west-2:012345678901:key/321examp-ed00-427f-9729-748ba2254794
... overwrite=true
... pattern=[A-z]+
Expand Down Expand Up @@ -121,7 +121,6 @@ func inlinePut(options []string) bool {

func putOptions(s string) bool {
if s == "" {
shell.Println("no input")
return false
}
paramOption := strings.Split(s, "=")
Expand All @@ -131,7 +130,7 @@ func putOptions(s string) bool {
return false
}
field := strings.ToLower(paramOption[0])
val := strings.Join(paramOption[1:], "=")
val := strings.Join(paramOption[1:], "=") // Handles the case where a value has an "=" character
err := validate(field, val)
if err != nil {
shell.Println(err)
Expand Down Expand Up @@ -177,10 +176,22 @@ func validateType(s string) (err error) {
}

func validateValue(s string) (err error) {
s = trimSpaces(s)
putParamInput.Value = aws.String(s)
return nil
}

// trimSpaces works around an issue in ishell where a space is added to the end of each line in a multiline value
// https://github.com/abiosoft/ishell/issues/132
func trimSpaces(s string) string {
parts := strings.Split(s, "\n")
for i := 0; i < len(parts)-1; i++ {
size := len(parts[i])
parts[i] = parts[i][:size-1]
}
return strings.Join(parts, "\n")
}

func validateName(s string) (err error) {
if strings.HasPrefix(s, parameterstore.Delimiter) {
putParamInput.SetName(s)
Expand Down Expand Up @@ -222,8 +233,10 @@ func validateRegion(s string) (err error) {
return nil
}

const StandardTier = "Standard"
const AdvancedTier = "Advanced"
const (
StandardTier = "Standard"
AdvancedTier = "Advanced"
)

func validateTier(s string) (err error) {
if strings.ToLower(s) == StandardTier || strings.ToLower(s) == AdvancedTier {
Expand Down

0 comments on commit 96efdaa

Please # to comment.