Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ jobs:
- name: Set up Docker
run: |
brew install docker docker-machine docker-compose

sudo mkdir -p /usr/local/bin
sudo curl -L -o /usr/local/bin/colima https://github.com/abiosoft/colima/releases/download/v0.6.7/colima-Darwin-x86_64 && sudo chmod +x /usr/local/bin/colima
brew install lima
brew install qemu
colima start

sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock

- name: Cache Go modules
Expand Down
2 changes: 1 addition & 1 deletion docs/vcr.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ $ vcr init
* [vcr secret](vcr_secret.md) - Manage VCR secrets
* [vcr upgrade](vcr_upgrade.md) - Show and update VCR CLI version

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
2 changes: 1 addition & 1 deletion docs/vcr_app.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Use app commands to create, list and generate the key pairs of Vonage applicatio
* [vcr app generate-keys](vcr_app_generate-keys.md) - Generate Vonage application keys
* [vcr app list](vcr_app_list.md) - List Vonage applications

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
2 changes: 1 addition & 1 deletion docs/vcr_app_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ $ vcr app create --name App

* [vcr app](vcr_app.md) - Use app commands to manage Vonage applications

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
2 changes: 1 addition & 1 deletion docs/vcr_app_generate-keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ $ vcr app generate-keys --app-id 42066b10-c4ae-48a0-addd-feb2bd615a67

* [vcr app](vcr_app.md) - Use app commands to manage Vonage applications

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
2 changes: 1 addition & 1 deletion docs/vcr_app_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ ID Name

* [vcr app](vcr_app.md) - Use app commands to manage Vonage applications

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
2 changes: 1 addition & 1 deletion docs/vcr_configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ $ vcr configure

* [vcr](vcr.md) - Streamline your Vonage Cloud Runtime development and management tasks with VCR

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
2 changes: 1 addition & 1 deletion docs/vcr_debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ $ vcr debug --name debugger"

* [vcr](vcr.md) - Streamline your Vonage Cloud Runtime development and management tasks with VCR

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
2 changes: 1 addition & 1 deletion docs/vcr_deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ $ vcr deploy

* [vcr](vcr.md) - Streamline your Vonage Cloud Runtime development and management tasks with VCR

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
2 changes: 1 addition & 1 deletion docs/vcr_init.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ $ vcr init my-app

* [vcr](vcr.md) - Streamline your Vonage Cloud Runtime development and management tasks with VCR

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
2 changes: 1 addition & 1 deletion docs/vcr_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Used for instance management
* [vcr instance log](vcr_instance_log.md) - This command will output the log of an instance.
* [vcr instance remove](vcr_instance_remove.md) - This command will remove an instance.

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
2 changes: 1 addition & 1 deletion docs/vcr_instance_log.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ $ vcr instance log --project-name <project-name> --instance-name <instance-name>

* [vcr instance](vcr_instance.md) - Used for instance management

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
2 changes: 1 addition & 1 deletion docs/vcr_instance_remove.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ $ vcr instance rm --id <instance-id>

* [vcr instance](vcr_instance.md) - Used for instance management

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
2 changes: 1 addition & 1 deletion docs/vcr_mongo.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ Used for managing MongoDB databases
* [vcr mongo info](vcr_mongo_info.md) - Get database connection info
* [vcr mongo list](vcr_mongo_list.md) - List databases

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
2 changes: 1 addition & 1 deletion docs/vcr_mongo_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ $ vcr mongo create

* [vcr mongo](vcr_mongo.md) - Used for managing MongoDB databases

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
2 changes: 1 addition & 1 deletion docs/vcr_mongo_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ $ vcr mongo delete --database <database>

* [vcr mongo](vcr_mongo.md) - Used for managing MongoDB databases

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
2 changes: 1 addition & 1 deletion docs/vcr_mongo_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ $ vcr mongo info --database <database>

* [vcr mongo](vcr_mongo.md) - Used for managing MongoDB databases

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
2 changes: 1 addition & 1 deletion docs/vcr_mongo_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ $ vcr mongo list

* [vcr mongo](vcr_mongo.md) - Used for managing MongoDB databases

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
2 changes: 1 addition & 1 deletion docs/vcr_secret.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ $ vcr secret create --name <name> --file <path/to/file>
* [vcr secret remove](vcr_secret_remove.md) - Remove a secret
* [vcr secret update](vcr_secret_update.md) - update a secret

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
2 changes: 1 addition & 1 deletion docs/vcr_secret_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ $ vcr secret create --name <name> --file <path/to/file>

* [vcr secret](vcr_secret.md) - Manage VCR secrets

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
2 changes: 1 addition & 1 deletion docs/vcr_secret_remove.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ $ vcr secret remove -n <secret_name>

* [vcr secret](vcr_secret.md) - Manage VCR secrets

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
2 changes: 1 addition & 1 deletion docs/vcr_secret_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ $ vcr secret update --name my-secret --value changed-value

* [vcr secret](vcr_secret.md) - Manage VCR secrets

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
5 changes: 3 additions & 2 deletions docs/vcr_upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ vcr upgrade [flags]
### Options

```
-f, --force Force update and skip prompt if new update exists
-f, --force Force update and skip prompt if new update exists
-p, --path string Path to the VCR CLI installed directory
```

### Options inherited from parent commands
Expand All @@ -35,4 +36,4 @@ vcr upgrade [flags]

* [vcr](vcr.md) - Streamline your Vonage Cloud Runtime development and management tasks with VCR

###### Auto generated by spf13/cobra on 11-Nov-2024
###### Auto generated by spf13/cobra on 26-Nov-2024
16 changes: 16 additions & 0 deletions pkg/cmdutil/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type DatastoreInterface interface {
// Factory provides clients and parameters for all subcommands.
type Factory interface {
Init(ctx context.Context, cfg config.CLIConfig, opts *config.GlobalOptions) error
InitUpgrade(opts *config.GlobalOptions)
InitDatastore(cfg config.CLIConfig, opts *config.GlobalOptions)
InitDeploymentClient(ctx context.Context, regionAlias string) error
SetGlobalOptions(opts *config.GlobalOptions)
Expand Down Expand Up @@ -126,6 +127,7 @@ func NewDefaultFactory(apiVersion string, releaseURL string) *DefaultFactory {
}

func (f *DefaultFactory) Init(ctx context.Context, cfg config.CLIConfig, opts *config.GlobalOptions) error {

f.cliConfig = cfg
f.globalOpts = opts
f.websocketConnectionClient = getWebsocketConnectionClient(f.APIKey(), f.APISecret())
Expand All @@ -145,6 +147,12 @@ func (f *DefaultFactory) Init(ctx context.Context, cfg config.CLIConfig, opts *c
return nil
}

func (f *DefaultFactory) InitUpgrade(opts *config.GlobalOptions) {
f.globalOpts = opts
f.httpClient = GetHTTPClient("", "")
f.releaseClient = api.NewReleaseClient(f.releaseURL, f.httpClient)
}

func (f *DefaultFactory) InitDatastore(cfg config.CLIConfig, opts *config.GlobalOptions) {
f.globalOpts = opts
f.cliConfig = cfg
Expand Down Expand Up @@ -220,6 +228,9 @@ func (f *DefaultFactory) GraphQLURL() string {
if f.globalOpts.GraphqlEndpoint != "" {
return f.globalOpts.GraphqlEndpoint
}
if f.globalOpts.Region != "" {
return makeGraphqlEndpoint(f.globalOpts.Region)
}
return f.cliConfig.GraphqlEndpoint
}

Expand Down Expand Up @@ -268,3 +279,8 @@ func getDatastore(graphQLURL string, httpClient *resty.Client) *api.Datastore {
func getWebsocketConnectionClient(apiKey, apiSecret string) *api.WebsocketConnectionClient {
return api.NewWebsocketConnectionClient(apiKey, apiSecret)
}

func makeGraphqlEndpoint(region string) string {
region = region[4:]
return fmt.Sprintf("https://graphql.%s.runtime.vonage.cloud/v1/graphql", region)
}
94 changes: 81 additions & 13 deletions script/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,56 @@
# Based on Deno installer: Copyright 2019 the Deno authors. All rights reserved. MIT license.
set -e

version=""
path=""
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "options:"
echo "-h, --help show brief help"
echo "-v, --version=VERSION specify a version to download"
echo "-o, --output-dir=DIR specify a directory to install"
exit 0
;;
-v)
shift
if test $# -gt 0; then
version=$1
else
echo "no version specified"
exit 1
fi
shift
;;
--version*)
version=`echo $1 | sed -e 's/^[^=]*=//g'`
echo "version:$version"
shift
;;
-o)
shift
if test $# -gt 0; then
path=$1
else
echo "no output dir specified"
exit 1
fi
shift
;;
--output-dir*)
path=`echo $1 | sed -e 's/^[^=]*=//g'`
echo "path:$path"
shift
;;
*)
echo "Error: Invalid argument $1" 1>&2
exit 1
;;
esac
done

main() {

os=$(uname -s | tr '[:upper:]' '[:lower:]')
arch=$(uname -m)
if [ "$arch" = "x86_64" ]; then
Expand All @@ -11,7 +60,7 @@ main() {
arch="arm64"
fi
vcr_binary="vcr_${os}_${arch}"
version="${1:+download/$1}"
version="${version:+download/$version}"
version="${version:-latest/download}"

vcr_uri="https://github.com/Vonage/cloud-runtime-cli/releases/$version/$vcr_binary.tar.gz"
Expand All @@ -31,6 +80,12 @@ main() {
mkdir -p "$bin_dir"
mkdir -p "$tmp_dir"

if [ -n "$path" ]; then
echo "Path provided: $path"
mkdir -p $path

fi

if ! curl -q --fail --location --progress-bar --output "$tmp_dir/${vcr_binary}.tar.gz" "$vcr_uri"; then
echo "Error encountered when downloading ${vcr_binary} to ${tmp_dir} , please try to run with sudo"
exit 1
Expand All @@ -41,20 +96,33 @@ main() {

rm "$tmp_dir/${vcr_binary}.tar.gz"
cp "$tmp_dir/${vcr_binary}" "$exe"

if [ -n "$path" ]; then
if mv "$tmp_dir/${vcr_binary}" "$path/vcr"; then
echo "vcr was installed successfully to $path/vcr"
echo "Run '$path/vcr --help' to get started"
case $SHELL in
/bin/zsh) shell_profile=".zshrc" ;;
*) shell_profile=".bash_profile" ;;
esac
echo "Or manually add the directory to your \$HOME/$shell_profile (or similar)"
echo " export VCR_INSTALL=\"$path\""
echo " export PATH=\"\$VCR_INSTALL:\$PATH\""
exit 0
else
exit 1
fi

fi

if mv "$tmp_dir/${vcr_binary}" "$sys_exe"; then
echo "vcr was installed successfully to $sys_exe"
echo "Run 'vcr --help' to get started"
echo "vcr was installed successfully to $sys_exe"
echo "Run 'vcr --help' to get started"
exit 0
else
case $SHELL in
/bin/zsh) shell_profile=".zshrc" ;;
*) shell_profile=".bash_profile" ;;
esac
echo "Error encountered when moving ${vcr_binary} to $sys_exe , please try to run with sudo"
echo "Or manually add the directory to your \$HOME/$shell_profile (or similar)"
echo " export VCR_INSTALL=\"$vcr_install\""
echo " export PATH=\"\$VCR_INSTALL/bin:\$PATH\""
echo "Run '$exe --help' to get started"
echo "Or use the -o flag to specify a directory where you have write permissions, for more information run with -h"
exit 1
fi
}

main "$1"
main "$1"
12 changes: 12 additions & 0 deletions testutil/mocks/factory.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions vcr/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ func NewCmdRoot(f cmdutil.Factory, version, buildDate, commit string, updateStre
return nil
}

if cmd.Name() == "upgrade" {
f.InitUpgrade(&opts)
close(updateStream)
return nil
}

cliConfig, err := config.ReadCLIConfig(opts.ConfigFilePath)
if err != nil {
if !errors.Is(err, config.ErrNoConfig) {
Expand All @@ -67,9 +73,9 @@ func NewCmdRoot(f cmdutil.Factory, version, buildDate, commit string, updateStre
cliConfig, path, err = config.ReadDefaultCLIConfig()
switch {
case errors.Is(err, config.ErrNoConfig):
fmt.Fprintf(io.ErrOut, "%s Config file not found at %q, please use 'vcr configure' to create one. Trying to use flags...\n", c.WarningIcon(), opts.ConfigFilePath)
fmt.Fprintf(io.Out, "%s Config file not found at %q, please use 'vcr configure' to create one. Trying to use flags...\n", c.WarningIcon(), opts.ConfigFilePath)
case err == nil:
fmt.Fprintf(io.ErrOut, "%s Config file not found at %q, using %q\n", c.WarningIcon(), opts.ConfigFilePath, path)
fmt.Fprintf(io.Out, "%s Config file not found at %q, using %q\n", c.WarningIcon(), opts.ConfigFilePath, path)
default:
close(updateStream)
return fmt.Errorf("failed to read config file %q : %w", path, err)
Expand All @@ -84,11 +90,6 @@ func NewCmdRoot(f cmdutil.Factory, version, buildDate, commit string, updateStre
return fmt.Errorf("failed to initialize cli: %w", err)
}

if cmd.Name() == "upgrade" {
close(updateStream)
return nil
}

go func() {
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(opts.Timeout))
defer cancel()
Expand Down
Loading
Loading