|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/urfave/cli/v3" |
| 7 | + |
| 8 | + "github.com/Scalingo/cli/cmd/autocomplete" |
| 9 | + "github.com/Scalingo/cli/dbng" |
| 10 | + "github.com/Scalingo/cli/detect" |
| 11 | + "github.com/Scalingo/cli/utils" |
| 12 | + "github.com/Scalingo/go-scalingo/v11" |
| 13 | +) |
| 14 | + |
| 15 | +var ( |
| 16 | + databaseNetPeeringsListCommand = cli.Command{ |
| 17 | + Name: "database-net-peerings", |
| 18 | + Category: "Databases DR", |
| 19 | + Usage: "List net peerings of a database", |
| 20 | + ArgsUsage: "database-id", |
| 21 | + Flags: []cli.Flag{databaseFlag()}, |
| 22 | + Description: CommandDescription{ |
| 23 | + Description: "List all net peerings of a database", |
| 24 | + Examples: []string{ |
| 25 | + "scalingo database-net-peerings my-db-id", |
| 26 | + "scalingo --database my-db database-net-peerings", |
| 27 | + }, |
| 28 | + SeeAlso: []string{"database-net-peerings-add", "database-net-peerings-remove", "database-network-configuration"}, |
| 29 | + }.Render(), |
| 30 | + Action: func(ctx context.Context, c *cli.Command) error { |
| 31 | + databaseID := detect.ExtractDatabaseNameFromCommandLineOrEnv(c) |
| 32 | + if databaseID == "" { |
| 33 | + return cli.ShowCommandHelp(ctx, c, "database-net-peerings") |
| 34 | + } |
| 35 | + utils.CheckForConsent(ctx, databaseID, utils.ConsentTypeDBs) |
| 36 | + |
| 37 | + err := dbng.DatabaseNetPeeringsList(ctx, databaseID) |
| 38 | + if err != nil { |
| 39 | + errorQuit(ctx, err) |
| 40 | + } |
| 41 | + |
| 42 | + return nil |
| 43 | + }, |
| 44 | + ShellComplete: func(ctx context.Context, c *cli.Command) { |
| 45 | + _ = autocomplete.CmdFlagsAutoComplete(c, "database-net-peerings") |
| 46 | + _ = autocomplete.DatabasesNgListAutoComplete(ctx) |
| 47 | + }, |
| 48 | + } |
| 49 | + |
| 50 | + databaseNetPeeringsAddCommand = cli.Command{ |
| 51 | + Name: "database-net-peerings-add", |
| 52 | + Category: "Databases DR", |
| 53 | + Usage: "Add a net peering to a database", |
| 54 | + ArgsUsage: "database-id", |
| 55 | + Flags: []cli.Flag{ |
| 56 | + databaseFlag(), |
| 57 | + &cli.StringFlag{ |
| 58 | + Name: "outscale-net-peering-id", |
| 59 | + Usage: "Outscale net peering ID", |
| 60 | + Required: true, |
| 61 | + }, |
| 62 | + }, |
| 63 | + Description: CommandDescription{ |
| 64 | + Description: "Initiate the creation of a net peering for a database", |
| 65 | + Examples: []string{ |
| 66 | + "scalingo database-net-peerings-add my-db-id --outscale-net-peering-id pcx-123456789", |
| 67 | + "scalingo --database my-db database-net-peerings-add --outscale-net-peering-id pcx-123456789", |
| 68 | + }, |
| 69 | + SeeAlso: []string{"database-net-peerings", "database-net-peerings-remove", "database-network-configuration"}, |
| 70 | + }.Render(), |
| 71 | + Action: func(ctx context.Context, c *cli.Command) error { |
| 72 | + databaseID := detect.ExtractDatabaseNameFromCommandLineOrEnv(c) |
| 73 | + if databaseID == "" { |
| 74 | + return cli.ShowCommandHelp(ctx, c, "database-net-peerings-add") |
| 75 | + } |
| 76 | + |
| 77 | + utils.CheckForConsent(ctx, databaseID, utils.ConsentTypeDBs) |
| 78 | + |
| 79 | + params := scalingo.DatabaseNetPeeringCreateParams{ |
| 80 | + OutscaleNetPeeringID: c.String("outscale-net-peering-id"), |
| 81 | + } |
| 82 | + |
| 83 | + err := dbng.DatabaseNetPeeringsAdd(ctx, databaseID, params) |
| 84 | + if err != nil { |
| 85 | + errorQuit(ctx, err) |
| 86 | + } |
| 87 | + |
| 88 | + return nil |
| 89 | + }, |
| 90 | + ShellComplete: func(ctx context.Context, c *cli.Command) { |
| 91 | + _ = autocomplete.CmdFlagsAutoComplete(c, "database-net-peerings-add") |
| 92 | + _ = autocomplete.DatabasesNgListAutoComplete(ctx) |
| 93 | + }, |
| 94 | + } |
| 95 | + |
| 96 | + databaseNetPeeringsRemoveCommand = cli.Command{ |
| 97 | + Name: "database-net-peerings-remove", |
| 98 | + Category: "Databases DR", |
| 99 | + Usage: "Remove a net peering from a database", |
| 100 | + ArgsUsage: "database-id net-peering-id", |
| 101 | + Flags: []cli.Flag{ |
| 102 | + databaseFlag(), |
| 103 | + &cli.StringFlag{ |
| 104 | + Name: "net-peering", |
| 105 | + Aliases: []string{"np"}, |
| 106 | + Usage: "Net peering ID to remove", |
| 107 | + }, |
| 108 | + }, |
| 109 | + Description: CommandDescription{ |
| 110 | + Description: "Delete an existing net peering from a database", |
| 111 | + Examples: []string{ |
| 112 | + "scalingo database-net-peerings-remove my-db-id np-id", |
| 113 | + "scalingo --database my-db database-net-peerings-remove np-id", |
| 114 | + }, |
| 115 | + SeeAlso: []string{"database-net-peerings", "database-net-peerings-add", "database-network-configuration"}, |
| 116 | + }.Render(), |
| 117 | + Action: func(ctx context.Context, c *cli.Command) error { |
| 118 | + databaseID := detect.ExtractDatabaseNameFromCommandLineOrEnv(c) |
| 119 | + if databaseID == "" { |
| 120 | + return cli.ShowCommandHelp(ctx, c, "database-net-peerings-remove") |
| 121 | + } |
| 122 | + |
| 123 | + utils.CheckForConsent(ctx, databaseID, utils.ConsentTypeDBs) |
| 124 | + |
| 125 | + err := dbng.DatabaseNetPeeringsRemove(ctx, databaseID, c.String("net-peering")) |
| 126 | + if err != nil { |
| 127 | + errorQuit(ctx, err) |
| 128 | + } |
| 129 | + |
| 130 | + return nil |
| 131 | + }, |
| 132 | + ShellComplete: func(ctx context.Context, c *cli.Command) { |
| 133 | + _ = autocomplete.CmdFlagsAutoComplete(c, "database-net-peerings-remove") |
| 134 | + _ = autocomplete.DatabasesNgListAutoComplete(ctx) |
| 135 | + }, |
| 136 | + } |
| 137 | + |
| 138 | + databaseNetworkConfigurationShowCommand = cli.Command{ |
| 139 | + Name: "database-network-configuration", |
| 140 | + Category: "Databases DR", |
| 141 | + Usage: "Show network configuration of a database", |
| 142 | + ArgsUsage: "database-id", |
| 143 | + Flags: []cli.Flag{databaseFlag()}, |
| 144 | + Description: CommandDescription{ |
| 145 | + Description: "Get network configuration of a database", |
| 146 | + Examples: []string{ |
| 147 | + "scalingo database-network-configuration my-db-id", |
| 148 | + "scalingo --database my-db database-network-configuration", |
| 149 | + }, |
| 150 | + SeeAlso: []string{"database-net-peerings", "database-net-peerings-add", "database-net-peerings-remove"}, |
| 151 | + }.Render(), |
| 152 | + Action: func(ctx context.Context, c *cli.Command) error { |
| 153 | + databaseID := detect.ExtractDatabaseNameFromCommandLineOrEnv(c) |
| 154 | + if databaseID == "" { |
| 155 | + return cli.ShowCommandHelp(ctx, c, "database-network-configuration") |
| 156 | + } |
| 157 | + |
| 158 | + utils.CheckForConsent(ctx, databaseID, utils.ConsentTypeDBs) |
| 159 | + |
| 160 | + err := dbng.DatabaseNetworkConfigurationShow(ctx, databaseID) |
| 161 | + if err != nil { |
| 162 | + errorQuit(ctx, err) |
| 163 | + } |
| 164 | + |
| 165 | + return nil |
| 166 | + }, |
| 167 | + ShellComplete: func(ctx context.Context, c *cli.Command) { |
| 168 | + _ = autocomplete.CmdFlagsAutoComplete(c, "database-network-configuration") |
| 169 | + _ = autocomplete.DatabasesNgListAutoComplete(ctx) |
| 170 | + }, |
| 171 | + } |
| 172 | +) |
0 commit comments