MCPcopy Create free account
hub / github.com/Scalingo/cli / DeleteUser

Function DeleteUser

db/users/delete.go:13–57  ·  view source on GitHub ↗
(ctx context.Context, app, addonUUID, username string)

Source from the content-addressed store, hash-verified

11)
12
13func DeleteUser(ctx context.Context, app, addonUUID, username string) error {
14 isSupported, err := doesDatabaseHandleUserManagement(ctx, app, addonUUID)
15 if err != nil {
16 return errors.Wrap(ctx, err, "get user management information")
17 }
18
19 if !isSupported {
20 io.Error(ErrDatabaseNotSupportUserManagement)
21 return nil
22 }
23
24 c, err := config.ScalingoClient(ctx)
25 if err != nil {
26 return errors.Wrap(ctx, err, "get Scalingo client")
27 }
28
29 databaseUsers, err := c.DatabaseListUsers(ctx, app, addonUUID)
30 if err != nil {
31 return errors.Wrap(ctx, err, "list the database's users")
32 }
33
34 var givenUser *scalingo.DatabaseUser
35 for _, user := range databaseUsers {
36 if strings.EqualFold(user.Name, username) {
37 givenUser = &user
38 break
39 }
40 }
41 if givenUser == nil {
42 io.Error("Confirmation failed: usernames do not match.")
43 return nil
44 }
45
46 if givenUser.Protected {
47 io.Error("Protected user is managed by the platform and cannot be deleted.")
48 return nil
49 }
50
51 err = c.DatabaseDeleteUser(ctx, app, addonUUID, username)
52 if err != nil {
53 return errors.Wrapf(ctx, err, "delete given user from database %v", username)
54 }
55 io.Statusf("User %v has been deleted\n", username)
56 return nil
57}

Callers

nothing calls this directly

Calls 4

ErrorFunction · 0.92
ScalingoClientFunction · 0.92
StatusfFunction · 0.92

Tested by

no test coverage detected