Skip to content

Commit

Permalink
Merge pull request #4 from Bisnode/improve_output
Browse files Browse the repository at this point in the history
Improved output on secrets and added last-modified timestamp
  • Loading branch information
mdanielolsson authored May 15, 2020
2 parents d0ee2c5 + ffe7435 commit abfd7d0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
3 changes: 3 additions & 0 deletions cmd/create_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ func CreateSecret(clientSet kubernetes.Interface, secretName, container *string,
"tbac.bisnode.com/container": *container,
"tbac.bisnode.com/sandbox": fmt.Sprintf("%v", sandbox),
},
Annotations: map[string]string{
"tbac.bisnode.com/last-modified": fmt.Sprintf("%v", metav1.Now().Rfc3339Copy()),
},
},
Data: util.AssembleInputData(data),
}
Expand Down
19 changes: 14 additions & 5 deletions cmd/get_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type SecretDescription struct {
Namespace string
Name string
CreationTimestamp metav1.Time
LastUpdated string
Service string
Container string
Data map[string][]byte
}

Expand Down Expand Up @@ -69,13 +72,16 @@ var getSecretCmd = &cobra.Command{

// PrettyPrintSecretDesc pretty prints a secret as a table view
func (s *SecretDescription) PrettyPrintSecretDesc() {
fmt.Printf("Namespace:\t%v\n", s.Namespace)
fmt.Printf("Secret name:\t%v\n", s.Name)
fmt.Printf("Created:\t%v\n", s.CreationTimestamp)
fmt.Printf("Secret name:%v%v\n", strings.Repeat(" ", 25-len("Secret Name:")), s.Name)
fmt.Printf("Service (app label):%v%v\n", strings.Repeat(" ", 25-len("Service (app label):")), s.Service)
fmt.Printf("Container:%v%v\n", strings.Repeat(" ", 25-len("Container:")), s.Container)
fmt.Printf("Namespace:%v%v\n", strings.Repeat(" ", 25-len("Namespace:")), s.Namespace)
fmt.Printf("Created:%v%v\n", strings.Repeat(" ", 25-len("Created:")), s.CreationTimestamp)
fmt.Printf("Last updated:%v%v\n\n", strings.Repeat(" ", 25-len("Last updated:")), s.LastUpdated)
if len(s.Data) > 0 {
fmt.Println(strings.Repeat("-", 46))
fmt.Println(strings.Repeat("-", 25), "DATA", strings.Repeat("-", 25))
for k, v := range s.Data {
fmt.Printf("%v:\n%v\n\n", k, string(v))
fmt.Printf("%v=%v\n", k, string(v))
}
}
}
Expand Down Expand Up @@ -117,6 +123,9 @@ func GetSecretDescription(clientSet kubernetes.Interface, secretName string) (se
secretDesc = &SecretDescription{
Namespace: Namespace,
Name: secretName,
LastUpdated: secrets.Items[0].Annotations["tbac.bisnode.com/last-modified"],
Service: secrets.Items[0].Labels["app"],
Container: secrets.Items[0].Labels["tbac.bisnode.com/container"],
CreationTimestamp: secrets.Items[0].CreationTimestamp,
Data: data,
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/patch_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ func PatchSecret(clientSet kubernetes.Interface, secretName *string, removeData,
patchSecret.Data[k] = v
}

if patchSecret.Annotations == nil {
patchSecret.Annotations = make(map[string]string)
}

patchSecret.Annotations["tbac.bisnode.com/last-modified"] = fmt.Sprintf("%v", metav1.Now().Rfc3339Copy())
patch, err := json.Marshal(patchSecret)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ k8s.io/apimachinery v0.17.4 h1:UzM+38cPUJnzqSQ+E1PY4YxMHIzQyCg29LOoGfo79Zw=
k8s.io/apimachinery v0.17.4/go.mod h1:gxLnyZcGNdZTCLnq3fgzyg2A5BVCHTNDFrw8AmuJ+0g=
k8s.io/apimachinery v0.18.0 h1:fuPfYpk3cs1Okp/515pAf0dNhL66+8zk8RLbSX+EgAE=
k8s.io/apimachinery v0.18.0/go.mod h1:9SnR/e11v5IbyPCGbvJViimtJ0SwHG4nfZFjU77ftcA=
k8s.io/apimachinery v0.18.1 h1:hKPYcQRPLQoG2e7fKkVl0YCvm9TBefXTfGILa9vjVVk=
k8s.io/apimachinery v0.18.2 h1:44CmtbmkzVDAhCpRVSiP2R5PPrC2RtlIv/MoB8xpdRA=
k8s.io/client-go v0.15.11 h1:yujXordVnH33fhe1bddPnFWsGfl0Gq6FyZ335TC3qk4=
k8s.io/client-go v0.15.11/go.mod h1:gkprEfouvgHvzeCvwwz2T8MTlfNuZn8vluW8orojRKI=
k8s.io/client-go v1.5.1 h1:XaX/lo2/u3/pmFau8HN+sB5C/b4dc4Dmm2eXjBH4p1E=
Expand Down
16 changes: 16 additions & 0 deletions tests/testdata/secrets.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package testdata

import (
"fmt"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -11,6 +13,13 @@ var GenerateSecrets = []v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "my-credentials",
Namespace: "default",
Labels: map[string]string{
"app": "my-credentials",
"tbac.bisnode.com/container": "default",
},
Annotations: map[string]string{
"tbac.bisnode.com/last-modified": fmt.Sprintf("%v", metav1.Now().Rfc3339Copy()),
},
},
Data: map[string][]byte{
"USERNAME": []byte("foo"),
Expand All @@ -22,6 +31,13 @@ var GenerateSecrets = []v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "my-api-key",
Namespace: "default",
Labels: map[string]string{
"app": "my-api-key",
"tbac.bisnode.com/container": "default",
},
Annotations: map[string]string{
"tbac.bisnode.com/last-modified": fmt.Sprintf("%v", metav1.Now().Rfc3339Copy()),
},
},
Data: map[string][]byte{
"URL": []byte("github.com"),
Expand Down

0 comments on commit abfd7d0

Please sign in to comment.