Skip to content

Commit

Permalink
Cast port number as string (#11)
Browse files Browse the repository at this point in the history
Addresses #10

When using RDS secrets the port number is not a string. As a result, the
unmarshal fails. Catch this scenario and add the port as a string.
  • Loading branch information
flands authored and mumoshu committed May 2, 2019
1 parent 397ccb6 commit 27a4856
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ IMAGE ?= mumoshu/aws-secret-operator:canary

publish:
operator-sdk build $(IMAGE) && docker push $(IMAGE)

install-tools:
go get github.com/aws/aws-sdk-go/aws/session
go get github.com/aws/aws-sdk-go/service/secretsmanager
go get github.com/pkg/errors
15 changes: 11 additions & 4 deletions pkg/controller/awssecret/secret.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package awssecret

import (
"encoding/json"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/secretsmanager"
"encoding/json"
"github.com/mumoshu/aws-secret-operator/pkg/apis/mumoshu/v1alpha1"
)

type Context struct {
s *session.Session
s *session.Session
sm *secretsmanager.SecretsManager
}

Expand All @@ -28,7 +28,7 @@ func (c *Context) String(secretId string, versionId string) (*string, error) {
}

getSecInput := &secretsmanager.GetSecretValueInput{
SecretId: &secretId,
SecretId: &secretId,
VersionId: &versionId,
}

Expand All @@ -47,7 +47,14 @@ func (c *Context) SecretsManagerSecretToKubernetesStringData(ref v1alpha1.Secret
}
m := map[string]string{}
if err := json.Unmarshal([]byte(*sec), &m); err != nil {
return nil, err
type Port struct {
Number json.Number `json:"port"`
}
port := Port{}
if err := json.Unmarshal([]byte(*sec), &port); err != nil {
return nil, err
}
m["port"] = string(port.Number)
}
return m, nil
}

0 comments on commit 27a4856

Please sign in to comment.