|
| 1 | +package objectstorage |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/UpCloudLtd/upcloud-cli/v3/internal/commands" |
| 5 | + "github.com/UpCloudLtd/upcloud-cli/v3/internal/format" |
| 6 | + "github.com/UpCloudLtd/upcloud-cli/v3/internal/labels" |
| 7 | + "github.com/UpCloudLtd/upcloud-cli/v3/internal/output" |
| 8 | + "github.com/UpCloudLtd/upcloud-cli/v3/internal/ui" |
| 9 | + "github.com/UpCloudLtd/upcloud-go-api/v6/upcloud/request" |
| 10 | +) |
| 11 | + |
| 12 | +// ShowCommand creates the "objectstorage show" command |
| 13 | +func ShowCommand() commands.Command { |
| 14 | + return &showCommand{ |
| 15 | + BaseCommand: commands.New( |
| 16 | + "show", |
| 17 | + "Show Managed object storage service details", |
| 18 | + "upctl objectstorage show 55199a44-4751-4e27-9394-7c7661910be8", |
| 19 | + ), |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +type showCommand struct { |
| 24 | + *commands.BaseCommand |
| 25 | +} |
| 26 | + |
| 27 | +// Execute implements commands.MultipleArgumentCommand |
| 28 | +func (c *showCommand) Execute(exec commands.Executor, uuid string) (output.Output, error) { |
| 29 | + svc := exec.All() |
| 30 | + objectStorage, err := svc.GetManagedObjectStorage(exec.Context(), &request.GetManagedObjectStorageRequest{UUID: uuid}) |
| 31 | + if err != nil { |
| 32 | + return nil, err |
| 33 | + } |
| 34 | + |
| 35 | + endpointRows := make([]output.TableRow, 0) |
| 36 | + for _, endpoint := range objectStorage.Endpoints { |
| 37 | + endpointRows = append(endpointRows, output.TableRow{ |
| 38 | + endpoint.DomainName, |
| 39 | + endpoint.Type, |
| 40 | + }) |
| 41 | + } |
| 42 | + |
| 43 | + endpointColumns := []output.TableColumn{ |
| 44 | + {Key: "domain_name", Header: "Domain"}, |
| 45 | + {Key: "type", Header: "Type"}, |
| 46 | + } |
| 47 | + |
| 48 | + networkRows := make([]output.TableRow, 0) |
| 49 | + for _, network := range objectStorage.Networks { |
| 50 | + networkUUID := "" |
| 51 | + if network.UUID != nil { |
| 52 | + networkUUID = *network.UUID |
| 53 | + } |
| 54 | + networkRows = append(networkRows, output.TableRow{ |
| 55 | + network.Name, |
| 56 | + networkUUID, |
| 57 | + network.Type, |
| 58 | + network.Family, |
| 59 | + }) |
| 60 | + } |
| 61 | + |
| 62 | + networkColumns := []output.TableColumn{ |
| 63 | + {Key: "name", Header: "Name"}, |
| 64 | + {Key: "uuid", Header: "UUID", Colour: ui.DefaultUUUIDColours, Format: format.PossiblyUnknownString}, |
| 65 | + {Key: "type", Header: "Type"}, |
| 66 | + {Key: "Family", Header: "Family"}, |
| 67 | + } |
| 68 | + |
| 69 | + userRows := make([]output.TableRow, 0) |
| 70 | + for _, user := range objectStorage.Users { |
| 71 | + userRows = append(userRows, output.TableRow{ |
| 72 | + user.Username, |
| 73 | + user.CreatedAt, |
| 74 | + user.UpdatedAt, |
| 75 | + user.OperationalState, |
| 76 | + }) |
| 77 | + } |
| 78 | + |
| 79 | + userColumns := []output.TableColumn{ |
| 80 | + {Key: "name", Header: "Username"}, |
| 81 | + {Key: "created_at", Header: "Created"}, |
| 82 | + {Key: "updated_at", Header: "Updated"}, |
| 83 | + {Key: "operational_state", Header: "Updated", Format: format.ObjectStorageUserOperationalState}, |
| 84 | + } |
| 85 | + |
| 86 | + // For JSON and YAML output, passthrough API response |
| 87 | + return output.MarshaledWithHumanOutput{ |
| 88 | + Value: objectStorage, |
| 89 | + Output: output.Combined{ |
| 90 | + output.CombinedSection{ |
| 91 | + Contents: output.Details{ |
| 92 | + Sections: []output.DetailSection{ |
| 93 | + { |
| 94 | + Title: "Overview:", |
| 95 | + Rows: []output.DetailRow{ |
| 96 | + {Title: "UUID:", Value: objectStorage.UUID, Colour: ui.DefaultUUUIDColours}, |
| 97 | + {Title: "Region:", Value: objectStorage.Region}, |
| 98 | + {Title: "Configured status:", Value: objectStorage.ConfiguredStatus, Format: format.ObjectStorageConfiguredStatus}, |
| 99 | + {Title: "Operational state:", Value: objectStorage.OperationalState, Format: format.ObjectStorageOperationalState}, |
| 100 | + {Title: "Created:", Value: objectStorage.CreatedAt}, |
| 101 | + {Title: "Updated:", Value: objectStorage.UpdatedAt}, |
| 102 | + }, |
| 103 | + }, |
| 104 | + }, |
| 105 | + }, |
| 106 | + }, |
| 107 | + labels.GetLabelsSectionWithResourceType(objectStorage.Labels, "managed object storage"), |
| 108 | + output.CombinedSection{ |
| 109 | + Key: "endpoints", |
| 110 | + Title: "Endpoints:", |
| 111 | + Contents: output.Table{ |
| 112 | + Columns: endpointColumns, |
| 113 | + Rows: endpointRows, |
| 114 | + EmptyMessage: "No endpoints found for this Managed object storage service.", |
| 115 | + }, |
| 116 | + }, |
| 117 | + output.CombinedSection{ |
| 118 | + Key: "networks", |
| 119 | + Title: "Networks:", |
| 120 | + Contents: output.Table{ |
| 121 | + Columns: networkColumns, |
| 122 | + Rows: networkRows, |
| 123 | + EmptyMessage: "No networks found for this Managed object storage service.", |
| 124 | + }, |
| 125 | + }, |
| 126 | + output.CombinedSection{ |
| 127 | + Key: "users", |
| 128 | + Title: "Users:", |
| 129 | + Contents: output.Table{ |
| 130 | + Columns: userColumns, |
| 131 | + Rows: userRows, |
| 132 | + EmptyMessage: "No users found for this Managed object storage service.", |
| 133 | + }, |
| 134 | + }, |
| 135 | + }, |
| 136 | + }, nil |
| 137 | +} |
0 commit comments