Skip to content

Commit

Permalink
added support for more secure bundle types
Browse files Browse the repository at this point in the history
  • Loading branch information
foundev committed May 11, 2021
1 parent 49fd151 commit 6b6d39a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,24 @@ 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
./bin/astra-cli db secBundle 3c577e51-4ff5-4551-86a4-41d475c61822 -d external -l external.zip
file external.zip saved 12072 bytes written
./bin/astra-cli db secBundle 3c577e51-4ff5-4551-86a4-41d475c61822 -d internal -l internal.zip
file internal.zip saved 12066 bytes written
./bin/astra-cli db secBundle 3c577e51-4ff5-4551-86a4-41d475c61822 -d proxy-internal -l proxy-internal.zip
file proxy-internal.zip saved 348 bytes written
./bin/astra-cli db secBundle 3c577e51-4ff5-4551-86a4-41d475c61822 -d proxy-external -l proxy-external.zip
file proxy-external.zip saved 339 bytes written
```

### get secure connection bundle url
### get secure connection bundle URLs

```
./bin/astra-cli db secBundle 3c577e51-4ff5-4551-86a4-41d475c61822 -o json
{
"downloadURL": "changed",
"downloadURLInternal": "changed",
"downloadURLMigrationProxy": "changed",
"downloadURLMigrationProxyInternal": "changed"
}
./bin/astra-cli db secBundle 3c577e51-4ff5-4551-86a4-41d475c61822 -o list
external bundle: changed
internal bundle: changed
external proxy: changed
internal proxy: changed
```

### listing databases
Expand Down
24 changes: 23 additions & 1 deletion cmd/db/secBundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ import (

var secBundleFmt string
var secBundleLoc string
var secBundleDownloadType string

func init() {
SecBundleCmd.Flags().StringVarP(&secBundleFmt, "output", "o", "zip", "Output format for report default is zip")
SecBundleCmd.Flags().StringVarP(&secBundleDownloadType, "download-type", "d", "external", "Bundle type to download external, internal, proxy-external and proxy-internal available. Only works with -o zip")
SecBundleCmd.Flags().StringVarP(&secBundleLoc, "location", "l", "secureBundle.zip", "location of bundle to download to if using zip format. ignore if using json")
}

Expand Down Expand Up @@ -63,7 +65,20 @@ func executeSecBundle(args []string, login func() (pkg.Client, error)) (string,
}
switch secBundleFmt {
case "zip":
bytesWritten, err := httputils.DownloadZip(secBundle.DownloadURL, secBundleLoc)
var urlToDownload string
switch secBundleDownloadType {
case "external":
urlToDownload = secBundle.DownloadURL
case "internal":
urlToDownload = secBundle.DownloadURLInternal
case "proxy-external":
urlToDownload = secBundle.DownloadURLMigrationProxy
case "proxy-internal":
urlToDownload = secBundle.DownloadURLMigrationProxyInternal
default:
return "", fmt.Errorf("invalid download type %s passed. valid options are 'external', 'internal', 'proxy-external', 'proxy-internal'", secBundleDownloadType)
}
bytesWritten, err := httputils.DownloadZip(urlToDownload, secBundleLoc)
if err != nil {
return "", fmt.Errorf("error outputing zip format '%v'", err)
}
Expand All @@ -74,6 +89,13 @@ func executeSecBundle(args []string, login func() (pkg.Client, error)) (string,
return "", fmt.Errorf("unexpected error marshaling to json: '%v', Try -output text instead", err)
}
return string(b), nil
case "list":
return fmt.Sprintf(`
external bundle: %s
internal bundle: %s
external proxy: %s
internal proxy: %s
`, secBundle.DownloadURL, secBundle.DownloadURLInternal, secBundle.DownloadURLMigrationProxy, secBundle.DownloadURLMigrationProxyInternal), nil
default:
return "", fmt.Errorf("-o %q is not valid option", secBundleFmt)
}
Expand Down

0 comments on commit 6b6d39a

Please sign in to comment.