Skip to content

Commit 9a7c87f

Browse files
Merge remote-tracking branch 'origin/main' into pkg-deploy-extract-only
2 parents 12710ab + 1955518 commit 9a7c87f

File tree

16 files changed

+493
-65
lines changed

16 files changed

+493
-65
lines changed

.github/workflows/release-perform.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131

3232
- uses: actions/setup-go@v3
3333
with:
34-
go-version: '1.20'
34+
go-version: '1.24'
3535
cache: true
3636

3737
- uses: goreleaser/goreleaser-action@v2

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
steps:
2121
- name: Cache Go modules
22-
uses: actions/cache@v2
22+
uses: actions/cache@v4
2323
with:
2424
path: |
2525
~/.cache/go-build
@@ -29,13 +29,13 @@ jobs:
2929
${{ runner.os }}-go-
3030
3131
- name: Set up Go
32-
uses: actions/setup-go@v2
32+
uses: actions/setup-go@v5
3333
with:
34-
go-version: '1.20'
34+
go-version: '1.24'
3535
id: go
3636

3737
- name: Checkout source code
38-
uses: actions/checkout@v3
38+
uses: actions/checkout@v4
3939

4040
- name: Run build
4141
run: make

cmd/aem/cli.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import (
55
"bytes"
66
"encoding/json"
77
"fmt"
8+
"io"
9+
"os"
10+
"path"
11+
"reflect"
12+
"sort"
13+
"strings"
14+
"time"
15+
816
"github.com/fatih/color"
917
"github.com/iancoleman/strcase"
1018
"github.com/jmespath-community/go-jmespath"
@@ -18,13 +26,6 @@ import (
1826
"github.com/wttech/aemc/pkg/common/fmtx"
1927
"github.com/wttech/aemc/pkg/common/pathx"
2028
"github.com/wttech/aemc/pkg/common/stringsx"
21-
"io"
22-
"os"
23-
"path"
24-
"reflect"
25-
"sort"
26-
"strings"
27-
"time"
2829
)
2930

3031
const (
@@ -206,7 +207,7 @@ func (c *CLI) openOutputLogFile() *os.File {
206207
}
207208
file, err := os.OpenFile(c.outputLogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
208209
if err != nil {
209-
log.Fatalf(fmt.Sprintf("cannot open/create CLI output file '%s': %s", c.outputLogFile, err))
210+
log.Fatalf("cannot open/create CLI output file '%s': %s", c.outputLogFile, err)
210211
}
211212
return file
212213
}
@@ -231,13 +232,13 @@ func (c *CLI) printCommandResult() {
231232
if c.outputNoColor {
232233
entry := log.WithField("changed", r.Changed).WithField("elapsed", r.Elapsed)
233234
if r.Failed {
234-
entry.Errorf(msg)
235+
entry.Error(msg)
235236
} else {
236-
entry.Infof(msg)
237+
entry.Info(msg)
237238
}
238239
} else {
239240
if r.Failed {
240-
log.Errorf(color.RedString(msg))
241+
log.Error(color.RedString(msg))
241242
} else {
242243
if r.Changed {
243244
log.Info(color.YellowString(msg))

cmd/aem/user.go

Lines changed: 164 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package main
22

3-
import "github.com/spf13/cobra"
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
48

59
func (c *CLI) userCmd() *cobra.Command {
610
cmd := &cobra.Command{
@@ -9,6 +13,8 @@ func (c *CLI) userCmd() *cobra.Command {
913
Aliases: []string{"usr"},
1014
}
1115
cmd.AddCommand(c.userKeyStore())
16+
cmd.AddCommand(c.userKey())
17+
cmd.AddCommand(c.userPassword())
1218
return cmd
1319
}
1420

@@ -24,10 +30,31 @@ func (c *CLI) userKeyStore() *cobra.Command {
2430
return cmd
2531
}
2632

33+
func (c *CLI) userKey() *cobra.Command {
34+
cmd := &cobra.Command{
35+
Use: "key",
36+
Short: "Private keys management",
37+
Aliases: []string{"keys"},
38+
}
39+
cmd.AddCommand(c.userKeyAdd())
40+
cmd.AddCommand(c.userKeyDelete())
41+
return cmd
42+
}
43+
44+
func (c *CLI) userPassword() *cobra.Command {
45+
cmd := &cobra.Command{
46+
Use: "password",
47+
Short: "Password management",
48+
Aliases: []string{"pwd"},
49+
}
50+
cmd.AddCommand(c.UserPasswordSet())
51+
return cmd
52+
}
53+
2754
func (c *CLI) KeystoreStatus() *cobra.Command {
2855
cmd := &cobra.Command{
2956
Use: "status",
30-
Short: "Get status of keystore",
57+
Short: "Get status of a user keystore",
3158
Aliases: []string{"show", "get", "read", "describe", "ls"},
3259
Run: func(cmd *cobra.Command, args []string) {
3360
instance, err := c.aem.InstanceManager().One()
@@ -39,7 +66,7 @@ func (c *CLI) KeystoreStatus() *cobra.Command {
3966
id, _ := cmd.Flags().GetString("id")
4067
scope, _ := cmd.Flags().GetString("scope")
4168

42-
result, err := instance.Auth().UserManager().KeystoreStatus(scope, id)
69+
result, err := instance.Auth().UserManager().Keystore().Status(scope, id)
4370

4471
if err != nil {
4572
c.Error(err)
@@ -53,14 +80,13 @@ func (c *CLI) KeystoreStatus() *cobra.Command {
5380
cmd.Flags().String("id", "", "user id")
5481
_ = cmd.MarkFlagRequired("id")
5582
cmd.Flags().String("scope", "", "user scope")
56-
_ = cmd.MarkFlagRequired("scope")
5783
return cmd
5884
}
5985

6086
func (c *CLI) KeystoreCreate() *cobra.Command {
6187
cmd := &cobra.Command{
6288
Use: "create",
63-
Short: "Create user Keystore",
89+
Short: "Create user keystore",
6490
Aliases: []string{"make", "new"},
6591
Run: func(cmd *cobra.Command, args []string) {
6692
instance, err := c.aem.InstanceManager().One()
@@ -72,26 +98,155 @@ func (c *CLI) KeystoreCreate() *cobra.Command {
7298
id, _ := cmd.Flags().GetString("id")
7399
scope, _ := cmd.Flags().GetString("scope")
74100
password, _ := cmd.Flags().GetString("keystore-password")
75-
changed, err := instance.Auth().UserManager().KeystoreCreate(scope, id, password)
101+
changed, err := instance.Auth().UserManager().Keystore().Create(scope, id, password)
102+
103+
if err != nil {
104+
c.Error(err)
105+
return
106+
}
107+
108+
if changed {
109+
c.Changed("User keystore created")
110+
} else {
111+
c.Ok("User keystore already exists")
112+
}
113+
},
114+
}
115+
116+
cmd.Flags().String("id", "", "user id")
117+
_ = cmd.MarkFlagRequired("id")
118+
cmd.Flags().String("scope", "", "user scope")
119+
cmd.Flags().String("keystore-password", "", "keystore password")
120+
_ = cmd.MarkFlagRequired("keystore-password")
121+
return cmd
122+
}
76123

124+
func (c *CLI) userKeyAdd() *cobra.Command {
125+
cmd := &cobra.Command{
126+
Use: "add",
127+
Short: "Add user private key to the keystore",
128+
Aliases: []string{"create", "new"},
129+
Run: func(cmd *cobra.Command, args []string) {
130+
instance, err := c.aem.InstanceManager().One()
77131
if err != nil {
78132
c.Error(err)
79133
return
80134
}
81135

136+
changed, err := instance.Auth().UserManager().Keystore().AddKey(
137+
cmd.Flag("scope").Value.String(),
138+
cmd.Flag("id").Value.String(),
139+
cmd.Flag("keystore-file").Value.String(),
140+
cmd.Flag("keystore-password").Value.String(),
141+
cmd.Flag("key-alias").Value.String(),
142+
cmd.Flag("key-password").Value.String(),
143+
cmd.Flag("new-alias").Value.String(),
144+
)
145+
146+
if err != nil {
147+
c.Error(err)
148+
return
149+
}
82150
if changed {
83-
c.Changed("User Keystore created")
151+
c.Changed("User key added")
84152
} else {
85-
c.Ok("User Keystore already exists")
153+
c.Ok("User key already exists")
86154
}
87155
},
88156
}
89157

90158
cmd.Flags().String("id", "", "user id")
91159
_ = cmd.MarkFlagRequired("id")
92160
cmd.Flags().String("scope", "", "user scope")
93-
_ = cmd.MarkFlagRequired("scope")
161+
cmd.Flags().String("keystore-file", "", "path to keystore file")
162+
_ = cmd.MarkFlagRequired("keystore-file")
94163
cmd.Flags().String("keystore-password", "", "keystore password")
95164
_ = cmd.MarkFlagRequired("keystore-password")
165+
cmd.Flags().String("key-alias", "", "key alias")
166+
_ = cmd.MarkFlagRequired("key-alias")
167+
cmd.Flags().String("key-password", "", "key password")
168+
cmd.Flags().String("new-alias", "", "new key alias (optional)")
169+
170+
return cmd
171+
}
172+
173+
func (c *CLI) userKeyDelete() *cobra.Command {
174+
cmd := &cobra.Command{
175+
Use: "delete",
176+
Short: "Delete user private key from the keystore",
177+
Aliases: []string{"remove", "rm"},
178+
Run: func(cmd *cobra.Command, args []string) {
179+
instance, err := c.aem.InstanceManager().One()
180+
if err != nil {
181+
c.Error(err)
182+
return
183+
}
184+
185+
changed, err := instance.Auth().UserManager().Keystore().DeleteKey(
186+
cmd.Flag("scope").Value.String(),
187+
cmd.Flag("id").Value.String(),
188+
cmd.Flag("key-alias").Value.String(),
189+
)
190+
191+
if err != nil {
192+
c.Error(err)
193+
return
194+
}
195+
if changed {
196+
c.Changed("User key deleted")
197+
} else {
198+
c.Ok("User key does not exist")
199+
}
200+
},
201+
}
202+
203+
cmd.Flags().String("id", "", "user id")
204+
_ = cmd.MarkFlagRequired("id")
205+
cmd.Flags().String("scope", "", "user scope")
206+
cmd.Flags().String("key-alias", "", "key alias")
207+
_ = cmd.MarkFlagRequired("key-alias")
208+
209+
return cmd
210+
}
211+
212+
func (c *CLI) UserPasswordSet() *cobra.Command {
213+
cmd := &cobra.Command{
214+
Use: "set",
215+
Short: "Set user password. Password is read from input.",
216+
Aliases: []string{"update", "change"},
217+
Run: func(cmd *cobra.Command, args []string) {
218+
instances, err := c.aem.InstanceManager().One()
219+
if err != nil {
220+
c.Error(err)
221+
return
222+
}
223+
224+
id, _ := cmd.Flags().GetString("id")
225+
scope, _ := cmd.Flags().GetString("scope")
226+
227+
var password string
228+
if err := c.ReadInput(&password); err != nil {
229+
c.Fail(fmt.Sprintf("error reading password from input: %s", err))
230+
return
231+
}
232+
233+
changed, err := instances.Auth().UserManager().SetPassword(scope, id, password)
234+
if err != nil {
235+
c.Error(err)
236+
return
237+
}
238+
239+
if changed {
240+
c.Changed("User password changed")
241+
} else {
242+
c.Ok("User password already set")
243+
}
244+
},
245+
}
246+
247+
cmd.Flags().String("id", "", "user id")
248+
_ = cmd.MarkFlagRequired("id")
249+
cmd.Flags().String("scope", "", "user scope")
250+
96251
return cmd
97252
}

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/wttech/aemc
22

3-
go 1.20
3+
go 1.24
44

55
require (
66
github.com/Masterminds/goutils v1.1.1
@@ -23,6 +23,7 @@ require (
2323
github.com/mholt/archiver/v3 v3.5.1
2424
github.com/olekukonko/tablewriter v0.0.5
2525
github.com/otiai10/copy v1.14.0
26+
github.com/pavlo-v-chernykh/keystore-go/v4 v4.5.0
2627
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
2728
github.com/samber/lo v1.39.0
2829
github.com/segmentio/textio v1.2.0

0 commit comments

Comments
 (0)