Skip to content

Commit

Permalink
Add age and backend to list-secrets output; go fmt added new go:build…
Browse files Browse the repository at this point in the history
… lines
  • Loading branch information
wallyworld committed Aug 18, 2021
1 parent 643c5e7 commit 7a3dcfa
Show file tree
Hide file tree
Showing 112 changed files with 150 additions and 31 deletions.
1 change: 1 addition & 0 deletions api/reboot/reboot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright 2014 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build !ppc64
// +build !ppc64

package reboot_test
Expand Down
1 change: 1 addition & 0 deletions api/secrets/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (api *Client) ListSecrets(showSecrets bool) ([]SecretDetails, error) {
Description: r.Description,
Tags: r.Tags,
ID: r.ID,
Provider: r.Provider,
ProviderID: r.ProviderID,
Revision: r.Revision,
CreateTime: r.CreateTime,
Expand Down
2 changes: 2 additions & 0 deletions api/secrets/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (s *SecretsSuite) TestListSecrets(c *gc.C) {
Description: "shhh",
Tags: map[string]string{"foo": "bar"},
ID: 1,
Provider: "juju",
ProviderID: "provider-id",
Revision: 2,
CreateTime: now,
Expand All @@ -70,6 +71,7 @@ func (s *SecretsSuite) TestListSecrets(c *gc.C) {
Description: "shhh",
Tags: map[string]string{"foo": "bar"},
ID: 1,
Provider: "juju",
ProviderID: "provider-id",
Revision: 2,
CreateTime: now,
Expand Down
9 changes: 6 additions & 3 deletions apiserver/facades/client/secrets/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,21 @@ func (s *SecretsAPI) ListSecrets(arg params.ListSecretsArgs) (params.ListSecretR
if err != nil {
return result, errors.Trace(err)
}
result.Results = make([]params.ListSecretResult, len(metadata))
for i, m := range metadata {
result.Results = append(result.Results, params.ListSecretResult{
secretResult := params.ListSecretResult{
Path: m.Path,
Scope: string(m.Scope),
Version: m.Version,
Description: m.Description,
Tags: m.Tags,
ID: m.ID,
Provider: m.Provider,
ProviderID: m.ProviderID,
Revision: m.Revision,
CreateTime: m.CreateTime,
UpdateTime: m.UpdateTime,
})
}
if arg.ShowSecrets {
URL := &coresecrets.URL{
Version: fmt.Sprintf("v%d", m.Version),
Expand All @@ -116,8 +118,9 @@ func (s *SecretsAPI) ListSecrets(arg params.ListSecretsArgs) (params.ListSecretR
if err == nil {
valueResult.Data = val.EncodedValues()
}
result.Results[i].Value = valueResult
secretResult.Value = valueResult
}
result.Results[i] = secretResult
}
return result, nil
}
2 changes: 2 additions & 0 deletions apiserver/facades/client/secrets/secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (s *SecretsSuite) assertListSecrets(c *gc.C, show bool) {
Description: "shhh",
Tags: map[string]string{"foo": "bar"},
ID: 666,
Provider: "juju",
ProviderID: "abcd",
Revision: 2,
CreateTime: now,
Expand Down Expand Up @@ -113,6 +114,7 @@ func (s *SecretsSuite) assertListSecrets(c *gc.C, show bool) {
Description: "shhh",
Tags: map[string]string{"foo": "bar"},
ID: 666,
Provider: "juju",
ProviderID: "abcd",
Revision: 2,
CreateTime: now,
Expand Down
4 changes: 4 additions & 0 deletions apiserver/facades/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -39738,6 +39738,9 @@
"path": {
"type": "string"
},
"provider": {
"type": "string"
},
"provider-id": {
"type": "string"
},
Expand Down Expand Up @@ -39772,6 +39775,7 @@
"scope",
"version",
"int",
"provider",
"revision",
"create-time",
"update-time"
Expand Down
1 change: 1 addition & 0 deletions apiserver/params/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type ListSecretResult struct {
Description string `json:"description,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
ID int `json:"int"`
Provider string `json:"provider"`
ProviderID string `json:"provider-id,omitempty"`
Revision int `json:"revision"`
CreateTime time.Time `json:"create-time"`
Expand Down
1 change: 1 addition & 0 deletions caas/kubernetes/provider/exec/termsize_unix.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build !windows
// +build !windows

package exec
Expand Down
1 change: 1 addition & 0 deletions caas/kubernetes/provider/exec/termsize_unix_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build aix || dragonfly || freebsd || (js && wasm) || linux || netbsd || openbsd || solaris
// +build aix dragonfly freebsd js,wasm linux netbsd openbsd solaris

package exec_test
Expand Down
3 changes: 2 additions & 1 deletion caas/kubernetes/provider/exec/termsize_windows.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

//+build windows
//go:build windows
// +build windows

package exec

Expand Down
1 change: 1 addition & 0 deletions charmhub/client_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build integration
// +build integration

// Copyright 2020 Canonical Ltd.
Expand Down
1 change: 1 addition & 0 deletions charmhub/find_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build integration
// +build integration

// Copyright 2020 Canonical Ltd.
Expand Down
1 change: 1 addition & 0 deletions charmhub/info_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build integration
// +build integration

// Copyright 2020 Canonical Ltd.
Expand Down
1 change: 1 addition & 0 deletions charmhub/refresh_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build integration
// +build integration

// Copyright 2020 Canonical Ltd.
Expand Down
1 change: 1 addition & 0 deletions cmd/containeragent/initialize/command_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build !windows
// +build !windows

package initialize_test
Expand Down
1 change: 1 addition & 0 deletions cmd/containeragent/initialize/config_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build !windows
// +build !windows

package initialize_test
Expand Down
1 change: 1 addition & 0 deletions cmd/containeragent/initialize/export_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build !windows
// +build !windows

package initialize
Expand Down
1 change: 1 addition & 0 deletions cmd/containeragent/initialize/package_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build !windows
// +build !windows

package initialize_test
Expand Down
1 change: 1 addition & 0 deletions cmd/containeragent/main_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build !windows
// +build !windows

package main
Expand Down
1 change: 1 addition & 0 deletions cmd/containeragent/package_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build !windows
// +build !windows

package main
Expand Down
1 change: 1 addition & 0 deletions cmd/containeragent/unit/agent_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build !windows
// +build !windows

package unit_test
Expand Down
1 change: 1 addition & 0 deletions cmd/containeragent/unit/export_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build !windows
// +build !windows

package unit
Expand Down
1 change: 1 addition & 0 deletions cmd/containeragent/unit/manifolds_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build !windows
// +build !windows

package unit_test
Expand Down
1 change: 1 addition & 0 deletions cmd/containeragent/unit/package_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build !windows
// +build !windows

package unit_test
Expand Down
1 change: 1 addition & 0 deletions cmd/juju/commands/scp_unix_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build !windows
// +build !windows

package commands
Expand Down
1 change: 1 addition & 0 deletions cmd/juju/commands/ssh_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright 2014 Cloudbase Solutions SRL
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build !windows
// +build !windows

package commands
Expand Down
11 changes: 8 additions & 3 deletions cmd/juju/secrets/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

apisecrets "github.com/juju/juju/api/secrets"
jujucmd "github.com/juju/juju/cmd"
"github.com/juju/juju/cmd/juju/common"
"github.com/juju/juju/cmd/modelcmd"
"github.com/juju/juju/cmd/output"
"github.com/juju/juju/core/secrets"
Expand Down Expand Up @@ -99,7 +100,8 @@ type secretDisplayDetails struct {
Version int `json:"version" yaml:"version"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Tags map[string]string `json:"tags,omitempty" yaml:"tags,omitempty"`
ProviderID string `json:"provider-id,omitempty" yaml:"provider-id,omitempty"`
Provider string `json:"backend" yaml:"backend"`
ProviderID string `json:"backend-id,omitempty" yaml:"backend-id,omitempty"`
CreateTime time.Time `json:"create-time" yaml:"create-time"`
UpdateTime time.Time `json:"update-time" yaml:"update-time"`
Value *secretValueDetails `json:"value,omitempty" yaml:"value,omitempty"`
Expand Down Expand Up @@ -131,6 +133,7 @@ func (c *listSecretsCommand) Run(ctxt *cmd.Context) error {
Description: m.Metadata.Description,
Tags: m.Metadata.Tags,
ID: m.Metadata.ID,
Provider: m.Metadata.Provider,
ProviderID: m.Metadata.ProviderID,
Revision: m.Metadata.Revision,
CreateTime: m.Metadata.CreateTime,
Expand Down Expand Up @@ -165,12 +168,14 @@ func formatSecretsTabular(writer io.Writer, value interface{}) error {
w := output.Wrapper{tw}
w.SetColumnAlignRight(1)

w.Println("ID", "Scope", "Revision", "Path")
w.Println("ID", "Scope", "Revision", "Backend", "Path", "Age")
sort.Slice(secrets, func(i, j int) bool {
return secrets[i].Path < secrets[j].Path
})
now := time.Now()
for _, s := range secrets {
w.Print(s.ID, s.Scope, s.Revision, s.Path)
age := common.UserFriendlyDuration(s.UpdateTime, now)
w.Print(s.ID, s.Scope, s.Revision, s.Provider, s.Path, age)
w.Println()
}
return tw.Flush()
Expand Down
13 changes: 7 additions & 6 deletions cmd/juju/secrets/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ func (s *ListSuite) TestListTabular(c *gc.C) {
[]apisecrets.SecretDetails{{
Metadata: coresecrets.SecretMetadata{
ID: 666, Scope: coresecrets.ScopeApplication,
Revision: 2, Path: "app.password"},
Revision: 2, Path: "app.password", Provider: "juju"},
}}, nil)
s.secretsAPI.EXPECT().Close().Return(nil)

ctx, err := cmdtesting.RunCommand(c, secrets.NewListCommandForTest(s.store, s.secretsAPI))
c.Assert(err, jc.ErrorIsNil)
out := cmdtesting.Stdout(ctx)
c.Assert(out, gc.Equals, `
ID Scope Revision Path
666 application 2 app.password
ID Scope Revision Backend Path Age
666 application 2 juju app.password 0001-01-01
`[1:])
}
Expand All @@ -69,7 +69,7 @@ func (s *ListSuite) TestListYAML(c *gc.C) {
[]apisecrets.SecretDetails{{
Metadata: coresecrets.SecretMetadata{
ID: 666, Scope: coresecrets.ScopeApplication,
Version: 1, Revision: 2, Path: "app.password"},
Version: 1, Revision: 2, Path: "app.password", Provider: "juju"},
Value: coresecrets.NewSecretValue(map[string]string{"foo": "YmFy"}),
}}, nil)
s.secretsAPI.EXPECT().Close().Return(nil)
Expand All @@ -83,6 +83,7 @@ func (s *ListSuite) TestListYAML(c *gc.C) {
path: app.password
scope: application
version: 1
backend: juju
create-time: 0001-01-01T00:00:00Z
update-time: 0001-01-01T00:00:00Z
value:
Expand All @@ -97,7 +98,7 @@ func (s *ListSuite) TestListJSON(c *gc.C) {
[]apisecrets.SecretDetails{{
Metadata: coresecrets.SecretMetadata{
ID: 666, Scope: coresecrets.ScopeApplication,
Version: 1, Revision: 2, Path: "app.password"},
Version: 1, Revision: 2, Path: "app.password", Provider: "juju"},
Value: coresecrets.NewSecretValue(map[string]string{"foo": "YmFy"}),
}}, nil)
s.secretsAPI.EXPECT().Close().Return(nil)
Expand All @@ -106,6 +107,6 @@ func (s *ListSuite) TestListJSON(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)
out := cmdtesting.Stdout(ctx)
c.Assert(out, gc.Equals, `
[{"ID":666,"revision":2,"path":"app.password","scope":"application","version":1,"create-time":"0001-01-01T00:00:00Z","update-time":"0001-01-01T00:00:00Z","value":{"Data":{"foo":"bar"}}}]
[{"ID":666,"revision":2,"path":"app.password","scope":"application","version":1,"backend":"juju","create-time":"0001-01-01T00:00:00Z","update-time":"0001-01-01T00:00:00Z","value":{"Data":{"foo":"bar"}}}]
`[1:])
}
1 change: 1 addition & 0 deletions cmd/juju/version_canary.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build !go1.6
// +build !go1.6

package main
Expand Down
1 change: 1 addition & 0 deletions cmd/jujuc/main_nix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright 2014 Cloudbase Solutions
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build !windows
// +build !windows

package main
Expand Down
1 change: 1 addition & 0 deletions cmd/jujuc/version_canary.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build !go1.6
// +build !go1.6

package main
Expand Down
1 change: 1 addition & 0 deletions cmd/jujud/main_nix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright 2014 Cloudbase Solutions
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build !windows
// +build !windows

package main
Expand Down
1 change: 1 addition & 0 deletions cmd/jujud/reboot/reboot_nix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright 2014 Cloudbase Solutions SRL
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build !windows
// +build !windows

package reboot
Expand Down
1 change: 1 addition & 0 deletions cmd/jujud/reboot/reboot_nix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright 2014 Cloudbase Solutions SRL
// Licensed under the AGPLv3, see LICENCE file for details.

//go:build !windows
// +build !windows

package reboot
Expand Down
Loading

0 comments on commit 7a3dcfa

Please sign in to comment.