(ctx context.Context, app, addonUUID string)
| 13 | ) |
| 14 | |
| 15 | func List(ctx context.Context, app, addonUUID string) error { |
| 16 | isSupported, err := doesDatabaseHandleUserManagement(ctx, app, addonUUID) |
| 17 | if err != nil { |
| 18 | return errors.Wrap(ctx, err, "get user management information") |
| 19 | } |
| 20 | |
| 21 | if !isSupported { |
| 22 | io.Error(ErrDatabaseNotSupportUserManagement) |
| 23 | return nil |
| 24 | } |
| 25 | |
| 26 | c, err := config.ScalingoClient(ctx) |
| 27 | if err != nil { |
| 28 | return errors.Wrap(ctx, err, "get Scalingo client") |
| 29 | } |
| 30 | |
| 31 | databaseUsers, err := c.DatabaseListUsers(ctx, app, addonUUID) |
| 32 | if err != nil { |
| 33 | return errors.Wrap(ctx, err, "list the database's users") |
| 34 | } |
| 35 | |
| 36 | header := []string{"Username", "Read-Only", "Protected"} |
| 37 | if len(databaseUsers) > 0 && databaseUsers[0].DbmsAttributes != nil { |
| 38 | header = append(header, "Password Encryption") |
| 39 | } |
| 40 | |
| 41 | t := tablewriter.NewWriter(os.Stdout) |
| 42 | t.Header(header) |
| 43 | |
| 44 | for _, user := range databaseUsers { |
| 45 | line := []string{ |
| 46 | user.Name, |
| 47 | strconv.FormatBool(user.ReadOnly), |
| 48 | strconv.FormatBool(user.Protected), |
| 49 | } |
| 50 | if user.DbmsAttributes != nil { |
| 51 | line = append(line, user.DbmsAttributes.PasswordEncryption) |
| 52 | } |
| 53 | t.Append(line) |
| 54 | } |
| 55 | t.Render() |
| 56 | |
| 57 | return nil |
| 58 | } |
nothing calls this directly
no test coverage detected