Skip to content

Commit f218d20

Browse files
amahajan-dolee-aaronandrewsomething
authored
Update doctl to support Spaces Keys API Updated (#1671)
* Update doctl to support Spaces Keys API * Update commands/spaces.go Co-authored-by: Andrew Starr-Bochicchio <[email protected]> * add spaces get key by access key id support * Update commands/spaces_keys.go Co-authored-by: Andrew Starr-Bochicchio <[email protected]> --------- Co-authored-by: Aaron Lee <[email protected]> Co-authored-by: Aaron Lee <[email protected]> Co-authored-by: Andrew Starr-Bochicchio <[email protected]>
1 parent e1bb04c commit f218d20

File tree

10 files changed

+880
-0
lines changed

10 files changed

+880
-0
lines changed

commands/command_config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ type CmdConfig struct {
7676
Serverless func() do.ServerlessService
7777
OAuth func() do.OAuthService
7878
PartnerNetworkConnects func() do.PartnerNetworkConnectsService
79+
SpacesKeys func() do.SpacesKeysService
7980
}
8081

8182
// NewCmdConfig creates an instance of a CmdConfig.
@@ -135,6 +136,7 @@ func NewCmdConfig(ns string, dc doctl.Config, out io.Writer, args []string, init
135136
c.PartnerNetworkConnects = func() do.PartnerNetworkConnectsService {
136137
return do.NewPartnerNetworkConnectsService(godoClient)
137138
}
139+
c.SpacesKeys = func() do.SpacesKeysService { return do.NewSpacesKeysService(godoClient) }
138140

139141
return nil
140142
},

commands/commands_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ type tcMocks struct {
256256
appDockerEngineClient *builder.MockDockerEngineClient
257257
oauth *domocks.MockOAuthService
258258
partnerNetworkConnects *domocks.MockPartnerNetworkConnectsService
259+
spacesKeys *domocks.MockSpacesKeysService
259260
}
260261

261262
func withTestClient(t *testing.T, tFn testFn) {
@@ -306,6 +307,7 @@ func withTestClient(t *testing.T, tFn testFn) {
306307
appDockerEngineClient: builder.NewMockDockerEngineClient(ctrl),
307308
oauth: domocks.NewMockOAuthService(ctrl),
308309
partnerNetworkConnects: domocks.NewMockPartnerNetworkConnectsService(ctrl),
310+
spacesKeys: domocks.NewMockSpacesKeysService(ctrl),
309311
}
310312

311313
testConfig := doctl.NewTestConfig()
@@ -364,6 +366,7 @@ func withTestClient(t *testing.T, tFn testFn) {
364366
Serverless: func() do.ServerlessService { return tm.serverless },
365367
OAuth: func() do.OAuthService { return tm.oauth },
366368
PartnerNetworkConnects: func() do.PartnerNetworkConnectsService { return tm.partnerNetworkConnects },
369+
SpacesKeys: func() do.SpacesKeysService { return tm.spacesKeys },
367370
}
368371

369372
tFn(config, tm)

commands/displayers/spaces_keys.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
Copyright 2018 The Doctl Authors All rights reserved.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package displayers
15+
16+
import (
17+
"io"
18+
19+
"github.com/digitalocean/doctl/do"
20+
)
21+
22+
type SpacesKey struct {
23+
SpacesKeys []do.SpacesKey
24+
}
25+
26+
var _ Displayable = &SpacesKey{}
27+
28+
// ColMap implements Displayable.
29+
func (s *SpacesKey) ColMap() map[string]string {
30+
return map[string]string{
31+
"Name": "Name",
32+
"AccessKey": "Access Key",
33+
"SecretKey": "Secret Key",
34+
"Grants": "Grants",
35+
"CreatedAt": "Created At",
36+
}
37+
}
38+
39+
// Cols implements Displayable.
40+
func (s *SpacesKey) Cols() []string {
41+
return []string{
42+
"Name",
43+
"AccessKey",
44+
"SecretKey",
45+
"Grants",
46+
"CreatedAt",
47+
}
48+
}
49+
50+
// JSON implements Displayable.
51+
func (s *SpacesKey) JSON(out io.Writer) error {
52+
return writeJSON(s.SpacesKeys, out)
53+
}
54+
55+
// KV implements Displayable.
56+
func (s *SpacesKey) KV() []map[string]any {
57+
out := make([]map[string]any, 0, len(s.SpacesKeys))
58+
59+
for _, key := range s.SpacesKeys {
60+
m := map[string]any{
61+
"Name": key.Name,
62+
"AccessKey": key.AccessKey,
63+
"SecretKey": key.SecretKey,
64+
"Grants": key.GrantString(),
65+
"CreatedAt": key.CreatedAt,
66+
}
67+
68+
out = append(out, m)
69+
}
70+
71+
return out
72+
}

commands/doit.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"time"
2323

2424
"github.com/digitalocean/doctl"
25+
2526
"github.com/fatih/color"
2627
"github.com/mattn/go-isatty"
2728
"github.com/spf13/cobra"
@@ -188,6 +189,7 @@ func addCommands() {
188189
DoitCmd.AddCommand(OneClicks())
189190
DoitCmd.AddCommand(Monitoring())
190191
DoitCmd.AddCommand(Serverless())
192+
DoitCmd.AddCommand(Spaces())
191193
}
192194

193195
func computeCmd() *Command {

commands/spaces.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright 2018 The Doctl Authors All rights reserved.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package commands
15+
16+
import "github.com/spf13/cobra"
17+
18+
func Spaces() *Command {
19+
cmd := &Command{
20+
Command: &cobra.Command{
21+
Use: "spaces",
22+
Aliases: []string{"sp"},
23+
Short: "Display commands that manage DigitalOcean Spaces.",
24+
Long: "The subcommands of `doctl spaces` allow you to access and manage Spaces.",
25+
GroupID: manageResourcesGroup,
26+
},
27+
}
28+
29+
cmd.AddCommand(SpacesKeys())
30+
31+
return cmd
32+
}

0 commit comments

Comments
 (0)