-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved help and secure bundle (#9)
* converted all commands to cobra, this only added 2 megs to the deploy on linux and I think is worth it * added secure bundle * updating docs to match
- Loading branch information
Showing
19 changed files
with
1,057 additions
and
500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,27 +29,35 @@ Apache 2.0 licensed Astra Cloud Management CLI | |
* login | ||
* execute commands on your database | ||
|
||
### login | ||
### login with token | ||
|
||
After creating a token with rights to use the devops api | ||
|
||
``` | ||
./bin/astra-cli login --token "changed" | ||
Login information saved | ||
``` | ||
### login service account | ||
|
||
After creating a service account on the Astra page | ||
|
||
``` | ||
./bin/astra-cli login -id "changed" -name "changed" -secret "changed" | ||
./bin/astra-cli login --id "changed" --name "changed" --secret "changed" | ||
Login information saved | ||
``` | ||
|
||
## login with json | ||
## login service account with json | ||
|
||
``` | ||
./bin/astra-cli login -json '{"clientId":"changed","clientName":"[email protected]","clientSecret":"changed"}' | ||
./bin/astra-cli login --json '{"clientId":"changed","clientName":"[email protected]","clientSecret":"changed"}' | ||
Login information saved | ||
``` | ||
|
||
### creating database | ||
|
||
``` | ||
./bin/astra-cli db create -user dbuser -password test234 -keyspace myks -name mydb | ||
./bin/astra-cli db create -v --keyspace myks --name mydb | ||
2021/02/24 18:23:24 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state PENDING but expected ACTIVE trying again 19 more times | ||
2021/02/24 18:23:29 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state PENDING but expected ACTIVE trying again 18 more times | ||
2021/02/24 18:23:35 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state PENDING but expected ACTIVE trying again 17 more times | ||
|
@@ -61,6 +69,25 @@ Login information saved | |
database 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b created | ||
``` | ||
|
||
### get secure connection bundle | ||
|
||
``` | ||
./bin/astra-cli db secBundle 3c577e51-4ff5-4551-86a4-41d475c61822 | ||
file secureBundle.zip saved 12072 bytes written | ||
``` | ||
|
||
### get secure connection bundle url | ||
|
||
``` | ||
./bin/astra-cli db secBundle 3c577e51-4ff5-4551-86a4-41d475c61822 -o json | ||
{ | ||
"downloadURL": "changed", | ||
"downloadURLInternal": "changed", | ||
"downloadURLMigrationProxy": "changed", | ||
"downloadURLMigrationProxyInternal": "changed" | ||
} | ||
``` | ||
|
||
### listing databases | ||
|
||
``` | ||
|
@@ -72,7 +99,7 @@ mydb 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b ACTIVE | |
### listing databases in json | ||
|
||
``` | ||
./bin/astra-cli db list -format json | ||
./bin/astra-cli db list -o json | ||
[ | ||
{ | ||
"id": "2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b", | ||
|
@@ -128,7 +155,7 @@ mydb 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b ACTIVE | |
### getting database by id in json | ||
|
||
``` | ||
./bin/astra-cli db get 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b -format json | ||
./bin/astra-cli db get 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b -o json | ||
json | ||
{ | ||
"id": "2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b", | ||
|
@@ -176,8 +203,10 @@ json | |
|
||
### parking database | ||
|
||
Does not work on serverless | ||
|
||
``` | ||
./bin/astra-cli db park 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b | ||
./bin/astra-cli db park -v 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b | ||
starting to park database 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b | ||
2021/02/24 18:31:26 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state PARKING but expected PARKED trying again 29 more times | ||
2021/02/24 18:31:56 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state PARKING but expected PARKED trying again 28 more times | ||
|
@@ -189,8 +218,10 @@ database 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b parked | |
|
||
### unparking database | ||
|
||
Does not work on serverless | ||
|
||
``` | ||
./bin/astra-cli db unpark 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b | ||
./bin/astra-cli db unpark -v 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b | ||
starting to unpark database 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b | ||
2021/02/25 08:41:02 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state UNPARKING but expected ACTIVE trying again 59 more times | ||
2021/02/25 08:41:32 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state UNPARKING but expected ACTIVE trying again 58 more times | ||
|
@@ -211,10 +242,10 @@ starting to unpark database 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b | |
database 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b unparked | ||
``` | ||
|
||
### deleteting database | ||
### deleting database | ||
|
||
``` | ||
./bin/astra-cli db delete 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b | ||
./bin/astra-cli db delete -v 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b | ||
starting to delete database 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b | ||
database 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b deleted | ||
``` | ||
|
@@ -224,5 +255,8 @@ database 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b deleted | |
I did not have a paid account to verify this works, but you can see it succesfully starts the process | ||
|
||
``` | ||
./bin/astra-cli db resize 72c4d35b-1875-495a-b5f1-97329d90b6c5 2 | ||
./bin/astra-cli db resize -v 72c4d35b-1875-495a-b5f1-97329d90b6c5 2 | ||
unable to unpark '72c4d35b-1875-495a-b5f1-97329d90b6c5' with error expected status code 2xx but had: 400 error was [map[ID:2.000009e+06 message:resizing is not supported for this database tier]] | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,46 @@ | ||
/** | ||
Copyright 2021 Ryan Svihla | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
// Copyright 2021 Ryan Svihla | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"os" | ||
|
||
"github.com/rsds143/astra-cli/cmd/db" | ||
"github.com/rsds143/astra-cli/pkg" | ||
"github.com/rsds143/astra-devops-sdk-go/astraops" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func DBUsage() string { | ||
return strings.Join([]string{ | ||
"\tastra-cli db <subcommands>", | ||
"\tdb subcommands:", | ||
fmt.Sprintf("\t%v", db.CreateUsage()), | ||
fmt.Sprintf("\t%v", db.DeleteUsage()), | ||
fmt.Sprintf("\t%v", db.GetUsage()), | ||
fmt.Sprintf("\t%v", db.ListUsage()), | ||
fmt.Sprintf("\t%v", db.ParkUsage()), | ||
fmt.Sprintf("\t%v", db.UnparkUsage()), | ||
fmt.Sprintf("\t%v", db.ResizeUsage()), | ||
fmt.Sprintf("\t%v", db.TiersUsage()), | ||
}, "\n") | ||
func init() { | ||
dbCmd.AddCommand(db.CreateCmd) | ||
dbCmd.AddCommand(db.DeleteCmd) | ||
dbCmd.AddCommand(db.ParkCmd) | ||
dbCmd.AddCommand(db.UnparkCmd) | ||
dbCmd.AddCommand(db.ResizeCmd) | ||
dbCmd.AddCommand(db.GetCmd) | ||
dbCmd.AddCommand(db.ListCmd) | ||
dbCmd.AddCommand(db.TiersCmd) | ||
dbCmd.AddCommand(db.SecBundleCmd) | ||
} | ||
|
||
// ExecuteDB launches several different subcommands and as of today is the main entry point | ||
// into automation of Astra | ||
func ExecuteDB(args []string, confFile pkg.ConfFiles, verbose bool) error { | ||
hasToken, err := confFile.HasToken() | ||
if err != nil { | ||
return fmt.Errorf("unable to read conf file %v with error %v", confFile.TokenPath, err) | ||
} | ||
var client *astraops.AuthenticatedClient | ||
if hasToken { | ||
token, err := pkg.ReadToken(confFile.TokenPath) | ||
if err != nil { | ||
return fmt.Errorf("found token at %v but unable to read it with error %v", confFile.TokenPath, err) | ||
} | ||
client = astraops.AuthenticateToken(token, verbose) | ||
} else { | ||
hasSa, err := confFile.HasServiceAccount() | ||
if err != nil { | ||
return fmt.Errorf("unable to read conf file %v with error %v", confFile.SaPath, err) | ||
} | ||
if !hasSa { | ||
return fmt.Errorf("unable to access any configuration, run astra-cli login first") | ||
} | ||
clientInfo, err := pkg.ReadLogin(confFile.SaPath) | ||
if err != nil { | ||
return fmt.Errorf("%v", err) | ||
} | ||
client, err = astraops.Authenticate(clientInfo, verbose) | ||
if err != nil { | ||
return fmt.Errorf("authenticate failed with error %v", err) | ||
} | ||
} | ||
if len(args) == 0 { | ||
return &pkg.ParseError{ | ||
Args: args, | ||
Err: fmt.Errorf("there is no standalone db command"), | ||
var dbCmd = &cobra.Command{ | ||
Use: "db", | ||
Short: "Shows all the db commands", | ||
Long: `Shows all other db commands. Create, Delete, Get information on your databases`, | ||
Run: func(cobraCmd *cobra.Command, args []string) { | ||
if err := cobraCmd.Usage(); err != nil { | ||
fmt.Fprintf(os.Stderr, "Unable to print usage with error %v\n", err) | ||
} | ||
} | ||
switch args[0] { | ||
case "create": | ||
return db.ExecuteCreate(args[1:], client) | ||
case "delete": | ||
return db.ExecuteDelete(args[1:], client) | ||
case "park": | ||
return db.ExecutePark(args[1:], client) | ||
case "unpark": | ||
return db.ExecuteUnpark(args[1:], client) | ||
case "resize": | ||
return db.ExecuteResize(args[1:], client) | ||
case "get": | ||
return db.ExecuteGet(args[1:], client) | ||
case "list": | ||
return db.ExecuteList(args[1:], client) | ||
case "tiers": | ||
return db.ExecuteTiers(args[1:], client) | ||
} | ||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.