Skip to content

Commit 45fbdcf

Browse files
jremy42remyleone
andauthored
fix(rdb): allow toggling is-admin without password when generate-pass… (#4719)
Co-authored-by: Rémy Léone <[email protected]>
1 parent cddd6a2 commit 45fbdcf

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

internal/namespaces/audit_trail/v1alpha1/audit_trail_cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"reflect"
99

1010
"github.com/scaleway/scaleway-cli/v2/core"
11-
"github.com/scaleway/scaleway-sdk-go/api/audit_trail/v1alpha1"
11+
audit_trail "github.com/scaleway/scaleway-sdk-go/api/audit_trail/v1alpha1"
1212
"github.com/scaleway/scaleway-sdk-go/scw"
1313
)
1414

internal/namespaces/inference/v1beta1/custom_endpoint.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ func endpointCreateBuilder(c *core.Command) *core.Command {
4242
endpointToCreate.Public = publicEndpoint
4343
}
4444
if endpoint.PrivateNetwork != nil && endpoint.PrivateNetwork.PrivateNetworkID != "" {
45-
endpointToCreate.PrivateNetwork = &inference.EndpointSpecPrivateNetwork{PrivateNetworkID: endpoint.PrivateNetwork.PrivateNetworkID}
45+
endpointToCreate.PrivateNetwork = &inference.EndpointSpecPrivateNetwork{
46+
PrivateNetworkID: endpoint.PrivateNetwork.PrivateNetworkID,
47+
}
4648
}
4749
createEndpointreq.Endpoint = &endpointToCreate
4850

internal/namespaces/rdb/v1/custom_user.go

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"reflect"
88

99
"github.com/scaleway/scaleway-cli/v2/core"
10+
"github.com/scaleway/scaleway-cli/v2/internal/interactive"
1011
"github.com/scaleway/scaleway-cli/v2/internal/passwordgenerator"
1112
"github.com/scaleway/scaleway-sdk-go/api/rdb/v1"
1213
"github.com/scaleway/scaleway-sdk-go/scw"
@@ -170,34 +171,48 @@ func userUpdateBuilder(c *core.Command) *core.Command {
170171
api := rdb.NewAPI(client)
171172

172173
customRequest := argsI.(*rdbUpdateUserRequestCustom)
173-
174174
updateUserRequest := customRequest.UpdateUserRequest
175175

176176
var err error
177-
if customRequest.GeneratePassword && customRequest.Password == nil {
178-
updateUserRequest.Password = new(string)
179-
*updateUserRequest.Password, err = passwordgenerator.GeneratePassword(21, 1, 1, 1, 1)
180-
if err != nil {
181-
return nil, err
182-
}
183-
fmt.Printf("Your generated password is %v \n", *updateUserRequest.Password)
184-
fmt.Printf("\n")
185-
}
186177

187-
if !customRequest.GeneratePassword && customRequest.Password == nil {
188-
return nil, errors.New(
189-
"you must provide a password when generate-password is set to false",
190-
)
178+
if customRequest.GeneratePassword || customRequest.Password != nil {
179+
switch {
180+
case customRequest.GeneratePassword && customRequest.Password == nil:
181+
updateUserRequest.Password = new(string)
182+
pwd, err := passwordgenerator.GeneratePassword(21, 1, 1, 1, 1)
183+
if err != nil {
184+
return nil, err
185+
}
186+
*updateUserRequest.Password = pwd
187+
188+
_, err = interactive.Println("Your generated password is", pwd)
189+
if err != nil {
190+
return nil, err
191+
}
192+
193+
case !customRequest.GeneratePassword && customRequest.Password == nil:
194+
return nil, errors.New(
195+
"you must provide a password when generate-password is set to false",
196+
)
197+
198+
default:
199+
updateUserRequest.Password = customRequest.Password
200+
}
191201
}
192202

193203
user, err := api.UpdateUser(updateUserRequest)
194204
if err != nil {
195205
return nil, err
196206
}
197207

208+
respPwd := ""
209+
if updateUserRequest.Password != nil {
210+
respPwd = *updateUserRequest.Password
211+
}
212+
198213
result := rdbUpdateUserResponseCustom{
199214
User: user,
200-
Password: *updateUserRequest.Password,
215+
Password: respPwd,
201216
}
202217

203218
return result, nil

0 commit comments

Comments
 (0)