├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── cmd ├── prvd │ └── main.go └── prvdnetwork │ └── main.go ├── go.mod ├── go.sum ├── prvd ├── accounts │ ├── accounts.go │ ├── accounts_init.go │ ├── accounts_list.go │ └── accounts_prompt.go ├── api_tokens │ ├── api_tokens.go │ ├── api_tokens_init.go │ ├── api_tokens_list.go │ └── api_tokens_prompt.go ├── applications │ ├── application_prompt.go │ ├── applications.go │ ├── applications_details.go │ ├── applications_init.go │ └── applications_list.go ├── axiom │ ├── baseline.go │ ├── baseline_prompt.go │ ├── domain_models │ │ ├── domain_models.go │ │ ├── domain_models_init.go │ │ ├── domain_models_list.go │ │ └── domain_models_prompt.go │ ├── participants │ │ ├── invitations │ │ │ ├── invitations.go │ │ │ ├── invitations_list.go │ │ │ └── invitations_prompt.go │ │ ├── organizations │ │ │ ├── organizations.go │ │ │ ├── organizations_invite.go │ │ │ ├── organizations_list.go │ │ │ └── organizations_prompt.go │ │ ├── participants.go │ │ ├── participants_prompt.go │ │ └── users │ │ │ ├── users.go │ │ │ ├── users_invite.go │ │ │ ├── users_list.go │ │ │ └── users_prompt.go │ ├── stack │ │ ├── stack.go │ │ ├── stack_logs.go │ │ ├── stack_prompt.go │ │ ├── stack_start.go │ │ └── stack_stop.go │ ├── subject_accounts │ │ ├── subject_accounts.go │ │ ├── subject_accounts_details.go │ │ ├── subject_accounts_init.go │ │ ├── subject_accounts_list.go │ │ └── subject_accounts_prompt.go │ ├── systems │ │ ├── systems.go │ │ ├── systems_details.go │ │ ├── systems_init.go │ │ ├── systems_list.go │ │ └── systems_prompt.go │ ├── workflows │ │ ├── messages │ │ │ ├── list.go │ │ │ ├── messages.go │ │ │ ├── messages_prompt.go │ │ │ └── send.go │ │ ├── workflows.go │ │ ├── workflows_deploy.go │ │ ├── workflows_details.go │ │ ├── workflows_init.go │ │ ├── workflows_list.go │ │ ├── workflows_prompt.go │ │ ├── workflows_version.go │ │ └── worksteps │ │ │ ├── worksteps.go │ │ │ ├── worksteps_init.go │ │ │ ├── worksteps_list.go │ │ │ └── worksteps_prompt.go │ └── workgroups │ │ ├── workgroups.go │ │ ├── workgroups_details.go │ │ ├── workgroups_init.go │ │ ├── workgroups_join.go │ │ ├── workgroups_list.go │ │ ├── workgroups_prompt.go │ │ └── workgroups_update.go ├── common │ ├── baseline.go │ ├── config.go │ ├── docker.go │ ├── global.go │ ├── infrastructure.go │ ├── prompt.go │ └── structs.go ├── connectors │ ├── connectors.go │ ├── connectors_delete.go │ ├── connectors_details.go │ ├── connectors_init.go │ ├── connectors_list.go │ └── connectors_prompt.go ├── contracts │ ├── contract_details.go │ ├── contracts.go │ ├── contracts_execute.go │ ├── contracts_init.go │ ├── contracts_list.go │ └── contracts_prompt.go ├── networks │ ├── networks.go │ ├── networks_disable.go │ ├── networks_init.go │ ├── networks_list.go │ └── networks_prompt.go ├── nodes │ ├── nodes.go │ ├── nodes_delete.go │ ├── nodes_init.go │ ├── nodes_logs.go │ └── nodes_prompt.go ├── organizations │ ├── organizations.go │ ├── organizations_details.go │ ├── organizations_init.go │ ├── organizations_list.go │ └── organizations_prompt.go ├── root.go ├── shell │ ├── escape.go │ ├── native.go │ ├── repl.go │ └── shell.go ├── users │ ├── authenticate.go │ ├── init.go │ ├── users.go │ └── users_prompt.go ├── vaults │ ├── keys │ │ ├── keys.go │ │ ├── keys_init.go │ │ ├── keys_list.go │ │ └── keys_prompt.go │ ├── vaults.go │ ├── vaults_init.go │ ├── vaults_list.go │ └── vaults_prompt.go └── wallets │ ├── wallets.go │ ├── wallets_init.go │ ├── wallets_list.go │ └── wallets_prompt.go ├── prvdnetwork └── root.go └── test └── shell_test.go /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | *.exe 21 | *.test 22 | *.prof 23 | 24 | # Mac specific 25 | .DS_Store 26 | 27 | .bin/ 28 | .vscode/ 29 | vendor/ 30 | 31 | bin/ 32 | nats-server.conf 33 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: build build-binaries clean install mod test 2 | 3 | clean: 4 | rm -rf ./.bin 2>/dev/null || true 5 | rm -rf ./vendor 2>/dev/null || true 6 | rm ./prvd 2>/dev/null || true 7 | go fix ./... 8 | go clean -i 9 | 10 | build: clean mod 11 | go fmt ./... 12 | CGO_CFLAGS=-Wno-undef-prefix go build -v -o ./.bin/prvd ./cmd/prvd 13 | CGO_CFLAGS=-Wno-undef-prefix go build -v -o ./.bin/prvdnetwork ./cmd/prvdnetwork 14 | 15 | build-binaries: clean mod 16 | go fmt ./... 17 | GOOS=darwin GOARCH=amd64 go build -o bin/prvd-amd64-darwin cmd/prvd/main.go 18 | GOOS=windows GOARCH=amd64 go build -o bin/prvd-amd64-windows cmd/prvd/main.go 19 | GOOS=linux GOARCH=amd64 go build -o bin/prvd-amd64-linux cmd/prvd/main.go 20 | 21 | install: build 22 | mkdir -p "${GOPATH}/bin" 23 | mv ./.bin/prvd "${GOPATH}/bin/prvd" 24 | mv ./.bin/prvdnetwork "${GOPATH}/bin/prvdnetwork" 25 | rm -rf ./.bin 26 | 27 | mod: 28 | go mod init 2>/dev/null || true 29 | go mod tidy 30 | go mod vendor 31 | 32 | test: build 33 | # TODO 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Provide CLI 2 | 3 | A command-line interface for [Provide](https://provide.services). Full documentation is available [here](https://docs.provide.services). Language-specific API clients are available [here](https://github.com/provideplatform). 4 | 5 | Quickstart and additional CLI documentation forthcoming. 6 | -------------------------------------------------------------------------------- /cmd/prvd/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import cmd "github.com/provideplatform/provide-cli/prvd" 20 | 21 | func main() { 22 | cmd.Execute() 23 | } 24 | -------------------------------------------------------------------------------- /cmd/prvdnetwork/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import cmd "github.com/provideplatform/provide-cli/prvdnetwork" 20 | 21 | func main() { 22 | cmd.Execute() 23 | } 24 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/provideplatform/provide-cli 2 | 3 | go 1.13 4 | 5 | require ( 6 | github.com/Microsoft/hcsshim v0.9.5 // indirect 7 | github.com/blang/semver/v4 v4.0.0 8 | github.com/c-bata/go-prompt v0.2.6 9 | github.com/containerd/containerd v1.6.9 // indirect 10 | github.com/dgrijalva/jwt-go v3.2.0+incompatible 11 | github.com/docker/docker v20.10.21+incompatible 12 | github.com/docker/go-connections v0.4.0 13 | github.com/kthomas/go-pgputil v0.0.0-20200602073402-784e96083943 14 | github.com/kthomas/go.uuid v1.2.1-0.20190324131420-28d1fa77e9a4 15 | github.com/manifoldco/promptui v0.8.0 16 | github.com/mattn/go-colorable v0.1.8 // indirect 17 | github.com/mattn/go-runewidth v0.0.12 // indirect 18 | github.com/mitchellh/go-homedir v1.1.0 19 | github.com/moby/sys/mount v0.3.3 // indirect 20 | github.com/opencontainers/runc v1.1.4 // indirect 21 | github.com/ory/viper v1.7.5 22 | github.com/provideplatform/provide-go v0.0.0-20230402033044-2ea8560d1e46 23 | github.com/rivo/uniseg v0.2.0 // indirect 24 | github.com/spf13/cobra v1.1.3 25 | github.com/spf13/viper v1.7.1 26 | golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd 27 | ) 28 | -------------------------------------------------------------------------------- /prvd/accounts/accounts.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package accounts 18 | 19 | import ( 20 | "os" 21 | 22 | "github.com/provideplatform/provide-cli/prvd/common" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | var AccountID string 27 | 28 | var AccountsCmd = &cobra.Command{ 29 | Use: "accounts", 30 | Short: "Manage signing identities & accounts", 31 | Long: `Various APIs are exposed to provide convenient access to elliptic-curve cryptography 32 | (ECC) helper methods such as generating managed (custodial) keypairs. 33 | 34 | For convenience, it is also possible to generate keypairs with this utility which you (or your application) 35 | is then responsible for securing. You should securely store any keys generated using this API. If you are 36 | looking for hierarchical deterministic support, check out the wallets API.`, 37 | Run: func(cmd *cobra.Command, args []string) { 38 | common.CmdExistsOrExit(cmd, args) 39 | 40 | generalPrompt(cmd, args, "") 41 | 42 | defer func() { 43 | if r := recover(); r != nil { 44 | os.Exit(1) 45 | } 46 | }() 47 | }, 48 | } 49 | 50 | func init() { 51 | AccountsCmd.AddCommand(accountsListCmd) 52 | AccountsCmd.AddCommand(accountsInitCmd) 53 | AccountsCmd.Flags().BoolVarP(&optional, "optional", "", false, "List all the optional flags") 54 | AccountsCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 55 | } 56 | -------------------------------------------------------------------------------- /prvd/accounts/accounts_list.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package accounts 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | provide "github.com/provideplatform/provide-go/api/nchain" 26 | "github.com/spf13/cobra" 27 | ) 28 | 29 | var page uint64 30 | var rpp uint64 31 | 32 | var accountsListCmd = &cobra.Command{ 33 | Use: "list", 34 | Short: "Retrieve a list of signing identities", 35 | Long: `Retrieve a list of signing identities (accounts) scoped to the authorized API token`, 36 | Run: listAccounts, 37 | } 38 | 39 | func listAccounts(cmd *cobra.Command, args []string) { 40 | token := common.RequireAPIToken() 41 | params := map[string]interface{}{ 42 | "page": fmt.Sprintf("%d", page), 43 | "rpp": fmt.Sprintf("%d", rpp), 44 | } 45 | if common.ApplicationID != "" { 46 | params["application_id"] = common.ApplicationID 47 | } 48 | resp, err := provide.ListAccounts(token, params) 49 | if err != nil { 50 | log.Printf("Failed to retrieve accounts list; %s", err.Error()) 51 | os.Exit(1) 52 | } 53 | // if status != 200 { 54 | // log.Printf("Failed to retrieve accounts list; received status: %d", status) 55 | // os.Exit(1) 56 | // } 57 | for i := range resp { 58 | account := resp[i] 59 | result := fmt.Sprintf("%s\t%s\n", account.ID.String(), account.Address) 60 | // TODO-- when account.Name exists... result = fmt.Sprintf("%s\t%s - %s\n", name, account, *account.Address) 61 | fmt.Print(result) 62 | } 63 | } 64 | 65 | func init() { 66 | accountsListCmd.Flags().StringVar(&common.ApplicationID, "application", "", "application identifier to filter accounts") 67 | accountsListCmd.Flags().BoolVarP(&optional, "optional", "", false, "List all the optional flags") 68 | accountsListCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 69 | accountsListCmd.Flags().Uint64Var(&page, "page", common.DefaultPage, "page number to retrieve") 70 | accountsListCmd.Flags().Uint64Var(&rpp, "rpp", common.DefaultRpp, "number of accounts to retrieve per page") 71 | } 72 | -------------------------------------------------------------------------------- /prvd/accounts/accounts_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package accounts 18 | 19 | import ( 20 | "fmt" 21 | 22 | "github.com/provideplatform/provide-cli/prvd/common" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | const promptStepCustody = "Custody" 27 | const promptStepInit = "Initialize" 28 | const promptStepList = "List" 29 | 30 | var emptyPromptArgs = []string{promptStepInit, promptStepList} 31 | var emptyPromptLabel = "What would you like to do" 32 | 33 | var accountTypePromptArgs = []string{"Managed", "Decentralised"} 34 | var accountTypeLabel = "What type of Wallet would you like to create" 35 | 36 | var custodyPromptArgs = []string{"No", "Yes"} 37 | var custodyPromptLabel = "Would you like your wallet to be non-custodial?" 38 | 39 | // General Endpoints 40 | func generalPrompt(cmd *cobra.Command, args []string, currentStep string) { 41 | switch step := currentStep; step { 42 | case promptStepInit: 43 | common.SelectInput(accountTypePromptArgs, accountTypeLabel) 44 | generalPrompt(cmd, args, promptStepCustody) 45 | case promptStepCustody: 46 | if optional { 47 | fmt.Println("Optional Flags:") 48 | if !nonCustodial { 49 | nonCustodial = common.SelectInput(custodyPromptArgs, custodyPromptLabel) == "Yes" 50 | } 51 | if accountName == "" { 52 | accountName = common.FreeInput("Account Name", "", common.NoValidation) 53 | } 54 | if common.ApplicationID == "" { 55 | common.RequireApplication() 56 | } 57 | if common.OrganizationID == "" { 58 | common.RequireOrganization() 59 | } 60 | } 61 | CreateAccount(cmd, args) 62 | case promptStepList: 63 | if optional { 64 | fmt.Println("Optional Flags:") 65 | common.RequireApplication() 66 | } 67 | page, rpp = common.PromptPagination(paginate, page, rpp) 68 | listAccounts(cmd, args) 69 | case "": 70 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 71 | generalPrompt(cmd, args, result) 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /prvd/api_tokens/api_tokens.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package api_tokens 18 | 19 | import ( 20 | "os" 21 | 22 | "github.com/provideplatform/provide-cli/prvd/common" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | var APITokensCmd = &cobra.Command{ 27 | Use: "api_tokens", 28 | Short: "Manage API tokens", 29 | Long: `API tokens can be created on behalf of a developer account, application or application user`, 30 | Run: func(cmd *cobra.Command, args []string) { 31 | common.CmdExistsOrExit(cmd, args) 32 | 33 | generalPrompt(cmd, args, "") 34 | 35 | defer func() { 36 | if r := recover(); r != nil { 37 | os.Exit(1) 38 | } 39 | }() 40 | }, 41 | } 42 | 43 | func init() { 44 | APITokensCmd.AddCommand(apiTokensListCmd) 45 | APITokensCmd.AddCommand(apiTokensInitCmd) 46 | APITokensCmd.Flags().BoolVarP(&optional, "optional", "", false, "List all the optional flags") 47 | APITokensCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 48 | } 49 | -------------------------------------------------------------------------------- /prvd/api_tokens/api_tokens_list.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package api_tokens 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | provide "github.com/provideplatform/provide-go/api/ident" 26 | 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | var page uint64 31 | var rpp uint64 32 | 33 | var apiTokensListCmd = &cobra.Command{ 34 | Use: "list", 35 | Short: "Retrieve a list of API tokens", 36 | Long: `Retrieve a list of API tokens scoped to the authorized API token`, 37 | Run: listAPITokens, 38 | } 39 | 40 | func listAPITokens(cmd *cobra.Command, args []string) { 41 | token := common.RequireAPIToken() 42 | params := map[string]interface{}{ 43 | "page": fmt.Sprintf("%d", page), 44 | "rpp": fmt.Sprintf("%d", rpp), 45 | } 46 | if common.ApplicationID != "" { 47 | params["application_id"] = common.ApplicationID 48 | } 49 | resp, err := provide.ListTokens(token, params) 50 | if err != nil { 51 | log.Printf("Failed to retrieve API tokens list; %s", err.Error()) 52 | os.Exit(1) 53 | } 54 | // if status != 200 { 55 | // log.Printf("Failed to retrieve API tokens list; received status: %d", status) 56 | // os.Exit(1) 57 | // } 58 | for i := range resp { 59 | apiToken := resp[i] 60 | result := fmt.Sprintf("%s\t%s\n", apiToken.ID.String(), *apiToken.Token) 61 | fmt.Print(result) 62 | } 63 | } 64 | 65 | func init() { 66 | apiTokensListCmd.Flags().StringVar(&common.ApplicationID, "application", "", "application identifier to filter API tokens") 67 | apiTokensListCmd.Flags().BoolVarP(&optional, "optional", "", false, "List all the optional flags") 68 | apiTokensListCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 69 | apiTokensListCmd.Flags().Uint64Var(&page, "page", common.DefaultPage, "page number to retrieve") 70 | apiTokensListCmd.Flags().Uint64Var(&rpp, "rpp", common.DefaultRpp, "number of API tokens to retrieve per page") 71 | } 72 | -------------------------------------------------------------------------------- /prvd/api_tokens/api_tokens_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package api_tokens 18 | 19 | import ( 20 | "fmt" 21 | 22 | "github.com/provideplatform/provide-cli/prvd/common" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | const promptStepInit = "Initialize" 27 | const promptStepList = "List" 28 | 29 | var emptyPromptArgs = []string{promptStepInit, promptStepList} 30 | var emptyPromptLabel = "What would you like to do" 31 | 32 | var refresTokenPromptArgs = []string{"Yes", "No"} 33 | var refresTokenPromptLabel = "Would you like to set a refresh token" 34 | 35 | var offlinePromptArgs = []string{"Yes", "No"} 36 | var offlinePromptLabel = "Would you like to set offline access" 37 | 38 | // General Endpoints 39 | func generalPrompt(cmd *cobra.Command, args []string, currentStep string) { 40 | switch step := currentStep; step { 41 | case promptStepInit: 42 | if optional { 43 | if common.ApplicationID == "" { 44 | common.RequireApplication() 45 | } 46 | if common.OrganizationID == "" { 47 | common.RequireOrganization() 48 | } 49 | if !refreshToken { 50 | result := common.SelectInput(refresTokenPromptArgs, refresTokenPromptLabel) 51 | refreshToken = result == "Yes" 52 | } 53 | if !offlineAccess { 54 | result := common.SelectInput(offlinePromptArgs, offlinePromptLabel) 55 | offlineAccess = result == "Yes" 56 | } 57 | if refreshToken && offlineAccess { 58 | fmt.Println("⚠️ WARNING: You currently have both refresh and offline token set, Refresh token will take precedence") 59 | } 60 | } 61 | createAPIToken(cmd, args) 62 | case promptStepList: 63 | if optional { 64 | common.RequireApplication() 65 | } 66 | page, rpp = common.PromptPagination(paginate, page, rpp) 67 | listAPITokens(cmd, args) 68 | case "": 69 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 70 | generalPrompt(cmd, args, result) 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /prvd/applications/application_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package applications 18 | 19 | import ( 20 | "fmt" 21 | 22 | "github.com/provideplatform/provide-cli/prvd/common" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | const promptStepDetails = "Details" 27 | const promptStepInit = "Initialize" 28 | const promptStepList = "List" 29 | 30 | var emptyPromptArgs = []string{promptStepInit, promptStepList} 31 | var emptyPromptLabel = "What would you like to do" 32 | 33 | var axiomPromptArgs = []string{"Yes", "No"} 34 | var axiomPromptLabel = "Would you like to make the application axiom compliant" 35 | 36 | var accountPromptArgs = []string{"Yes", "No"} 37 | var accountPromptLabel = "Would you like to make an account" 38 | 39 | var walletPromptArgs = []string{"Yes", "No"} 40 | var walletPromptLabel = "Would you like to set up a wallet" 41 | 42 | // General Endpoints 43 | func generalPrompt(cmd *cobra.Command, args []string, step string) { 44 | switch step { 45 | case promptStepInit: 46 | if applicationName == "" { 47 | applicationName = common.FreeInput("Application Name", "", common.MandatoryValidation) 48 | } 49 | if common.NetworkID == "" { 50 | common.RequireNetwork() 51 | } 52 | if optional { 53 | fmt.Println("Optional Flags:") 54 | if applicationType == "" { 55 | applicationType = common.FreeInput("Application Type", "", common.NoValidation) 56 | } 57 | if !axiom { 58 | result := common.SelectInput(axiomPromptArgs, axiomPromptLabel) 59 | axiom = result == "Yes" 60 | } 61 | if !withoutAccount { 62 | result := common.SelectInput(accountPromptArgs, accountPromptLabel) 63 | axiom = result == "Yes" 64 | } 65 | if !withoutWallet { 66 | result := common.SelectInput(walletPromptArgs, walletPromptLabel) 67 | axiom = result == "Yes" 68 | } 69 | } 70 | createApplication(cmd, args) 71 | case promptStepDetails: 72 | common.RequireApplication() 73 | fetchApplicationDetails(cmd, args) 74 | case promptStepList: 75 | page, rpp = common.PromptPagination(paginate, page, rpp) 76 | listApplications(cmd, args) 77 | case "": 78 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 79 | generalPrompt(cmd, args, result) 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /prvd/applications/applications.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package applications 18 | 19 | import ( 20 | "os" 21 | 22 | "github.com/provideplatform/provide-cli/prvd/common" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | const applicationTypeMessageBus = "message_bus" 27 | 28 | var application map[string]interface{} 29 | 30 | var ApplicationsCmd = &cobra.Command{ 31 | Use: "applications", 32 | Short: "Manage applications", 33 | Long: `Create and manage logical applications which target a specific network and expose the following APIs: 34 | 35 | - API Tokens 36 | - Smart Contracts 37 | - Token Contracts 38 | - Signing Identities (wallets) 39 | - Oracles 40 | - Bridges 41 | - Connectors (i.e., IPFS) 42 | - Payment Hubs 43 | - Transactions`, 44 | Run: func(cmd *cobra.Command, args []string) { 45 | common.CmdExistsOrExit(cmd, args) 46 | 47 | generalPrompt(cmd, args, "") 48 | 49 | defer func() { 50 | if r := recover(); r != nil { 51 | os.Exit(1) 52 | } 53 | }() 54 | }, 55 | } 56 | 57 | func init() { 58 | ApplicationsCmd.AddCommand(applicationsListCmd) 59 | ApplicationsCmd.AddCommand(applicationsInitCmd) 60 | ApplicationsCmd.AddCommand(applicationsDetailsCmd) 61 | ApplicationsCmd.Flags().BoolVarP(&optional, "optional", "", false, "List all the optional flags") 62 | ApplicationsCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 63 | } 64 | -------------------------------------------------------------------------------- /prvd/applications/applications_details.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package applications 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | provide "github.com/provideplatform/provide-go/api/ident" 26 | 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | var applicationsDetailsCmd = &cobra.Command{ 31 | Use: "details", 32 | Short: "Retrieve a specific application", 33 | Long: `Retrieve details for a specific application by identifier, scoped to the authorized API token`, 34 | Run: fetchApplicationDetails, 35 | } 36 | 37 | func fetchApplicationDetails(cmd *cobra.Command, args []string) { 38 | token := common.RequireAPIToken() 39 | params := map[string]interface{}{} 40 | application, err := provide.GetApplicationDetails(token, common.ApplicationID, params) 41 | if err != nil { 42 | log.Printf("Failed to retrieve details for application with id: %s; %s", common.ApplicationID, err.Error()) 43 | os.Exit(1) 44 | } 45 | result := fmt.Sprintf("%s\t%s\n", application.ID.String(), *application.Name) 46 | fmt.Print(result) 47 | } 48 | 49 | func init() { 50 | applicationsDetailsCmd.Flags().StringVar(&common.ApplicationID, "application", "", "id of the application") 51 | // applicationsDetailsCmd.MarkFlagRequired("application") 52 | } 53 | -------------------------------------------------------------------------------- /prvd/applications/applications_list.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package applications 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | provide "github.com/provideplatform/provide-go/api/ident" 26 | 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | var page uint64 31 | var rpp uint64 32 | 33 | var applicationsListCmd = &cobra.Command{ 34 | Use: "list", 35 | Short: "Retrieve a list of applications", 36 | Long: `Retrieve a list of applications scoped to the authorized API token`, 37 | Run: listApplications, 38 | } 39 | 40 | func listApplications(cmd *cobra.Command, args []string) { 41 | token := common.RequireAPIToken() 42 | params := map[string]interface{}{ 43 | "page": fmt.Sprintf("%d", page), 44 | "rpp": fmt.Sprintf("%d", rpp), 45 | } 46 | applications, err := provide.ListApplications(token, params) 47 | if err != nil { 48 | log.Printf("Failed to retrieve applications list; %s", err.Error()) 49 | os.Exit(1) 50 | } 51 | for i := range applications { 52 | application := applications[i] 53 | result := fmt.Sprintf("%s\t%s\n", application.ID.String(), *application.Name) 54 | fmt.Print(result) 55 | } 56 | } 57 | 58 | func init() { 59 | applicationsListCmd.Flags().Uint64Var(&page, "page", common.DefaultPage, "page number to retrieve") 60 | applicationsListCmd.Flags().Uint64Var(&rpp, "rpp", common.DefaultRpp, "number of applications to retrieve per page") 61 | applicationsListCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 62 | } 63 | -------------------------------------------------------------------------------- /prvd/axiom/baseline.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package axiom 18 | 19 | import ( 20 | "github.com/spf13/cobra" 21 | 22 | "github.com/provideplatform/provide-cli/prvd/axiom/domain_models" 23 | "github.com/provideplatform/provide-cli/prvd/axiom/stack" 24 | "github.com/provideplatform/provide-cli/prvd/axiom/subject_accounts" 25 | "github.com/provideplatform/provide-cli/prvd/axiom/workflows" 26 | "github.com/provideplatform/provide-cli/prvd/axiom/workgroups" 27 | "github.com/provideplatform/provide-cli/prvd/common" 28 | ) 29 | 30 | var Optional bool 31 | 32 | var BaselineCmd = &cobra.Command{ 33 | Use: "axiom", 34 | Short: "Interact with the axiom protocol", 35 | Long: `Interact with the axiom protocol.`, 36 | Run: func(cmd *cobra.Command, args []string) { 37 | common.CmdExistsOrExit(cmd, args) 38 | 39 | generalPrompt(cmd, args, "") 40 | }, 41 | } 42 | 43 | var proxyCmd = &cobra.Command{ 44 | Use: "proxy", 45 | Short: "See `prvd axiom stack --help` instead", 46 | Long: `Create, manage and interact with local axiom stack instances. 47 | 48 | See: prvd axiom stack --help instead. This command is deprecated and will be removed soon.`, 49 | Run: func(cmd *cobra.Command, args []string) { 50 | generalPrompt(cmd, args, "") 51 | }, 52 | } 53 | 54 | func init() { 55 | BaselineCmd.AddCommand(proxyCmd) 56 | BaselineCmd.AddCommand(stack.StackCmd) 57 | BaselineCmd.AddCommand(workgroups.WorkgroupsCmd) 58 | BaselineCmd.AddCommand(workflows.WorkflowsCmd) 59 | BaselineCmd.AddCommand(subject_accounts.SubjectAccountsCmd) 60 | BaselineCmd.AddCommand(domain_models.DomainModelsCmd) 61 | BaselineCmd.Flags().BoolVarP(&Optional, "optional", "", false, "List all the optional flags") 62 | } 63 | -------------------------------------------------------------------------------- /prvd/axiom/baseline_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package axiom 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/axiom/participants" 21 | "github.com/provideplatform/provide-cli/prvd/axiom/stack" 22 | "github.com/provideplatform/provide-cli/prvd/axiom/subject_accounts" 23 | "github.com/provideplatform/provide-cli/prvd/axiom/workflows" 24 | "github.com/provideplatform/provide-cli/prvd/axiom/workgroups" 25 | 26 | "github.com/provideplatform/provide-cli/prvd/common" 27 | 28 | "github.com/spf13/cobra" 29 | ) 30 | 31 | const promptStack = "Stack" 32 | const promptWorkgroups = "Workgroups" 33 | const promptWorkflows = "Workflows" 34 | const promptParticipant = "Participants" 35 | const promptSubjectAccounts = "Subject-Accounts" 36 | 37 | var emptyPromptArgs = []string{promptStack, promptWorkgroups, promptWorkflows, promptParticipant, promptSubjectAccounts} 38 | var emptyPromptLabel = "What would you like to do" 39 | 40 | // General Endpoints 41 | func generalPrompt(cmd *cobra.Command, args []string, currentStep string) { 42 | switch step := currentStep; step { 43 | case promptStack: 44 | stack.Optional = Optional 45 | stack.StackCmd.Run(cmd, args) 46 | case promptWorkgroups: 47 | workgroups.Optional = Optional 48 | workgroups.WorkgroupsCmd.Run(cmd, args) 49 | case promptWorkflows: 50 | workflows.Optional = Optional 51 | workflows.WorkflowsCmd.Run(cmd, args) 52 | case promptParticipant: 53 | participants.Optional = Optional 54 | participants.ParticipantsCmd.Run(cmd, args) 55 | case promptSubjectAccounts: 56 | subject_accounts.Optional = Optional 57 | subject_accounts.SubjectAccountsCmd.Run(cmd, args) 58 | case "": 59 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 60 | generalPrompt(cmd, args, result) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /prvd/axiom/domain_models/domain_models.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package domain_models 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var DomainModelsCmd = &cobra.Command{ 25 | Use: "domain-models", 26 | Short: "Interact with axiom domain models", 27 | Long: `Create, manage and interact with domain models via the axiom protocol.`, 28 | Run: func(cmd *cobra.Command, args []string) { 29 | common.CmdExistsOrExit(cmd, args) 30 | 31 | generalPrompt(cmd, args, "") 32 | }, 33 | } 34 | 35 | func init() { 36 | DomainModelsCmd.AddCommand(listBaselineDomainModelsCmd) 37 | DomainModelsCmd.AddCommand(initBaselineDomainModelCmd) 38 | // SubjectAccountsCmd.AddCommand(subjectAccountDetailsCmd) 39 | DomainModelsCmd.Flags().BoolVarP(&Optional, "optional", "", false, "List all the Optional flags") 40 | DomainModelsCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 41 | } 42 | -------------------------------------------------------------------------------- /prvd/axiom/domain_models/domain_models_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package domain_models 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | 22 | "github.com/spf13/cobra" 23 | ) 24 | 25 | const promptStepList = "List" 26 | const promptStepInit = "Initialize" 27 | 28 | var emptyPromptArgs = []string{promptStepList, promptStepInit} 29 | var emptyPromptLabel = "What would you like to do" 30 | 31 | // General Endpoints 32 | func generalPrompt(cmd *cobra.Command, args []string, step string) { 33 | switch step { 34 | case promptStepInit: 35 | initDomainModelRun(cmd, args) 36 | case promptStepList: 37 | page, rpp = common.PromptPagination(paginate, page, rpp) 38 | listDomainModelsRun(cmd, args) 39 | // case promptStepDetails: 40 | // fetchSubjectAccountDetailsRun(cmd, args) 41 | case "": 42 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 43 | generalPrompt(cmd, args, result) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /prvd/axiom/participants/invitations/invitations.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package invitations 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | 22 | "github.com/spf13/cobra" 23 | ) 24 | 25 | var ParticipantsInvitationsCmd = &cobra.Command{ 26 | Use: "invitations", 27 | Short: "Interact with axiom workgroup invitations", 28 | Long: `Invite, manage and interact with workgroup invitations via the axiom protocol.`, 29 | Run: func(cmd *cobra.Command, args []string) { 30 | common.CmdExistsOrExit(cmd, args) 31 | 32 | generalPrompt(cmd, args, "") 33 | }, 34 | } 35 | 36 | func init() { 37 | ParticipantsInvitationsCmd.AddCommand(listBaselineWorkgroupInvitationsCmd) 38 | 39 | ParticipantsInvitationsCmd.Flags().BoolVarP(&Optional, "Optional", "", false, "List all the Optional flags") 40 | ParticipantsInvitationsCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 41 | } 42 | -------------------------------------------------------------------------------- /prvd/axiom/participants/invitations/invitations_list.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package invitations 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | "github.com/provideplatform/provide-go/api/ident" 26 | "github.com/spf13/cobra" 27 | ) 28 | 29 | var page uint64 30 | var rpp uint64 31 | 32 | var listBaselineWorkgroupInvitationsCmd = &cobra.Command{ 33 | Use: "list", 34 | Short: "List workgroup invitations", 35 | Long: `List the pending invitations for a axiom workgroup`, 36 | Run: listInvitations, 37 | } 38 | 39 | func listInvitations(cmd *cobra.Command, args []string) { 40 | generalPrompt(cmd, args, promptStepList) 41 | } 42 | 43 | func listInvitationsRun(cmd *cobra.Command, args []string) { 44 | if common.OrganizationID == "" { 45 | common.RequireOrganization() 46 | } 47 | if common.WorkgroupID == "" { 48 | common.RequireWorkgroup() 49 | } 50 | 51 | common.AuthorizeOrganizationContext(false) 52 | 53 | token, err := common.ResolveOrganizationToken() 54 | if err != nil { 55 | log.Printf("failed to fetch axiom workgroup invitations; %s", err.Error()) 56 | os.Exit(1) 57 | } 58 | 59 | invitations, err := ident.ListApplicationInvitations(*token.AccessToken, common.WorkgroupID, map[string]interface{}{ 60 | "page": fmt.Sprintf("%d", page), 61 | "rpp": fmt.Sprintf("%d", rpp), 62 | }) 63 | if err != nil { 64 | log.Printf("failed to fetch axiom workgroup invitations; %s", err.Error()) 65 | os.Exit(1) 66 | } 67 | 68 | if len(invitations) == 0 { 69 | fmt.Print("No Pending Invitations Found") 70 | } 71 | 72 | for _, invitation := range invitations { 73 | result := fmt.Sprintf("%s\n", invitation.Email) // TODO-- make this show more relevant information 74 | fmt.Print(result) 75 | } 76 | } 77 | 78 | func init() { 79 | listBaselineWorkgroupInvitationsCmd.Flags().StringVar(&common.OrganizationID, "organization", "", "organization identifier") 80 | listBaselineWorkgroupInvitationsCmd.Flags().StringVar(&common.WorkgroupID, "workgroup", "", "workgroup identifier") 81 | 82 | listBaselineWorkgroupInvitationsCmd.Flags().Uint64Var(&page, "page", common.DefaultPage, "page number to retrieve") 83 | listBaselineWorkgroupInvitationsCmd.Flags().Uint64Var(&rpp, "rpp", common.DefaultRpp, "number of participants to retrieve per page") 84 | listBaselineWorkgroupInvitationsCmd.Flags().BoolVarP(&Optional, "Optional", "", false, "List all the Optional flags") 85 | listBaselineWorkgroupInvitationsCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 86 | } 87 | -------------------------------------------------------------------------------- /prvd/axiom/participants/invitations/invitations_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package invitations 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | 22 | "github.com/spf13/cobra" 23 | ) 24 | 25 | const promptStepList = "List" 26 | 27 | // const promptStepInvite = "Invite" 28 | 29 | var emptyPromptArgs = []string{promptStepList} 30 | var emptyPromptLabel = "What would you like to do" 31 | 32 | var Optional bool 33 | var paginate bool 34 | 35 | // General Endpoints 36 | func generalPrompt(cmd *cobra.Command, args []string, step string) { 37 | switch step { 38 | case promptStepList: 39 | // page, rpp = common.PromptPagination(paginate, page, rpp) 40 | listInvitationsRun(cmd, args) 41 | // case promptStepInvite: 42 | // inviteOrganizationRun(cmd, args) 43 | case "": 44 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 45 | generalPrompt(cmd, args, result) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /prvd/axiom/participants/organizations/organizations.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package organizations 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var ParticipantsOrganizationsCmd = &cobra.Command{ 25 | Use: "organizations", 26 | Short: "Interact with axiom organization participants", 27 | Long: `Create, manage and interact with organization participants via the axiom protocol.`, 28 | Run: func(cmd *cobra.Command, args []string) { 29 | common.CmdExistsOrExit(cmd, args) 30 | 31 | generalPrompt(cmd, args, "") 32 | }, 33 | } 34 | 35 | func init() { 36 | ParticipantsOrganizationsCmd.AddCommand(inviteBaselineWorkgroupOrganizationCmd) 37 | ParticipantsOrganizationsCmd.AddCommand(listBaselineWorkgroupOrganizationsCmd) 38 | 39 | ParticipantsOrganizationsCmd.Flags().BoolVarP(&Optional, "optional", "", false, "List all the Optional flags") 40 | ParticipantsOrganizationsCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 41 | } 42 | -------------------------------------------------------------------------------- /prvd/axiom/participants/organizations/organizations_list.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package organizations 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | "github.com/provideplatform/provide-go/api/ident" 26 | "github.com/spf13/cobra" 27 | ) 28 | 29 | var page uint64 30 | var rpp uint64 31 | 32 | var listBaselineWorkgroupOrganizationsCmd = &cobra.Command{ 33 | Use: "list", 34 | Short: "List workgroup organizations", 35 | Long: `List the organizations for a axiom workgroup`, 36 | Run: listOrganizations, 37 | } 38 | 39 | func listOrganizations(cmd *cobra.Command, args []string) { 40 | generalPrompt(cmd, args, promptStepList) 41 | } 42 | 43 | func listOrganizationsRun(cmd *cobra.Command, args []string) { 44 | if common.OrganizationID == "" { 45 | common.RequireOrganization() 46 | } 47 | if common.WorkgroupID == "" { 48 | common.RequireWorkgroup() 49 | } 50 | 51 | common.AuthorizeOrganizationContext(false) 52 | 53 | token, err := common.ResolveOrganizationToken() 54 | if err != nil { 55 | log.Printf("failed to fetch axiom workgroup organizations; %s", err.Error()) 56 | os.Exit(1) 57 | } 58 | 59 | orgs, err := ident.ListApplicationOrganizations(*token.AccessToken, common.WorkgroupID, map[string]interface{}{ 60 | "page": fmt.Sprintf("%d", page), 61 | "rpp": fmt.Sprintf("%d", rpp), 62 | }) 63 | if err != nil { 64 | log.Printf("failed to fetch axiom workgroup organizations; %s", err.Error()) 65 | os.Exit(1) 66 | } 67 | 68 | for _, org := range orgs { 69 | result := fmt.Sprintf("%s\t%s\n", *org.ID, *org.Name) // TODO-- show DegreeOfSeparation 70 | fmt.Print(result) 71 | } 72 | } 73 | 74 | func init() { 75 | listBaselineWorkgroupOrganizationsCmd.Flags().StringVar(&common.OrganizationID, "organization", "", "organization identifier") 76 | listBaselineWorkgroupOrganizationsCmd.Flags().StringVar(&common.WorkgroupID, "workgroup", "", "workgroup identifier") 77 | 78 | listBaselineWorkgroupOrganizationsCmd.Flags().Uint64Var(&page, "page", common.DefaultPage, "page number to retrieve") 79 | listBaselineWorkgroupOrganizationsCmd.Flags().Uint64Var(&rpp, "rpp", common.DefaultRpp, "number of participants to retrieve per page") 80 | listBaselineWorkgroupOrganizationsCmd.Flags().BoolVarP(&Optional, "Optional", "", false, "List all the Optional flags") 81 | listBaselineWorkgroupOrganizationsCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 82 | } 83 | -------------------------------------------------------------------------------- /prvd/axiom/participants/organizations/organizations_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package organizations 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | 22 | "github.com/spf13/cobra" 23 | ) 24 | 25 | const promptStepList = "List" 26 | const promptStepInvite = "Invite" 27 | 28 | var emptyPromptArgs = []string{promptStepInvite, promptStepList} 29 | var emptyPromptLabel = "What would you like to do" 30 | 31 | var Optional bool 32 | var paginate bool 33 | 34 | // General Endpoints 35 | func generalPrompt(cmd *cobra.Command, args []string, step string) { 36 | switch step { 37 | case promptStepList: 38 | // page, rpp = common.PromptPagination(paginate, page, rpp) 39 | listOrganizationsRun(cmd, args) 40 | case promptStepInvite: 41 | inviteOrganizationRun(cmd, args) 42 | case "": 43 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 44 | generalPrompt(cmd, args, result) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /prvd/axiom/participants/participants.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package participants 18 | 19 | import ( 20 | participants_invitations "github.com/provideplatform/provide-cli/prvd/axiom/participants/invitations" 21 | participants_organizations "github.com/provideplatform/provide-cli/prvd/axiom/participants/organizations" 22 | participants_users "github.com/provideplatform/provide-cli/prvd/axiom/participants/users" 23 | "github.com/provideplatform/provide-cli/prvd/common" 24 | 25 | "github.com/spf13/cobra" 26 | ) 27 | 28 | var ParticipantsCmd = &cobra.Command{ 29 | Use: "participants", 30 | Short: "Interact with participants in a axiom workgroup", 31 | Long: `Invite, manage and interact with workgroup participants via the axiom protocol.`, 32 | Run: func(cmd *cobra.Command, args []string) { 33 | common.CmdExistsOrExit(cmd, args) 34 | 35 | generalPrompt(cmd, args, "") 36 | }, 37 | } 38 | 39 | func init() { 40 | ParticipantsCmd.AddCommand(participants_users.ParticipantsUsersCmd) 41 | ParticipantsCmd.AddCommand(participants_organizations.ParticipantsOrganizationsCmd) 42 | ParticipantsCmd.AddCommand(participants_invitations.ParticipantsInvitationsCmd) 43 | 44 | ParticipantsCmd.Flags().BoolVarP(&Optional, "Optional", "", false, "List all the Optional flags") 45 | ParticipantsCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 46 | } 47 | -------------------------------------------------------------------------------- /prvd/axiom/participants/participants_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package participants 18 | 19 | import ( 20 | participants_invitations "github.com/provideplatform/provide-cli/prvd/axiom/participants/invitations" 21 | participants_organizations "github.com/provideplatform/provide-cli/prvd/axiom/participants/organizations" 22 | participants_users "github.com/provideplatform/provide-cli/prvd/axiom/participants/users" 23 | "github.com/provideplatform/provide-cli/prvd/common" 24 | 25 | "github.com/spf13/cobra" 26 | ) 27 | 28 | const promptStepUsers = "Users" 29 | const promptStepOrganizations = "Organizations" 30 | const promptStepInvitations = "Invitations" 31 | 32 | var emptyPromptArgs = []string{promptStepUsers, promptStepOrganizations, promptStepInvitations} 33 | var emptyPromptLabel = "What would you like to do" 34 | 35 | var Optional bool 36 | var paginate bool 37 | 38 | // var custodyPromptArgs = []string{"No", "Yes"} 39 | // var custodyPromptLabel = "Would you like the participant to be a managed tenant?" 40 | 41 | // General Endpoints 42 | func generalPrompt(cmd *cobra.Command, args []string, step string) { 43 | switch step { 44 | // case promptStepInviteUser: 45 | // inviteUserRun(cmd, args) 46 | // case promptStepInviteOrganization: 47 | // inviteOrganizationRun(cmd, args) 48 | // case promptStepList: 49 | // if Optional { 50 | // fmt.Println("Optional Flags:") 51 | // if common.ApplicationID == "" { 52 | // common.RequireApplication() 53 | // } 54 | // } 55 | // page, rpp = common.PromptPagination(paginate, page, rpp) 56 | // listParticipantsRun(cmd, args) 57 | case promptStepUsers: 58 | participants_users.Optional = Optional 59 | participants_users.ParticipantsUsersCmd.Run(cmd, args) 60 | case promptStepOrganizations: 61 | participants_organizations.Optional = Optional 62 | participants_organizations.ParticipantsOrganizationsCmd.Run(cmd, args) 63 | case promptStepInvitations: 64 | participants_invitations.Optional = Optional 65 | participants_invitations.ParticipantsInvitationsCmd.Run(cmd, args) 66 | case "": 67 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 68 | generalPrompt(cmd, args, result) 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /prvd/axiom/participants/users/users.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package users 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var ParticipantsUsersCmd = &cobra.Command{ 25 | Use: "users", 26 | Short: "Interact with axiom user participants", 27 | Long: `Create, manage and interact with user participants via the axiom protocol.`, 28 | Run: func(cmd *cobra.Command, args []string) { 29 | common.CmdExistsOrExit(cmd, args) 30 | 31 | generalPrompt(cmd, args, "") 32 | }, 33 | } 34 | 35 | func init() { 36 | ParticipantsUsersCmd.AddCommand(inviteBaselineWorkgroupUserCmd) 37 | ParticipantsUsersCmd.AddCommand(listBaselineWorkgroupUsersCmd) 38 | 39 | ParticipantsUsersCmd.Flags().BoolVarP(&Optional, "optional", "", false, "List all the Optional flags") 40 | ParticipantsUsersCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 41 | } 42 | -------------------------------------------------------------------------------- /prvd/axiom/participants/users/users_list.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package users 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | "github.com/provideplatform/provide-go/api/ident" 26 | "github.com/spf13/cobra" 27 | ) 28 | 29 | var page uint64 30 | var rpp uint64 31 | 32 | var listBaselineWorkgroupUsersCmd = &cobra.Command{ 33 | Use: "list", 34 | Short: "List workgroup users", 35 | Long: `List the users for a axiom workgroup`, // TODO-- actually lists organization users 36 | Run: listUsers, 37 | } 38 | 39 | func listUsers(cmd *cobra.Command, args []string) { 40 | generalPrompt(cmd, args, promptStepList) 41 | } 42 | 43 | func listUsersRun(cmd *cobra.Command, args []string) { 44 | if common.OrganizationID == "" { 45 | common.RequireOrganization() 46 | } 47 | 48 | common.AuthorizeOrganizationContext(false) 49 | 50 | token, err := common.ResolveOrganizationToken() 51 | 52 | users, err := ident.ListOrganizationUsers(*token.AccessToken, common.OrganizationID, map[string]interface{}{ 53 | "page": fmt.Sprintf("%d", page), 54 | "rpp": fmt.Sprintf("%d", rpp), 55 | }) 56 | if err != nil { 57 | log.Printf("failed to fetch axiom workgroup users; %s", err.Error()) 58 | os.Exit(1) 59 | } 60 | 61 | for _, user := range users { 62 | result := fmt.Sprintf("%s\t%s\n", *user.ID, user.Name) // TODO-- show role from permissions / Workgroup.UserID 63 | fmt.Print(result) 64 | } 65 | } 66 | 67 | func init() { 68 | listBaselineWorkgroupUsersCmd.Flags().StringVar(&common.OrganizationID, "organization", "", "organization identifier") 69 | 70 | listBaselineWorkgroupUsersCmd.Flags().Uint64Var(&page, "page", common.DefaultPage, "page number to retrieve") 71 | listBaselineWorkgroupUsersCmd.Flags().Uint64Var(&rpp, "rpp", common.DefaultRpp, "number of participants to retrieve per page") 72 | listBaselineWorkgroupUsersCmd.Flags().BoolVarP(&Optional, "Optional", "", false, "List all the Optional flags") 73 | listBaselineWorkgroupUsersCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 74 | } 75 | -------------------------------------------------------------------------------- /prvd/axiom/participants/users/users_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package users 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | 22 | "github.com/spf13/cobra" 23 | ) 24 | 25 | const promptStepList = "List" 26 | const promptStepInvite = "Invite" 27 | 28 | var emptyPromptArgs = []string{promptStepInvite, promptStepList} 29 | var emptyPromptLabel = "What would you like to do" 30 | 31 | var Optional bool 32 | var paginate bool 33 | 34 | // General Endpoints 35 | func generalPrompt(cmd *cobra.Command, args []string, step string) { 36 | switch step { 37 | case promptStepList: 38 | // page, rpp = common.PromptPagination(paginate, page, rpp) 39 | listUsersRun(cmd, args) 40 | case promptStepInvite: 41 | inviteUserRun(cmd, args) 42 | case "": 43 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 44 | generalPrompt(cmd, args, result) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /prvd/axiom/stack/stack.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package stack 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var StackCmd = &cobra.Command{ 25 | Use: "stack", 26 | Short: "Interact with a local axiom stack", 27 | Long: `Create, manage and interact with local axiom stack instances.`, 28 | Run: func(cmd *cobra.Command, args []string) { 29 | common.CmdExistsOrExit(cmd, args) 30 | 31 | generalPrompt(cmd, args, "") 32 | }, 33 | } 34 | 35 | var runBaselineStackCmd = &cobra.Command{ 36 | Use: "run", 37 | Short: "See `prvd axiom stack start --help` instead", 38 | Long: `Start a local axiom stack instance and connect to internal systems of record. 39 | 40 | See: prvd axiom stack run --help instead. This command is deprecated and will be removed soon.`, 41 | Run: func(cmd *cobra.Command, args []string) { 42 | runStackStart(cmd, args) 43 | }, 44 | } 45 | 46 | func init() { 47 | StackCmd.AddCommand(logsBaselineStackCmd) 48 | StackCmd.AddCommand(runBaselineStackCmd) 49 | StackCmd.AddCommand(startBaselineStackCmd) 50 | StackCmd.AddCommand(stopBaselineStackCmd) 51 | StackCmd.Flags().BoolVarP(&Optional, "optional", "", false, "List all the optional flags") 52 | } 53 | -------------------------------------------------------------------------------- /prvd/axiom/stack/stack_logs.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package stack 18 | 19 | import ( 20 | "log" 21 | "os" 22 | "sync" 23 | 24 | "github.com/docker/docker/client" 25 | "github.com/provideplatform/provide-cli/prvd/common" 26 | 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | var logsBaselineStackCmd = &cobra.Command{ 31 | Use: "logs", 32 | Short: "Print axiom stack logs", 33 | Long: `Print the logs from each container in a local axiom stack instance`, 34 | Run: stackLogs, 35 | } 36 | 37 | func stackLogs(cmd *cobra.Command, args []string) { 38 | generalPrompt(cmd, args, promptStepLogs) 39 | } 40 | 41 | func stackLogsRun(cmd *cobra.Command, args []string) { 42 | docker, err := client.NewEnvClient() 43 | if err != nil { 44 | log.Printf("failed to initialize docker; %s", err.Error()) 45 | os.Exit(1) 46 | } 47 | 48 | wg := sync.WaitGroup{} 49 | common.LogContainers(docker, &wg, name) 50 | wg.Wait() 51 | } 52 | 53 | func init() { 54 | logsBaselineStackCmd.Flags().StringVar(&name, "name", "axiom-local", "name of the axiom stack instance") 55 | } 56 | -------------------------------------------------------------------------------- /prvd/axiom/stack/stack_stop.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package stack 18 | 19 | import ( 20 | "log" 21 | "os" 22 | 23 | "github.com/docker/docker/client" 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | 26 | "github.com/spf13/cobra" 27 | ) 28 | 29 | var stopBaselineStackCmd = &cobra.Command{ 30 | Use: "stop", 31 | Short: "Stop the axiom stack", 32 | Long: `Stop a local axiom stack instance`, 33 | Run: stopStack, 34 | } 35 | 36 | func stopStack(cmd *cobra.Command, args []string) { 37 | generalPrompt(cmd, args, promptStepStop) 38 | } 39 | 40 | func runStackStop(cmd *cobra.Command, args []string) { 41 | docker, err := client.NewEnvClient() 42 | if err != nil { 43 | log.Printf("failed to initialize docker; %s", err.Error()) 44 | os.Exit(1) 45 | } 46 | 47 | if !prune { 48 | common.StopContainers(docker, name) 49 | } else { 50 | common.PurgeContainers(docker, name, true) 51 | common.PurgeNetwork(docker, name) 52 | } 53 | 54 | log.Printf("%s local axiom instance stopped", name) 55 | } 56 | 57 | func init() { 58 | stopBaselineStackCmd.Flags().StringVar(&name, "name", "axiom-local", "name of the axiom stack instance") 59 | stopBaselineStackCmd.Flags().BoolVar(&prune, "prune", false, "when true, previously-created docker resources are pruned prior to stack initialization") 60 | } 61 | -------------------------------------------------------------------------------- /prvd/axiom/subject_accounts/subject_accounts.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package subject_accounts 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var SubjectAccountsCmd = &cobra.Command{ 25 | Use: "subject-accounts", 26 | Short: "Interact with axiom subject accounts", 27 | Long: `Create, manage and interact with subject accounts via the axiom protocol.`, 28 | Run: func(cmd *cobra.Command, args []string) { 29 | common.CmdExistsOrExit(cmd, args) 30 | 31 | generalPrompt(cmd, args, "") 32 | }, 33 | } 34 | 35 | func init() { 36 | SubjectAccountsCmd.AddCommand(listBaselineSubjectAccountsCmd) 37 | SubjectAccountsCmd.AddCommand(initBaselineSubjectAccountCmd) 38 | SubjectAccountsCmd.AddCommand(subjectAccountDetailsCmd) 39 | SubjectAccountsCmd.Flags().BoolVarP(&Optional, "optional", "", false, "List all the Optional flags") 40 | SubjectAccountsCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 41 | } 42 | -------------------------------------------------------------------------------- /prvd/axiom/subject_accounts/subject_accounts_details.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package subject_accounts 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | "github.com/provideplatform/provide-go/api/axiom" 26 | 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | var subjectAccountDetailsCmd = &cobra.Command{ 31 | Use: "details", 32 | Short: "Retrieve a specific subject account", 33 | Long: `Retrieve details for a specific axiom subject account`, 34 | Run: fetchSubjectAccountDetails, 35 | } 36 | 37 | func fetchSubjectAccountDetails(cmd *cobra.Command, args []string) { 38 | generalPrompt(cmd, args, promptStepDetails) 39 | } 40 | 41 | func fetchSubjectAccountDetailsRun(cmd *cobra.Command, args []string) { 42 | if common.OrganizationID == "" { 43 | common.RequireOrganization() 44 | } 45 | 46 | if common.WorkgroupID == "" { 47 | common.RequireWorkgroup() 48 | } 49 | 50 | token, err := common.ResolveOrganizationToken() 51 | 52 | if common.SubjectAccountID == "" { 53 | common.SubjectAccountID = common.SHA256(fmt.Sprintf("%s.%s", common.OrganizationID, common.WorkgroupID)) 54 | } 55 | 56 | sa, err := axiom.GetSubjectAccountDetails(*token.AccessToken, common.OrganizationID, common.SubjectAccountID, map[string]interface{}{}) 57 | if err != nil { 58 | log.Printf("Failed to retrieve details for subject account with id: %s; %s", common.OrganizationID, err.Error()) 59 | os.Exit(1) 60 | } 61 | 62 | if sa.ID == nil { 63 | fmt.Println("subject account not found") 64 | return 65 | } 66 | 67 | result := fmt.Sprintf("%s;\tworkgroup: %s\t%s;\torganization: %s\t%s\n", *sa.ID, common.Workgroup.ID, *common.Workgroup.Name, *common.Organization.ID, *common.Organization.Name) 68 | fmt.Print(result) 69 | } 70 | 71 | func init() { 72 | subjectAccountDetailsCmd.Flags().StringVar(&common.OrganizationID, "organization", "", "organization identifier") 73 | subjectAccountDetailsCmd.Flags().StringVar(&common.WorkgroupID, "workgroup", "", "workgroup identifier") 74 | subjectAccountDetailsCmd.Flags().StringVar(&common.SubjectAccountID, "subject-account", "", "subject account identifier") 75 | } 76 | -------------------------------------------------------------------------------- /prvd/axiom/subject_accounts/subject_accounts_list.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package subject_accounts 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | "github.com/provideplatform/provide-go/api/axiom" 26 | "github.com/provideplatform/provide-go/api/ident" 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | var page uint64 31 | var rpp uint64 32 | 33 | var listBaselineSubjectAccountsCmd = &cobra.Command{ 34 | Use: "list", 35 | Short: "List axiom subject accounts", 36 | Long: `List all available axiom subject accounts`, 37 | Run: listSubjectAccounts, 38 | } 39 | 40 | func listSubjectAccounts(cmd *cobra.Command, args []string) { 41 | generalPrompt(cmd, args, promptStepList) 42 | } 43 | 44 | func listSubjectAccountsRun(cmd *cobra.Command, args []string) { 45 | token, err := common.ResolveOrganizationToken() 46 | if err != nil { 47 | log.Printf("failed to retrieve axiom subject accounts; %s", err.Error()) 48 | os.Exit(1) 49 | } 50 | 51 | subject_accounts, err := axiom.ListSubjectAccounts(*token.AccessToken, common.OrganizationID, map[string]interface{}{ 52 | "page": fmt.Sprintf("%d", page), 53 | "rpp": fmt.Sprintf("%d", rpp), 54 | }) 55 | if err != nil { 56 | log.Printf("failed to retrieve axiom subject accounts; %s", err.Error()) 57 | os.Exit(1) 58 | } 59 | // fmt.Printf("subject accounts len: %v", len(subject_accounts)) 60 | for _, subject_account := range subject_accounts { 61 | details, err := axiom.GetSubjectAccountDetails(*token.AccessToken, common.OrganizationID, *subject_account.ID, map[string]interface{}{}) 62 | if err != nil { 63 | log.Printf("failed to retrieve axiom subject accounts; %s", err.Error()) 64 | os.Exit(1) 65 | } 66 | 67 | subject_account_wg, err := axiom.GetWorkgroupDetails(*token.AccessToken, *details.Metadata.WorkgroupID, map[string]interface{}{}) 68 | if err != nil { 69 | log.Printf("failed to retrieve axiom subject accounts; %s", err.Error()) 70 | os.Exit(1) 71 | } 72 | 73 | subject_account_org, err := ident.GetOrganizationDetails(*token.AccessToken, *details.Metadata.OrganizationID, map[string]interface{}{}) 74 | if err != nil { 75 | log.Printf("failed to retrieve axiom subject accounts; %s", err.Error()) 76 | os.Exit(1) 77 | } 78 | 79 | result := fmt.Sprintf("%s;\tworkgroup: %s\t%s;\torganization: %s\t%s\n", *subject_account.ID, subject_account_wg.ID, *subject_account_wg.Name, *subject_account_org.ID, *subject_account_org.Name) 80 | fmt.Print(result) 81 | } 82 | } 83 | 84 | func init() { 85 | listBaselineSubjectAccountsCmd.Flags().StringVar(&common.OrganizationID, "organization", "", "organization identifier") 86 | 87 | listBaselineSubjectAccountsCmd.Flags().Uint64Var(&page, "page", common.DefaultPage, "page number to retrieve") 88 | listBaselineSubjectAccountsCmd.Flags().Uint64Var(&rpp, "rpp", common.DefaultRpp, "number of axiom subject accounts to retrieve per page") 89 | listBaselineSubjectAccountsCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 90 | } 91 | -------------------------------------------------------------------------------- /prvd/axiom/subject_accounts/subject_accounts_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package subject_accounts 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | 22 | "github.com/spf13/cobra" 23 | ) 24 | 25 | const promptStepInit = "Initialize" 26 | const promptStepList = "List" 27 | const promptStepDetails = "Details" 28 | 29 | var emptyPromptArgs = []string{promptStepList} 30 | var emptyPromptLabel = "What would you like to do" 31 | 32 | // General Endpoints 33 | func generalPrompt(cmd *cobra.Command, args []string, step string) { 34 | switch step { 35 | case promptStepInit: 36 | createSubjectAccountRun(cmd, args) 37 | case promptStepList: 38 | page, rpp = common.PromptPagination(paginate, page, rpp) 39 | listSubjectAccountsRun(cmd, args) 40 | case promptStepDetails: 41 | fetchSubjectAccountDetailsRun(cmd, args) 42 | case "": 43 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 44 | generalPrompt(cmd, args, result) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /prvd/axiom/systems/systems.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package systems 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var Optional bool 25 | var paginate bool 26 | 27 | var SystemsCmd = &cobra.Command{ 28 | Use: "systems", 29 | Short: "Interact with axiom workgroup systems", 30 | Long: `Create, manage and interact with workgroup systems of record via the axiom protocol.`, 31 | Run: func(cmd *cobra.Command, args []string) { 32 | common.CmdExistsOrExit(cmd, args) 33 | 34 | generalPrompt(cmd, args, "") 35 | }, 36 | } 37 | 38 | func init() { 39 | SystemsCmd.AddCommand(initBaselineSystemCmd) 40 | SystemsCmd.AddCommand(listBaselineSystemsCmd) 41 | SystemsCmd.AddCommand(detailBaselineSystemCmd) 42 | SystemsCmd.Flags().BoolVarP(&Optional, "optional", "", false, "List all the Optional flags") 43 | SystemsCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 44 | } 45 | -------------------------------------------------------------------------------- /prvd/axiom/systems/systems_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package systems 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | 22 | "github.com/spf13/cobra" 23 | ) 24 | 25 | const promptStepInit = "Initialize" 26 | const promptStepUpdate = "Update" 27 | const promptStepList = "List" 28 | const promptStepDetails = "Details" 29 | 30 | var emptyPromptArgs = []string{promptStepList, promptStepDetails, promptStepInit, promptStepUpdate} 31 | var emptyPromptLabel = "What would you like to do" 32 | 33 | // General Endpoints 34 | func generalPrompt(cmd *cobra.Command, args []string, step string) { 35 | switch step { 36 | case promptStepInit: 37 | initSystemRun(cmd, args) 38 | case promptStepList: 39 | // page, rpp = common.PromptPagination(paginate, page, rpp) 40 | listSystemsRun(cmd, args) 41 | // case promptStepDetails: 42 | // fetchSubjectAccountDetailsRun(cmd, args) 43 | case promptStepDetails: 44 | fetchSystemDetailsRun(cmd, args) 45 | case "": 46 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 47 | generalPrompt(cmd, args, result) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /prvd/axiom/workflows/messages/list.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package messages 18 | 19 | import ( 20 | "log" 21 | "os" 22 | 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | var listBaselineMessagesCmd = &cobra.Command{ 27 | Use: "list", 28 | Short: "List axiom messages", 29 | Long: `List axiom messages in the context of a workflow`, 30 | Run: listMessages, 31 | } 32 | 33 | func listMessages(cmd *cobra.Command, args []string) { 34 | log.Printf("not implemented") 35 | os.Exit(1) 36 | } 37 | 38 | func init() { 39 | 40 | } 41 | -------------------------------------------------------------------------------- /prvd/axiom/workflows/messages/messages.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package messages 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var MessagesCmd = &cobra.Command{ 25 | Use: "messages", 26 | Short: "Interact with a axiom workflows", 27 | Long: `Create, manage and interact with workflows via the axiom protocol.`, 28 | Run: func(cmd *cobra.Command, args []string) { 29 | common.CmdExistsOrExit(cmd, args) 30 | 31 | generalPrompt(cmd, args, "") 32 | }, 33 | } 34 | 35 | func init() { 36 | MessagesCmd.AddCommand(listBaselineMessagesCmd) 37 | MessagesCmd.AddCommand(sendBaselineMessageCmd) 38 | MessagesCmd.Flags().BoolVarP(&Optional, "optional", "", false, "List all the Optional flags") 39 | } 40 | -------------------------------------------------------------------------------- /prvd/axiom/workflows/messages/messages_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package messages 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | const promptStepSend = "Send" 25 | 26 | var items = map[string]string{"General Consistency": "general_consistency"} 27 | var custodyPromptLabel = "Message Type" 28 | 29 | var emptyPromptArgs = []string{promptStepSend} 30 | var emptyPromptLabel = "What would you like to do" 31 | 32 | // General Endpoints 33 | func generalPrompt(cmd *cobra.Command, args []string, currentStep string) { 34 | switch step := currentStep; step { 35 | case promptStepSend: 36 | sendMessageRun(cmd, args) 37 | case "": 38 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 39 | generalPrompt(cmd, args, result) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /prvd/axiom/workflows/workflows.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package workflows 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/axiom/workflows/messages" 21 | "github.com/provideplatform/provide-cli/prvd/axiom/workflows/worksteps" 22 | "github.com/provideplatform/provide-cli/prvd/common" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | var paginate bool 27 | 28 | var WorkflowsCmd = &cobra.Command{ 29 | Use: "workflows", 30 | Short: "Interact with a axiom workflows", 31 | Long: `Create, manage and interact with workflows via the axiom protocol.`, 32 | Run: func(cmd *cobra.Command, args []string) { 33 | common.CmdExistsOrExit(cmd, args) 34 | 35 | generalPrompt(cmd, args, "") 36 | }, 37 | } 38 | 39 | func init() { 40 | WorkflowsCmd.AddCommand(listBaselineWorkflowsCmd) 41 | WorkflowsCmd.AddCommand(detailBaselineWorkflowCmd) 42 | WorkflowsCmd.AddCommand(initBaselineWorkflowCmd) 43 | WorkflowsCmd.AddCommand(deployBaselineWorkflowCmd) 44 | WorkflowsCmd.AddCommand(versionBaselineWorkflowCmd) 45 | WorkflowsCmd.AddCommand(worksteps.WorkstepsCmd) 46 | WorkflowsCmd.AddCommand(messages.MessagesCmd) 47 | WorkflowsCmd.Flags().BoolVarP(&Optional, "optional", "", false, "List all the Optional flags") 48 | } 49 | -------------------------------------------------------------------------------- /prvd/axiom/workflows/workflows_deploy.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package workflows 18 | 19 | import ( 20 | "encoding/json" 21 | "fmt" 22 | "log" 23 | "os" 24 | 25 | "github.com/provideplatform/provide-cli/prvd/common" 26 | "github.com/provideplatform/provide-go/api/axiom" 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | var deployBaselineWorkflowCmd = &cobra.Command{ 31 | Use: "deploy", 32 | Short: "deploy axiom workflow", 33 | Long: `deploy a axiom prototype workflow`, 34 | Run: deployWorkflow, 35 | } 36 | 37 | func deployWorkflow(cmd *cobra.Command, args []string) { 38 | generalPrompt(cmd, args, promptStepDeploy) 39 | } 40 | 41 | func deployWorkflowRun(cmd *cobra.Command, args []string) { 42 | if common.OrganizationID == "" { 43 | common.RequireOrganization() 44 | } 45 | if common.WorkgroupID == "" { 46 | common.RequireWorkgroup() 47 | } 48 | 49 | token, err := common.ResolveOrganizationToken() 50 | if err != nil { 51 | log.Printf("failed to deploy workflow; %s", err.Error()) 52 | os.Exit(1) 53 | } 54 | if workflowID == "" { 55 | workflowPrompt(*token.AccessToken) 56 | } 57 | 58 | w, err := axiom.GetWorkflowDetails(*token.AccessToken, workflowID, map[string]interface{}{}) 59 | if err != nil { 60 | log.Printf("failed to deploy workflow; %s", err.Error()) 61 | os.Exit(1) 62 | } 63 | if w.WorkflowID != nil { 64 | log.Print("failed to deploy workflow; cannot deploy a workflow instance") 65 | os.Exit(1) 66 | } 67 | if *w.Status != "draft" { 68 | log.Print("failed to deploy workflow; cannot deploy a non-draft instance") 69 | os.Exit(1) 70 | } 71 | 72 | ws, err := axiom.ListWorksteps(*token.AccessToken, workflowID, map[string]interface{}{}) 73 | if err != nil { 74 | log.Printf("failed to deploy workflow; %s", err.Error()) 75 | os.Exit(1) 76 | } 77 | 78 | hasFinality := false 79 | for _, workstep := range ws { 80 | var metadata map[string]interface{} 81 | raw, _ := json.Marshal(workstep.Metadata) 82 | json.Unmarshal(raw, &metadata) 83 | 84 | if metadata["prover"] == nil { 85 | log.Printf("failed to deploy workflow; all worksteps must have a prover") 86 | os.Exit(1) 87 | } 88 | 89 | if workstep.RequireFinality { 90 | hasFinality = true 91 | } 92 | } 93 | 94 | if !hasFinality { 95 | log.Printf("failed to deploy workflow; at least 1 workstep must require finality") 96 | os.Exit(1) 97 | } 98 | 99 | deployed, err := axiom.DeployWorkflow(*token.AccessToken, workflowID, map[string]interface{}{}) 100 | if err != nil { 101 | fmt.Printf("failed to deploy workflow; %s", err.Error()) 102 | os.Exit(1) 103 | } 104 | 105 | // wait til status is deployed ? 106 | 107 | result, _ := json.MarshalIndent(deployed, "", "\t") 108 | fmt.Printf("%s\n", string(result)) 109 | } 110 | 111 | func init() { 112 | deployBaselineWorkflowCmd.Flags().StringVar(&common.OrganizationID, "organization", os.Getenv("PROVIDE_ORGANIZATION_ID"), "organization identifier") 113 | deployBaselineWorkflowCmd.Flags().StringVar(&common.WorkgroupID, "workgroup", "", "workgroup identifier") 114 | deployBaselineWorkflowCmd.Flags().StringVar(&workflowID, "workflow", "", "workflow identifier") 115 | 116 | deployBaselineWorkflowCmd.Flags().BoolVarP(&Optional, "optional", "", false, "List all the Optional flags") 117 | } 118 | -------------------------------------------------------------------------------- /prvd/axiom/workflows/workflows_details.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package workflows 18 | 19 | import ( 20 | "encoding/json" 21 | "fmt" 22 | "log" 23 | "os" 24 | 25 | "github.com/manifoldco/promptui" 26 | "github.com/provideplatform/provide-cli/prvd/common" 27 | "github.com/provideplatform/provide-go/api/axiom" 28 | 29 | "github.com/spf13/cobra" 30 | ) 31 | 32 | var workflowID string 33 | 34 | var detailBaselineWorkflowCmd = &cobra.Command{ 35 | Use: "details", 36 | Short: "Retrieve a specific axiom workflow", 37 | Long: `Retrieve details for a specific axiom workflow by identifier, scoped to the authorized API token`, 38 | Run: fetchWorkflowDetails, 39 | } 40 | 41 | func fetchWorkflowDetails(cmd *cobra.Command, args []string) { 42 | generalPrompt(cmd, args, promptStepDetails) 43 | } 44 | 45 | func fetchWorkflowDetailsRun(cmd *cobra.Command, args []string) { 46 | if err := common.RequireOrganization(); err != nil { 47 | fmt.Printf("failed to retrive workflow details; %s", err.Error()) 48 | os.Exit(1) 49 | } 50 | 51 | if err := common.RequireWorkgroup(); err != nil { 52 | fmt.Printf("failed to retrive workflow details; %s", err.Error()) 53 | os.Exit(1) 54 | } 55 | 56 | token, err := common.ResolveOrganizationToken() 57 | if err != nil { 58 | log.Printf("failed to retrieve workflow details; %s", err.Error()) 59 | os.Exit(1) 60 | } 61 | 62 | if workflowID == "" { 63 | workflowPrompt(*token.AccessToken) 64 | } 65 | 66 | w, err := axiom.GetWorkflowDetails(*token.AccessToken, workflowID, map[string]interface{}{}) 67 | if err != nil { 68 | log.Printf("failed to retrieve workflow details; %s", err.Error()) 69 | os.Exit(1) 70 | } 71 | 72 | result, _ := json.MarshalIndent(w, "", "\t") 73 | fmt.Printf("%s\n", string(result)) 74 | } 75 | 76 | func workflowPrompt(token string) { 77 | workflows, err := axiom.ListWorkflows(token, map[string]interface{}{ 78 | "workgroup_id": common.WorkgroupID, 79 | }) 80 | if err != nil { 81 | fmt.Printf("failed to retrieve workflow details; %s", err.Error()) 82 | os.Exit(1) 83 | } 84 | 85 | if len(workflows) == 0 { 86 | fmt.Print("No workflows found\n") 87 | os.Exit(1) 88 | } 89 | 90 | opts := make([]string, 0) 91 | 92 | for _, workflow := range workflows { 93 | opts = append(opts, *workflow.Name) 94 | } 95 | 96 | prompt := promptui.Select{ 97 | Label: "Select Workflow", 98 | Items: opts, 99 | } 100 | 101 | i, _, err := prompt.Run() 102 | if err != nil { 103 | fmt.Printf("failed to retrieve workflow details; %s", err.Error()) 104 | os.Exit(1) 105 | } 106 | 107 | workflowID = workflows[i].ID.String() 108 | } 109 | 110 | func init() { 111 | detailBaselineWorkflowCmd.Flags().StringVar(&common.OrganizationID, "organization", "", "organization identifier") 112 | detailBaselineWorkflowCmd.Flags().StringVar(&common.WorkgroupID, "workgroup", "", "workgroup identifier") 113 | detailBaselineWorkflowCmd.Flags().StringVar(&workflowID, "workflow", "", "workflow identifier") 114 | } 115 | -------------------------------------------------------------------------------- /prvd/axiom/workflows/workflows_list.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package workflows 18 | 19 | import ( 20 | "encoding/json" 21 | "fmt" 22 | "os" 23 | 24 | "github.com/manifoldco/promptui" 25 | "github.com/provideplatform/provide-cli/prvd/common" 26 | "github.com/provideplatform/provide-go/api/axiom" 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | var filterPrototypes bool 31 | var filterInstances bool 32 | 33 | var page uint64 34 | var rpp uint64 35 | 36 | var listBaselineWorkflowsCmd = &cobra.Command{ 37 | Use: "list", 38 | Short: "List axiom workflows", 39 | Long: `List all available axiom workflows`, 40 | Run: listWorkflows, 41 | } 42 | 43 | func listWorkflows(cmd *cobra.Command, args []string) { 44 | generalPrompt(cmd, args, promptStepList) 45 | } 46 | 47 | func listWorkflowsRun(cmd *cobra.Command, args []string) { 48 | if common.OrganizationID == "" { 49 | common.RequireOrganization() 50 | } 51 | if common.WorkgroupID == "" { 52 | common.RequireWorkgroup() 53 | } 54 | if !filterInstances { 55 | prompt := promptui.Prompt{ 56 | IsConfirm: true, 57 | Label: "Filter Instances", 58 | } 59 | 60 | if _, err := prompt.Run(); err == nil { 61 | filterInstances = true 62 | } 63 | } 64 | if !filterPrototypes { 65 | prompt := promptui.Prompt{ 66 | IsConfirm: true, 67 | Label: "Filter Prototypes", 68 | } 69 | 70 | if _, err := prompt.Run(); err == nil { 71 | filterPrototypes = true 72 | } 73 | } 74 | 75 | common.AuthorizeOrganizationContext(true) 76 | 77 | token, err := common.ResolveOrganizationToken() 78 | if err != nil { 79 | fmt.Printf("failed to list workflows; %s", err.Error()) 80 | os.Exit(1) 81 | } 82 | 83 | params := map[string]interface{}{ 84 | "workgroup_id": common.WorkgroupID, 85 | } 86 | 87 | if filterInstances { 88 | params["filter_instances"] = "true" 89 | } 90 | 91 | if filterPrototypes { 92 | params["filter_prototypes"] = "true" 93 | } 94 | 95 | workflows, err := axiom.ListWorkflows(*token.AccessToken, params) 96 | if err != nil { 97 | fmt.Printf("failed to list workflows; %s", err.Error()) 98 | os.Exit(1) 99 | } 100 | 101 | if len(workflows) == 0 { 102 | fmt.Print("No workflows found\n") 103 | return 104 | } 105 | 106 | for _, workflow := range workflows { 107 | result, _ := json.MarshalIndent(workflow, "", "\t") 108 | fmt.Printf("%s\n", string(result)) 109 | } 110 | } 111 | 112 | func init() { 113 | listBaselineWorkflowsCmd.Flags().StringVar(&common.OrganizationID, "organization", "", "organization identifier") 114 | listBaselineWorkflowsCmd.Flags().StringVar(&common.WorkgroupID, "workgroup", "", "workgroup identifier") 115 | 116 | listBaselineWorkflowsCmd.Flags().BoolVar(&filterInstances, "filter-instances", false, "filter workflow prototypes") 117 | listBaselineWorkflowsCmd.Flags().BoolVar(&filterPrototypes, "filter-prototypes", false, "filter workflow instances") 118 | 119 | listBaselineWorkflowsCmd.Flags().Uint64Var(&page, "page", common.DefaultPage, "page number to retrieve") 120 | listBaselineWorkflowsCmd.Flags().Uint64Var(&rpp, "rpp", common.DefaultRpp, "number of axiom workgroups to retrieve per page") 121 | listBaselineWorkflowsCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 122 | } 123 | -------------------------------------------------------------------------------- /prvd/axiom/workflows/workflows_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package workflows 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/axiom/workflows/messages" 21 | "github.com/provideplatform/provide-cli/prvd/axiom/workflows/worksteps" 22 | "github.com/provideplatform/provide-cli/prvd/common" 23 | 24 | "github.com/spf13/cobra" 25 | ) 26 | 27 | const promptStepInit = "Initialize" 28 | const promptStepList = "List" 29 | const promptStepDetails = "Details" 30 | const promptStepDeploy = "Deploy" 31 | const promptStepVersion = "Version" 32 | 33 | const promptStepWorksteps = "Worksteps" 34 | const promptStepMessages = "Messages" 35 | 36 | var emptyPromptArgs = []string{promptStepInit, promptStepList, promptStepDetails, promptStepMessages} 37 | var emptyPromptLabel = "What would you like to do" 38 | 39 | // General Endpoints 40 | func generalPrompt(cmd *cobra.Command, args []string, step string) { 41 | switch step { 42 | case promptStepInit: 43 | initWorkflowRun(cmd, args) 44 | case promptStepList: 45 | listWorkflowsRun(cmd, args) 46 | case promptStepDetails: 47 | fetchWorkflowDetailsRun(cmd, args) 48 | case promptStepDeploy: 49 | deployWorkflowRun(cmd, args) 50 | case promptStepVersion: 51 | versionWorkflowRun(cmd, args) 52 | case promptStepWorksteps: 53 | worksteps.WorkstepsCmd.Run(cmd, args) 54 | case promptStepMessages: 55 | messages.Optional = Optional 56 | messages.MessagesCmd.Run(cmd, args) 57 | case "": 58 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 59 | generalPrompt(cmd, args, result) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /prvd/axiom/workflows/worksteps/worksteps.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package worksteps 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var paginate bool 25 | 26 | var WorkstepsCmd = &cobra.Command{ 27 | Use: "worksteps", 28 | Short: "Interact with a axiom worksteps", 29 | Long: `Create, manage and interact with workflow worksteps via the axiom protocol.`, 30 | Run: func(cmd *cobra.Command, args []string) { 31 | common.CmdExistsOrExit(cmd, args) 32 | 33 | generalPrompt(cmd, args, "") 34 | }, 35 | } 36 | 37 | func init() { 38 | WorkstepsCmd.AddCommand(listBaselineWorkstepsCmd) 39 | // WorkstepsCmd.AddCommand(detailBaselineWorkstepCmd) 40 | WorkstepsCmd.AddCommand(initBaselineWorkstepCmd) 41 | WorkstepsCmd.Flags().BoolVarP(&Optional, "optional", "", false, "List all the Optional flags") 42 | 43 | } 44 | -------------------------------------------------------------------------------- /prvd/axiom/workflows/worksteps/worksteps_list.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package worksteps 18 | 19 | import ( 20 | "encoding/json" 21 | "fmt" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | "github.com/provideplatform/provide-go/api/axiom" 26 | "github.com/spf13/cobra" 27 | ) 28 | 29 | var page uint64 30 | var rpp uint64 31 | 32 | var listBaselineWorkstepsCmd = &cobra.Command{ 33 | Use: "list", 34 | Short: "List axiom worksteps", 35 | Long: `List all available axiom workflow worksteps`, 36 | Run: listWorksteps, 37 | } 38 | 39 | func listWorksteps(cmd *cobra.Command, args []string) { 40 | generalPrompt(cmd, args, promptStepList) 41 | } 42 | 43 | func listWorkstepsRun(cmd *cobra.Command, args []string) { 44 | if common.OrganizationID == "" { 45 | common.RequireOrganization() 46 | } 47 | if common.WorkgroupID == "" { 48 | common.RequireWorkgroup() 49 | } 50 | 51 | token, err := common.ResolveOrganizationToken() 52 | if err != nil { 53 | fmt.Printf("failed to list worksteps; %s", err.Error()) 54 | os.Exit(1) 55 | } 56 | 57 | if workflowID == "" { 58 | workflowPrompt(*token.AccessToken) 59 | } 60 | 61 | worksteps, err := axiom.ListWorksteps(*token.AccessToken, workflowID, map[string]interface{}{}) 62 | if err != nil { 63 | fmt.Printf("failed to list worksteps; %s", err.Error()) 64 | os.Exit(1) 65 | } 66 | 67 | if len(worksteps) == 0 { 68 | fmt.Print("No worksteps found\n") 69 | return 70 | } 71 | 72 | for _, workstep := range worksteps { 73 | result, _ := json.MarshalIndent(workstep, "", "\t") 74 | fmt.Printf("%s\n", string(result)) 75 | } 76 | } 77 | 78 | func init() { 79 | listBaselineWorkstepsCmd.Flags().StringVar(&common.OrganizationID, "organization", "", "organization identifier") 80 | listBaselineWorkstepsCmd.Flags().StringVar(&common.WorkgroupID, "workgroup", "", "workgroup identifier") 81 | listBaselineWorkstepsCmd.Flags().StringVar(&workflowID, "workflow", "", "workflow identifier") 82 | 83 | listBaselineWorkstepsCmd.Flags().Uint64Var(&page, "page", common.DefaultPage, "page number to retrieve") 84 | listBaselineWorkstepsCmd.Flags().Uint64Var(&rpp, "rpp", common.DefaultRpp, "number of axiom workgroups to retrieve per page") 85 | listBaselineWorkstepsCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 86 | } 87 | -------------------------------------------------------------------------------- /prvd/axiom/workflows/worksteps/worksteps_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package worksteps 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | 22 | "github.com/spf13/cobra" 23 | ) 24 | 25 | const promptStepInit = "Initialize" 26 | const promptStepList = "List" 27 | const promptStepDetails = "Details" 28 | 29 | var emptyPromptArgs = []string{promptStepInit, promptStepList, promptStepDetails} 30 | var emptyPromptLabel = "What would you like to do" 31 | 32 | // General Endpoints 33 | func generalPrompt(cmd *cobra.Command, args []string, step string) { 34 | switch step { 35 | case promptStepInit: 36 | initWorkstepRun(cmd, args) 37 | case promptStepList: 38 | listWorkstepsRun(cmd, args) 39 | // case promptStepDetails: 40 | // fetchWorkstepDetailsRun(cmd, args) 41 | case "": 42 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 43 | generalPrompt(cmd, args, result) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /prvd/axiom/workgroups/workgroups.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package workgroups 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/axiom/participants" 21 | "github.com/provideplatform/provide-cli/prvd/axiom/systems" 22 | "github.com/provideplatform/provide-cli/prvd/common" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | var WorkgroupsCmd = &cobra.Command{ 27 | Use: "workgroups", 28 | Short: "Interact with axiom workgroups", 29 | Long: `Create, manage and interact with workgroups via the axiom protocol.`, 30 | Run: func(cmd *cobra.Command, args []string) { 31 | common.CmdExistsOrExit(cmd, args) 32 | 33 | generalPrompt(cmd, args, "") 34 | }, 35 | } 36 | 37 | func init() { 38 | WorkgroupsCmd.AddCommand(listBaselineWorkgroupsCmd) 39 | WorkgroupsCmd.AddCommand(detailBaselineWorkgroupCmd) 40 | WorkgroupsCmd.AddCommand(initBaselineWorkgroupCmd) 41 | WorkgroupsCmd.AddCommand(updateBaselineWorkgroupCmd) 42 | WorkgroupsCmd.AddCommand(joinBaselineWorkgroupCmd) 43 | WorkgroupsCmd.AddCommand(participants.ParticipantsCmd) 44 | WorkgroupsCmd.AddCommand(systems.SystemsCmd) 45 | 46 | WorkgroupsCmd.Flags().BoolVarP(&Optional, "optional", "", false, "List all the Optional flags") 47 | WorkgroupsCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 48 | } 49 | -------------------------------------------------------------------------------- /prvd/axiom/workgroups/workgroups_details.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package workgroups 18 | 19 | import ( 20 | "encoding/json" 21 | "fmt" 22 | "log" 23 | "os" 24 | 25 | "github.com/provideplatform/provide-cli/prvd/common" 26 | "github.com/provideplatform/provide-go/api/axiom" 27 | 28 | "github.com/spf13/cobra" 29 | ) 30 | 31 | var detailBaselineWorkgroupCmd = &cobra.Command{ 32 | Use: "details", 33 | Short: "Retrieve a specific axiom workgroup", 34 | Long: `Retrieve details for a specific axiom workgroup by identifier, scoped to the authorized API token`, 35 | Run: fetchWorkgroupDetails, 36 | } 37 | 38 | func fetchWorkgroupDetails(cmd *cobra.Command, args []string) { 39 | generalPrompt(cmd, args, promptStepDetails) 40 | } 41 | 42 | func fetchWorkgroupDetailsRun(cmd *cobra.Command, args []string) { 43 | if common.OrganizationID == "" { 44 | common.RequireOrganization() 45 | } 46 | 47 | if common.WorkgroupID == "" { 48 | common.RequireWorkgroup() 49 | } 50 | 51 | common.AuthorizeOrganizationContext(true) 52 | 53 | token, err := common.ResolveOrganizationToken() 54 | if err != nil { 55 | log.Printf("Failed to retrieve details for workgroup with id: %s; %s", common.WorkgroupID, err.Error()) 56 | os.Exit(1) 57 | } 58 | 59 | wg, err := axiom.GetWorkgroupDetails(*token.AccessToken, common.WorkgroupID, map[string]interface{}{}) 60 | if err != nil { 61 | log.Printf("Failed to retrieve details for workgroup with id: %s; %s", common.WorkgroupID, err.Error()) 62 | os.Exit(1) 63 | } 64 | 65 | result, _ := json.MarshalIndent(wg, "", "\t") 66 | fmt.Printf("%s\n", string(result)) 67 | } 68 | 69 | func init() { 70 | detailBaselineWorkgroupCmd.Flags().StringVar(&common.OrganizationID, "organization", "", "organization identifier") 71 | detailBaselineWorkgroupCmd.Flags().StringVar(&common.WorkgroupID, "workgroup", "", "workgroup identifier") 72 | } 73 | -------------------------------------------------------------------------------- /prvd/axiom/workgroups/workgroups_list.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package workgroups 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | "github.com/provideplatform/provide-go/api/axiom" 26 | "github.com/spf13/cobra" 27 | ) 28 | 29 | var page uint64 30 | var rpp uint64 31 | 32 | var listBaselineWorkgroupsCmd = &cobra.Command{ 33 | Use: "list", 34 | Short: "List axiom workgroups", 35 | Long: `List all available axiom workgroups`, 36 | Run: listWorkgroups, 37 | } 38 | 39 | func listWorkgroups(cmd *cobra.Command, args []string) { 40 | generalPrompt(cmd, args, promptStepList) 41 | } 42 | 43 | func listWorkgroupsRun(cmd *cobra.Command, args []string) { 44 | token, err := common.ResolveOrganizationToken() 45 | if err != nil { 46 | log.Printf("failed to retrieve axiom workgroups; %s", err.Error()) 47 | os.Exit(1) 48 | } 49 | 50 | workgroups, err := axiom.ListWorkgroups(*token.AccessToken, map[string]interface{}{ 51 | "page": fmt.Sprintf("%d", page), 52 | "rpp": fmt.Sprintf("%d", rpp), 53 | }) 54 | if err != nil { 55 | log.Printf("failed to retrieve axiom workgroups; %s", err.Error()) 56 | os.Exit(1) 57 | } 58 | for _, workgroup := range workgroups { 59 | result := fmt.Sprintf("%s\t%s\n", workgroup.ID, *workgroup.Name) 60 | fmt.Print(result) 61 | } 62 | } 63 | 64 | func init() { 65 | listBaselineWorkgroupsCmd.Flags().StringVar(&common.OrganizationID, "organization", "", "organization identifier") 66 | 67 | listBaselineWorkgroupsCmd.Flags().Uint64Var(&page, "page", common.DefaultPage, "page number to retrieve") 68 | listBaselineWorkgroupsCmd.Flags().Uint64Var(&rpp, "rpp", common.DefaultRpp, "number of axiom workgroups to retrieve per page") 69 | listBaselineWorkgroupsCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 70 | } 71 | -------------------------------------------------------------------------------- /prvd/axiom/workgroups/workgroups_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package workgroups 18 | 19 | import ( 20 | "fmt" 21 | 22 | "github.com/provideplatform/provide-cli/prvd/common" 23 | 24 | "github.com/spf13/cobra" 25 | ) 26 | 27 | const promptStepList = "List" 28 | const promptStepDetails = "Details" 29 | const promptStepInit = "Initialize" 30 | const promptStepUpdate = "Update" 31 | const promptStepJoin = "Join" 32 | 33 | var emptyPromptArgs = []string{promptStepInit, promptStepList, promptStepJoin} 34 | var emptyPromptLabel = "What would you like to do" 35 | 36 | // General Endpoints 37 | func generalPrompt(cmd *cobra.Command, args []string, step string) { 38 | switch step { 39 | case promptStepList: 40 | page, rpp = common.PromptPagination(paginate, page, rpp) 41 | listWorkgroupsRun(cmd, args) 42 | case promptStepDetails: 43 | fetchWorkgroupDetailsRun(cmd, args) 44 | case promptStepInit: 45 | if Optional { 46 | fmt.Println("Optional Flags:") 47 | if common.NetworkID == "" { 48 | common.RequireL1Network() 49 | } 50 | if common.OrganizationID == "" { 51 | common.RequireOrganization() 52 | } 53 | if common.MessagingEndpoint == "" { 54 | common.MessagingEndpoint = common.FreeInput("Messaging Endpoint", "", common.NoValidation) 55 | } 56 | if name == "" { 57 | name = common.FreeInput("Name", "", common.NoValidation) 58 | } 59 | } 60 | initWorkgroupRun(cmd, args) 61 | case promptStepUpdate: 62 | updateWorkgroupRun(cmd, args) 63 | case promptStepJoin: 64 | if Optional { 65 | fmt.Println("Optional Flags:") 66 | if common.OrganizationID == "" { 67 | common.RequireOrganization() 68 | } 69 | if inviteJWT == "" { 70 | inviteJWT = common.FreeInput("JWT Invite", "", common.NoValidation) 71 | } 72 | } 73 | joinWorkgroupRun(cmd, args) 74 | case "": 75 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 76 | generalPrompt(cmd, args, result) 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /prvd/common/structs.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package common 18 | 19 | import ( 20 | "time" 21 | 22 | uuid "github.com/kthomas/go.uuid" 23 | 24 | "github.com/provideplatform/provide-go/api/axiom" 25 | "github.com/provideplatform/provide-go/api/ident" 26 | ) 27 | 28 | // Workgroup is a axiom workgroup context; called WorkgroupType because Workgroup is already declared in common 29 | type WorkgroupType struct { 30 | axiom.Workgroup 31 | Config *WorkgroupConfig `json:"config"` 32 | } 33 | 34 | // WorkgroupConfig is a axiom workgroup configuration object 35 | type WorkgroupConfig struct { 36 | Environment *string `json:"environment"` 37 | L2NetworkID *uuid.UUID `json:"l2_network_id"` 38 | L3NetworkID *uuid.UUID `json:"l3_network_id"` 39 | OnboardingComplete bool `json:"onboarding_complete"` 40 | SystemSecretIDs []*uuid.UUID `json:"system_secret_ids"` 41 | VaultID *uuid.UUID `json:"vault_id"` 42 | WebhookSecret *string `json:"webhook_secret"` 43 | } 44 | 45 | // Organization model; called OrganizationType because Organization is already declared in common 46 | type OrganizationType struct { 47 | ident.Organization 48 | Metadata *OrganizationMetadata `json:"metadata"` 49 | } 50 | 51 | // Organization metadata 52 | type OrganizationMetadata struct { 53 | Address string `json:"address"` 54 | BPIEndpoint string `json:"bpi_endpoint"` 55 | Domain string `json:"domain"` 56 | MessagingEndpoint string `json:"messaging_endpoint"` 57 | Workgroups map[uuid.UUID]*OrganizationWorkgroupMetadata `json:"workgroups"` 58 | } 59 | 60 | // Organization workgroup metadata 61 | type OrganizationWorkgroupMetadata struct { 62 | BPIEndpoint *string `json:"bpi_endpoint"` 63 | MessagingEndpoint *string `json:"messaging_endpoint"` 64 | OperatorSeparationDegree uint32 `json:"operator_separation_degree"` 65 | Privacy *WorkgroupMetadataLegal `json:"privacy,omitempty"` 66 | SystemSecretIDs []*uuid.UUID `json:"system_secret_ids"` 67 | TOS *WorkgroupMetadataLegal `json:"tos,omitempty"` 68 | VaultID *uuid.UUID `json:"vault_id"` 69 | } 70 | 71 | // Organization workgroup metadata legal data 72 | type WorkgroupMetadataLegal struct { 73 | AgreedAt *time.Time `json:"agreed_at"` 74 | Signature *string `json:"signature"` 75 | } 76 | -------------------------------------------------------------------------------- /prvd/connectors/connectors.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package connectors 18 | 19 | import ( 20 | "os" 21 | 22 | "github.com/provideplatform/provide-cli/prvd/common" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | const connectorTypeIPFS = "ipfs" 27 | 28 | var connector map[string]interface{} 29 | var connectors []interface{} 30 | 31 | var ConnectorsCmd = &cobra.Command{ 32 | Use: "connectors", 33 | Short: "Manage arbitrary external infrastructure", 34 | Long: `Connectors are adapters that connect external arbitrary infrastructure with Provide. 35 | 36 | This API allows you to provision load balanced, cloud-agnostic infrastructure for your distributed system.`, 37 | Run: func(cmd *cobra.Command, args []string) { 38 | common.CmdExistsOrExit(cmd, args) 39 | 40 | generalPrompt(cmd, args, "") 41 | 42 | defer func() { 43 | if r := recover(); r != nil { 44 | os.Exit(1) 45 | } 46 | }() 47 | }, 48 | } 49 | 50 | func init() { 51 | ConnectorsCmd.AddCommand(connectorsListCmd) 52 | ConnectorsCmd.AddCommand(connectorsInitCmd) 53 | ConnectorsCmd.AddCommand(connectorsDetailsCmd) 54 | ConnectorsCmd.AddCommand(connectorsDeleteCmd) 55 | ConnectorsCmd.Flags().BoolVarP(&optional, "optional", "", false, "List all the optional flags") 56 | ConnectorsCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 57 | } 58 | -------------------------------------------------------------------------------- /prvd/connectors/connectors_delete.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package connectors 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | provide "github.com/provideplatform/provide-go/api/nchain" 26 | 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | var connectorsDeleteCmd = &cobra.Command{ 31 | Use: "delete", 32 | Short: "Delete a specific connector", 33 | Long: `Delete a specific connector by identifier and teardown any associated infrastructure`, 34 | Run: deleteConnector, 35 | } 36 | 37 | func deleteConnector(cmd *cobra.Command, args []string) { 38 | token := common.RequireAPIToken() 39 | err := provide.DeleteConnector(token, common.ConnectorID) 40 | if err != nil { 41 | log.Printf("Failed to delete connector with id: %s; %s", common.ConnectorID, err.Error()) 42 | os.Exit(1) 43 | } 44 | // if status != 204 { 45 | // log.Printf("Failed to delete connector with id: %s; received status: %d", common.ConnectorID, status) 46 | // os.Exit(1) 47 | // } 48 | fmt.Printf("Deleted connector with id: %s", common.ConnectorID) 49 | } 50 | 51 | func init() { 52 | connectorsDeleteCmd.Flags().StringVar(&common.ConnectorID, "connector", "", "id of the connector") 53 | // connectorsDeleteCmd.MarkFlagRequired("connector") 54 | 55 | connectorsDeleteCmd.Flags().StringVar(&common.ApplicationID, "application", "", "application id") 56 | // connectorsDeleteCmd.MarkFlagRequired("application") 57 | } 58 | -------------------------------------------------------------------------------- /prvd/connectors/connectors_details.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package connectors 18 | 19 | import ( 20 | "encoding/json" 21 | "fmt" 22 | "log" 23 | "os" 24 | 25 | "github.com/provideplatform/provide-cli/prvd/common" 26 | provide "github.com/provideplatform/provide-go/api/nchain" 27 | 28 | "github.com/spf13/cobra" 29 | ) 30 | 31 | var connectorsDetailsCmd = &cobra.Command{ 32 | Use: "details", 33 | Short: "Retrieve details for a specific connector", 34 | Long: `Retrieve details for a specific connector by identifier, scoped to the authorized API token`, 35 | Run: fetchConnectorDetails, 36 | } 37 | 38 | func fetchConnectorDetails(cmd *cobra.Command, args []string) { 39 | token := common.RequireAPIToken() 40 | params := map[string]interface{}{} 41 | connector, err := provide.GetConnectorDetails(token, common.ConnectorID, params) 42 | if err != nil { 43 | log.Printf("Failed to retrieve details for connector with id: %s; %s", common.ConnectorID, err.Error()) 44 | os.Exit(1) 45 | } 46 | // if status != 200 { 47 | // log.Printf("Failed to retrieve details for connector with id: %s; received status: %d", common.ConnectorID, status) 48 | // os.Exit(1) 49 | // } 50 | var config map[string]interface{} 51 | json.Unmarshal(*connector.Config, &config) 52 | result := fmt.Sprintf("%s\t%s\t%s", connector.ID.String(), *connector.Name, *connector.Type) 53 | if *connector.Type == connectorTypeIPFS { 54 | result = fmt.Sprintf("%s\t%s", result, config["api_url"]) 55 | } 56 | fmt.Printf("%s\n", result) 57 | } 58 | 59 | func init() { 60 | connectorsDetailsCmd.Flags().StringVar(&common.ConnectorID, "connector", "", "id of the connector") 61 | // connectorsDetailsCmd.MarkFlagRequired("connector") 62 | } 63 | -------------------------------------------------------------------------------- /prvd/connectors/connectors_list.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package connectors 18 | 19 | import ( 20 | "encoding/json" 21 | "fmt" 22 | "log" 23 | "os" 24 | 25 | "github.com/provideplatform/provide-cli/prvd/common" 26 | provide "github.com/provideplatform/provide-go/api/nchain" 27 | 28 | "github.com/spf13/cobra" 29 | ) 30 | 31 | var page uint64 32 | var rpp uint64 33 | 34 | var connectorsListCmd = &cobra.Command{ 35 | Use: "list", 36 | Short: "Retrieve a list of connectors", 37 | Long: `Retrieve a list of connectors scoped to the authorized API token`, 38 | Run: listConnectors, 39 | } 40 | 41 | func listConnectors(cmd *cobra.Command, args []string) { 42 | token := common.RequireAPIToken() 43 | params := map[string]interface{}{ 44 | "page": fmt.Sprintf("%d", page), 45 | "rpp": fmt.Sprintf("%d", rpp), 46 | } 47 | if common.ApplicationID != "" { 48 | params["application_id"] = common.ApplicationID 49 | } 50 | connectors, err := provide.ListConnectors(token, params) 51 | if err != nil { 52 | log.Printf("Failed to retrieve connectors list; %s", err.Error()) 53 | os.Exit(1) 54 | } 55 | // if status != 200 { 56 | // log.Printf("Failed to retrieve connectors list; received status: %d", status) 57 | // os.Exit(1) 58 | // } 59 | for i := range connectors { 60 | connector := connectors[i] 61 | var config map[string]interface{} 62 | json.Unmarshal(*connector.Config, &config) 63 | result := fmt.Sprintf("%s\t%s\t%s", connector.ID.String(), *connector.Name, *connector.Type) 64 | if *connector.Type == connectorTypeIPFS { 65 | result = fmt.Sprintf("%s\t%s", result, config["api_url"]) 66 | } 67 | fmt.Printf("%s\n", result) 68 | } 69 | } 70 | 71 | func init() { 72 | connectorsListCmd.Flags().StringVar(&common.ApplicationID, "application", "", "application identifier to filter connectors") 73 | connectorsListCmd.Flags().BoolVarP(&optional, "optional", "", false, "List all the optional flags") 74 | connectorsListCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 75 | connectorsListCmd.Flags().Uint64Var(&page, "page", common.DefaultPage, "page number to retrieve") 76 | connectorsListCmd.Flags().Uint64Var(&rpp, "rpp", common.DefaultRpp, "number of connectors to retrieve per page") 77 | } 78 | -------------------------------------------------------------------------------- /prvd/connectors/connectors_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package connectors 18 | 19 | import ( 20 | "strconv" 21 | 22 | "github.com/provideplatform/provide-cli/prvd/common" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | const promptStepInit = "Init" 27 | const promptStepList = "List" 28 | const promptStepDetails = "Details" 29 | const promptStepDelete = "Delete" 30 | 31 | var emptyPromptArgs = []string{promptStepInit, promptStepList, promptStepDetails, promptStepDelete} 32 | var emptyPromptLabel = "What would you like to do" 33 | 34 | // General Endpoints 35 | func generalPrompt(cmd *cobra.Command, args []string, currentStep string) { 36 | switch step := currentStep; step { 37 | case promptStepInit: 38 | if connectorName == "" { 39 | connectorName = common.FreeInput("Connector Name", "", common.MandatoryValidation) 40 | } 41 | if connectorType == "" { 42 | connectorType = common.FreeInput("Connector Type", "", common.MandatoryValidation) 43 | } 44 | if common.ApplicationID == "" { 45 | common.RequireApplication() 46 | } 47 | if common.NetworkID == "" { 48 | common.RequireL1Network() 49 | } 50 | if optional { 51 | if ipfsAPIPort == 5001 { 52 | result := common.FreeInput("IPFS API Port", "5001", common.NumberValidation) 53 | ipfsAPIPort, _ = strconv.ParseUint(result, 10, 64) 54 | } 55 | if ipfsGatewayPort == 8080 { 56 | result := common.FreeInput("IPFS Gateway Port", "8080", common.NumberValidation) 57 | ipfsGatewayPort, _ = strconv.ParseUint(result, 10, 64) 58 | } 59 | } 60 | createConnector(cmd, args) 61 | case promptStepList: 62 | if optional { 63 | common.RequireApplication() 64 | } 65 | page, rpp = common.PromptPagination(paginate, page, rpp) 66 | listConnectors(cmd, args) 67 | case promptStepDetails: 68 | common.RequireConnector(map[string]interface{}{}) 69 | fetchConnectorDetails(cmd, args) 70 | case promptStepDelete: 71 | if common.ConnectorID == "" { 72 | common.RequireConnector(map[string]interface{}{}) 73 | } 74 | if common.ApplicationID == "" { 75 | common.RequireApplication() 76 | } 77 | deleteConnector(cmd, args) 78 | case "": 79 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 80 | generalPrompt(cmd, args, result) 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /prvd/contracts/contract_details.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package contracts 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | provide "github.com/provideplatform/provide-go/api/nchain" 26 | 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | var contractsDetailsCmd = &cobra.Command{ 31 | Use: "details", 32 | Short: "Retrieve a specific smart contract", 33 | Long: `Retrieve details for a specific smart contract by identifier, scoped to the authorized API token`, 34 | Run: fetchContractDetails, 35 | } 36 | 37 | func fetchContractDetails(cmd *cobra.Command, args []string) { 38 | token := common.RequireAPIToken() 39 | params := map[string]interface{}{} 40 | contract, err := provide.GetContractDetails(token, common.ContractID, params) 41 | if err != nil { 42 | log.Printf("Failed to retrieve details for contract with id: %s; %s", common.ContractID, err.Error()) 43 | os.Exit(1) 44 | } 45 | // if status != 200 { 46 | // log.Printf("Failed to retrieve details for contract with id: %s; %s", common.ContractID, resp) 47 | // os.Exit(1) 48 | // } 49 | result := fmt.Sprintf("%s\t%s\n", contract.ID.String(), *contract.Name) 50 | fmt.Print(result) 51 | } 52 | 53 | func init() { 54 | contractsDetailsCmd.Flags().StringVar(&common.ContractID, "contract", "", "id of the contract") 55 | contractsDetailsCmd.MarkFlagRequired("contract") 56 | } 57 | -------------------------------------------------------------------------------- /prvd/contracts/contracts.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package contracts 18 | 19 | import ( 20 | "os" 21 | 22 | "github.com/provideplatform/provide-cli/prvd/common" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | const contractTypeRegistry = "registry" 27 | 28 | var contract map[string]interface{} 29 | var contracts []interface{} 30 | var contractType string 31 | 32 | var ContractsCmd = &cobra.Command{ 33 | Use: "contracts", 34 | Short: "Manage smart contracts", 35 | Long: `Compile and deploy smart contracts locally from source or execute previously-deployed contracts`, 36 | Run: func(cmd *cobra.Command, args []string) { 37 | common.CmdExistsOrExit(cmd, args) 38 | 39 | generalPrompt(cmd, args, "") 40 | 41 | defer func() { 42 | if r := recover(); r != nil { 43 | os.Exit(1) 44 | } 45 | }() 46 | }, 47 | } 48 | 49 | func init() { 50 | ContractsCmd.AddCommand(contractsListCmd) 51 | ContractsCmd.AddCommand(contractsExecuteCmd) 52 | ContractsCmd.Flags().BoolVarP(&optional, "optional", "", false, "List all the optional flags") 53 | ContractsCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 54 | } 55 | -------------------------------------------------------------------------------- /prvd/contracts/contracts_execute.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package contracts 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | "strings" 24 | 25 | "github.com/provideplatform/provide-cli/prvd/common" 26 | provide "github.com/provideplatform/provide-go/api/nchain" 27 | 28 | "github.com/spf13/cobra" 29 | ) 30 | 31 | var contractExecMethod string 32 | var contractExecValue uint64 33 | var contractExecParams []interface{} 34 | var optional bool 35 | var paginate bool 36 | 37 | var contractsExecuteCmd = &cobra.Command{ 38 | Use: "execute --contract 0x5E250bB077ec836915155229E83d187715266167 --method vote --argv [] --value 0 --wallet 0x8A70B0C7E9896ac7025279a2Da240aEBD17A0cA3", 39 | Short: "Execute a smart contract", 40 | Long: `Execute a smart contract method on a specific specific contract`, 41 | Run: executeContract, 42 | } 43 | 44 | func executeContract(cmd *cobra.Command, args []string) { 45 | if common.AccountID == "" && common.WalletID == "" { 46 | fmt.Println("Cannot execute a contract without a specified signer.") 47 | os.Exit(1) 48 | } 49 | token := common.RequireAPIToken() 50 | params := map[string]interface{}{ 51 | "method": contractExecMethod, 52 | "params": contractExecParams, 53 | "value": contractExecValue, 54 | } 55 | if common.AccountID != "" { 56 | if strings.HasPrefix(common.AccountID, "0x") { 57 | params["account_address"] = common.AccountID 58 | } else { 59 | params["account_id"] = common.AccountID 60 | } 61 | } 62 | if common.WalletID != "" { 63 | params["wallet_id"] = common.WalletID 64 | } 65 | resp, err := provide.ExecuteContract(token, common.ContractID, params) 66 | if err != nil { 67 | log.Printf("Failed to execute contract with id: %s; %s", common.ContractID, err.Error()) 68 | os.Exit(1) 69 | } 70 | 71 | fmt.Printf("Successfully executed tx for asynchronous contract execution; tx ref: %s", *resp.Reference) 72 | 73 | // if status == 200 { 74 | // execution := resp.(map[string]interface{}) 75 | // executionJSON, _ := json.Marshal(execution) 76 | // fmt.Printf("Successfully executed contract; response: %s", string(executionJSON)) 77 | // } else if status == 202 { 78 | // execution := resp.(map[string]interface{}) 79 | // txRef := execution["ref"].(string) 80 | // fmt.Printf("Successfully queued tx for asynchronous contract execution; tx ref: %s", txRef) 81 | // } else if status >= 400 { 82 | // fmt.Printf("Failed to execute contract; %d response: %s", status, resp) 83 | // } 84 | } 85 | 86 | func init() { 87 | contractsExecuteCmd.Flags().StringVar(&common.ContractID, "contract", "", "target contract id") 88 | // contractsExecuteCmd.MarkFlagRequired("contract") 89 | 90 | contractsExecuteCmd.Flags().StringVar(&contractExecMethod, "method", "", "ABI method to invoke on the contract") 91 | // contractsExecuteCmd.MarkFlagRequired("method") 92 | 93 | contractsExecuteCmd.Flags().Uint64Var(&contractExecValue, "value", 0, "value to send with transaction, specific in the smallest denonination of currency for the network (i.e., wei)") 94 | 95 | contractsExecuteCmd.Flags().StringVar(&common.AccountID, "account", "", "signing account id with which to sign the tx") 96 | contractsExecuteCmd.Flags().StringVar(&common.WalletID, "wallet", "", "HD wallet id with which to sign the tx") 97 | contractsExecuteCmd.Flags().BoolVarP(&optional, "optional", "", false, "List all the optional flags") 98 | } 99 | -------------------------------------------------------------------------------- /prvd/contracts/contracts_init.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package contracts 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | provide "github.com/provideplatform/provide-go/api/nchain" 26 | 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | var contractName string 31 | var compiledArtifact map[string]interface{} 32 | 33 | var contractsInitCmd = &cobra.Command{ 34 | Use: "init --name 'Registry' --network 024ff1ef-7369-4dee-969c-1918c6edb5d4", 35 | Short: "Initialize a new smart contract", 36 | Long: `Initialize a new smart contract on behalf of a specific application; this operation may result in the contract being deployed`, 37 | Run: createContract, 38 | } 39 | 40 | func compiledArtifactFactory() map[string]interface{} { 41 | if compiledArtifact != nil { 42 | return compiledArtifact 43 | } 44 | 45 | // TODO: support cli and soljson compiler 46 | return map[string]interface{}{ 47 | "name": nil, 48 | "abi": nil, 49 | "assembly": nil, 50 | "bytecode": nil, 51 | "deps": nil, 52 | "opcodes": nil, 53 | "raw": nil, 54 | "source": nil, 55 | "fingerprint": nil, 56 | } 57 | } 58 | 59 | func contractParamsFactory() map[string]interface{} { 60 | params := map[string]interface{}{ 61 | "wallet_id": common.WalletID, 62 | "compiled_artifact": compiledArtifactFactory(), 63 | } 64 | if contractType != "" { 65 | params["type"] = contractType 66 | } 67 | return params 68 | } 69 | 70 | func createContract(cmd *cobra.Command, args []string) { 71 | if common.WalletID == "" { 72 | fmt.Println("Cannot create a contract without a specified signer.") 73 | os.Exit(1) 74 | } 75 | token := common.RequireAPIToken() 76 | params := map[string]interface{}{ 77 | "name": contractName, 78 | "network_id": common.NetworkID, 79 | "application_id": common.ApplicationID, 80 | "address": "0x", 81 | "params": contractParamsFactory(), 82 | } 83 | contract, err := provide.CreateContract(token, params) 84 | if err != nil { 85 | log.Printf("Failed to initialize application; %s", err.Error()) 86 | os.Exit(1) 87 | } 88 | common.ContractID = contract.ID.String() 89 | result := fmt.Sprintf("%s\t%s\n", contract.ID.String(), *contract.Name) 90 | fmt.Print(result) 91 | } 92 | 93 | func init() { 94 | contractsInitCmd.Flags().StringVar(&contractName, "name", "", "name of the contract") 95 | contractsInitCmd.MarkFlagRequired("name") 96 | 97 | contractsInitCmd.Flags().StringVar(&common.NetworkID, "network", "", "target network id") 98 | contractsInitCmd.MarkFlagRequired("network") 99 | 100 | contractsInitCmd.Flags().StringVar(&common.ApplicationID, "application", "", "target application id") 101 | contractsInitCmd.MarkFlagRequired("application") 102 | 103 | contractsInitCmd.Flags().StringVar(&common.WalletID, "wallet", "", "wallet id with which to sign the tx") 104 | contractsInitCmd.MarkFlagRequired("wallet") 105 | } 106 | -------------------------------------------------------------------------------- /prvd/contracts/contracts_list.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package contracts 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | provide "github.com/provideplatform/provide-go/api/nchain" 26 | 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | var page uint64 31 | var rpp uint64 32 | 33 | var contractsListCmd = &cobra.Command{ 34 | Use: "list", 35 | Short: "Retrieve a list of contracts", 36 | Long: `Retrieve a list of contracts scoped to the authorized API token`, 37 | Run: listContracts, 38 | } 39 | 40 | func listContracts(cmd *cobra.Command, args []string) { 41 | token := common.RequireAPIToken() 42 | params := map[string]interface{}{ 43 | "page": fmt.Sprintf("%d", page), 44 | "rpp": fmt.Sprintf("%d", rpp), 45 | } 46 | if common.ApplicationID != "" { 47 | params["application_id"] = common.ApplicationID 48 | } 49 | contracts, err := provide.ListContracts(token, params) 50 | if err != nil { 51 | log.Printf("Failed to retrieve contracts list; %s", err.Error()) 52 | os.Exit(1) 53 | } 54 | for i := range contracts { 55 | contract := contracts[i] 56 | result := fmt.Sprintf("%s\t%s\t%s\n", contract.ID.String(), *contract.Address, *contract.Name) 57 | fmt.Print(result) 58 | } 59 | } 60 | 61 | func init() { 62 | contractsListCmd.Flags().StringVar(&common.ApplicationID, "application", "", "application identifier to filter contracts") 63 | contractsListCmd.Flags().BoolVarP(&optional, "optional", "", false, "List all the optional flags") 64 | contractsListCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 65 | contractsListCmd.Flags().Uint64Var(&page, "page", common.DefaultPage, "page number to retrieve") 66 | contractsListCmd.Flags().Uint64Var(&rpp, "rpp", common.DefaultRpp, "number of contracts to retrieve per page") 67 | } 68 | -------------------------------------------------------------------------------- /prvd/contracts/contracts_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package contracts 18 | 19 | import ( 20 | "strconv" 21 | 22 | "github.com/provideplatform/provide-cli/prvd/common" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | const promptStepExecute = "Execute" 27 | const promptStepList = "List" 28 | 29 | var emptyPromptArgs = []string{promptStepExecute, promptStepList} 30 | var emptyPromptLabel = "What would you like to do" 31 | 32 | // General Endpoints 33 | func generalPrompt(cmd *cobra.Command, args []string, currentStep string) { 34 | switch step := currentStep; step { 35 | case promptStepExecute: 36 | if contractExecMethod == "" { 37 | contractExecMethod = common.FreeInput("Method", "", common.MandatoryValidation) 38 | } 39 | if common.ContractID == "" { 40 | common.ContractID = common.FreeInput("Contract ID", "", common.MandatoryValidation) 41 | } 42 | if optional { 43 | if common.AccountID == "" { 44 | common.RequireAccount(map[string]interface{}{}) 45 | } 46 | if common.WalletID == "" { 47 | common.RequireWallet() 48 | } 49 | if contractExecValue == 0 { 50 | result := common.FreeInput("Value", "0", common.NumberValidation) 51 | contractExecValue, _ = strconv.ParseUint(result, 10, 64) 52 | 53 | } 54 | } 55 | executeContract(cmd, args) 56 | case promptStepList: 57 | if optional { 58 | common.RequireApplication() 59 | } 60 | page, rpp = common.PromptPagination(paginate, page, rpp) 61 | case "": 62 | listContracts(cmd, args) 63 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 64 | generalPrompt(cmd, args, result) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /prvd/networks/networks.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package networks 18 | 19 | import ( 20 | "os" 21 | 22 | "github.com/provideplatform/provide-cli/prvd/common" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | var network map[string]interface{} 27 | var networks []interface{} 28 | 29 | var NetworksCmd = &cobra.Command{ 30 | Use: "networks", 31 | Short: "Manage networks", 32 | Long: `Manage and provision elastic distributed networks and other infrastructure`, 33 | Run: func(cmd *cobra.Command, args []string) { 34 | common.CmdExistsOrExit(cmd, args) 35 | 36 | generalPrompt(cmd, args, "") 37 | 38 | defer func() { 39 | if r := recover(); r != nil { 40 | os.Exit(1) 41 | } 42 | }() 43 | }, 44 | } 45 | 46 | func init() { 47 | NetworksCmd.AddCommand(networksInitCmd) 48 | NetworksCmd.AddCommand(networksListCmd) 49 | NetworksCmd.AddCommand(networksDisableCmd) 50 | NetworksCmd.Flags().BoolVarP(&optional, "optional", "", false, "List all the optional flags") 51 | NetworksCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 52 | } 53 | -------------------------------------------------------------------------------- /prvd/networks/networks_disable.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package networks 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | provide "github.com/provideplatform/provide-go/api/nchain" 26 | 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | var networksDisableCmd = &cobra.Command{ 31 | Use: "disable", 32 | Short: "Disable a specific network", 33 | Long: `Disable a specific network by identifier`, 34 | Run: disableNetwork, 35 | } 36 | 37 | func disableNetwork(cmd *cobra.Command, args []string) { 38 | token := common.RequireAPIToken() 39 | err := provide.UpdateNetwork(token, common.NetworkID, map[string]interface{}{ 40 | "enabled": false, 41 | }) 42 | if err != nil { 43 | log.Printf("Failed to disable network with id: %s; %s", common.NetworkID, err.Error()) 44 | os.Exit(1) 45 | } 46 | // if status != 204 { 47 | // log.Printf("Failed to disable network with id: %s; received status: %d", common.NetworkID, status) 48 | // os.Exit(1) 49 | // } 50 | fmt.Printf("Disabled network with id: %s", common.NetworkID) 51 | } 52 | 53 | func init() { 54 | networksDisableCmd.Flags().StringVar(&common.NetworkID, "network", "", "id of the network") 55 | // networksDisableCmd.MarkFlagRequired("network") 56 | } 57 | -------------------------------------------------------------------------------- /prvd/networks/networks_list.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package networks 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | provide "github.com/provideplatform/provide-go/api/nchain" 26 | 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | var public bool 31 | 32 | var page uint64 33 | var rpp uint64 34 | 35 | var networksListCmd = &cobra.Command{ 36 | Use: "list", 37 | Short: "Retrieve a list of networks", 38 | Long: `Retrieve a list of networks scoped to the authorized API token`, 39 | Run: listNetworks, 40 | } 41 | 42 | func listNetworks(cmd *cobra.Command, args []string) { 43 | token := common.RequireAPIToken() 44 | params := map[string]interface{}{ 45 | "page": fmt.Sprintf("%d", page), 46 | "rpp": fmt.Sprintf("%d", rpp), 47 | } 48 | if public { 49 | params["public"] = "true" 50 | } 51 | networks, err := provide.ListNetworks(token, params) 52 | if err != nil { 53 | log.Printf("Failed to retrieve networks list; %s", err.Error()) 54 | os.Exit(1) 55 | } 56 | for i := range networks { 57 | network := networks[i] 58 | result := fmt.Sprintf("%s\t%s\n", network.ID.String(), *network.Name) 59 | fmt.Print(result) 60 | } 61 | } 62 | 63 | func init() { 64 | networksListCmd.Flags().BoolVarP(&public, "public", "p", false, "filter private networks (false by default)") 65 | networksListCmd.Flags().BoolVarP(&optional, "optional", "", false, "List all the optional flags") 66 | networksListCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 67 | networksListCmd.Flags().Uint64Var(&page, "page", common.DefaultPage, "page number to retrieve") 68 | networksListCmd.Flags().Uint64Var(&rpp, "rpp", common.DefaultRpp, "number of networks to retrieve per page") 69 | } 70 | -------------------------------------------------------------------------------- /prvd/networks/networks_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package networks 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | const promptStepInit = "Initialize" 25 | const promptStepList = "List" 26 | const promptStepDisable = "Disable" 27 | 28 | var emptyPromptArgs = []string{promptStepInit, promptStepList, promptStepDisable} 29 | var emptyPromptLabel = "What would you like to do" 30 | 31 | var publicPromptArgs = []string{"Yes", "No"} 32 | var publicPromptLabel = "Would you like the network to be public" 33 | 34 | // General Endpoints 35 | func generalPrompt(cmd *cobra.Command, args []string, currentStep string) { 36 | switch step := currentStep; step { 37 | case promptStepInit: 38 | // Validation non-null 39 | if chain == "" { 40 | chain = common.FreeInput("Chain", "", common.NoValidation) 41 | } 42 | if nativeCurrency == "" { 43 | nativeCurrency = common.FreeInput("Native Currency", "", common.NoValidation) 44 | } 45 | if platform == "" { 46 | platform = common.FreeInput("Platform", "", common.NoValidation) 47 | } 48 | if protocolID == "" { 49 | protocolID = common.FreeInput("Protocol ID", "", common.NoValidation) 50 | } 51 | if networkName == "" { 52 | networkName = common.FreeInput("Network Name", "", common.NoValidation) 53 | } 54 | CreateNetwork(cmd, args) 55 | case promptStepList: 56 | if optional { 57 | result := common.SelectInput(publicPromptArgs, publicPromptLabel) 58 | public = result == "Yes" 59 | } 60 | page, rpp = common.PromptPagination(paginate, page, rpp) 61 | listNetworks(cmd, args) 62 | case promptStepDisable: 63 | common.RequireNetwork() 64 | disableNetwork(cmd, args) 65 | case "": 66 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 67 | generalPrompt(cmd, args, result) 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /prvd/nodes/nodes.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package nodes 18 | 19 | import ( 20 | "os" 21 | 22 | "github.com/provideplatform/provide-cli/prvd/common" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | var node map[string]interface{} 27 | var nodes []interface{} 28 | var nodeType string 29 | 30 | var NodesCmd = &cobra.Command{ 31 | Use: "nodes", 32 | Short: "Manage nodes", 33 | Long: `Manage and provision elastic distributed nodes`, 34 | Run: func(cmd *cobra.Command, args []string) { 35 | common.CmdExistsOrExit(cmd, args) 36 | 37 | generalPrompt(cmd, args, "") 38 | 39 | defer func() { 40 | if r := recover(); r != nil { 41 | os.Exit(1) 42 | } 43 | }() 44 | }, 45 | } 46 | 47 | func init() { 48 | NodesCmd.AddCommand(nodesInitCmd) 49 | NodesCmd.AddCommand(nodesLogsCmd) 50 | NodesCmd.AddCommand(nodesDeleteCmd) 51 | NodesCmd.Flags().BoolVarP(&optional, "optional", "", false, "List all the optional flags") 52 | 53 | } 54 | -------------------------------------------------------------------------------- /prvd/nodes/nodes_delete.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package nodes 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | // provide "github.com/provideplatform/provide-go/api/nchain" 22 | 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | var nodesDeleteCmd = &cobra.Command{ 27 | Use: "delete", 28 | Short: "Delete a specific node", 29 | Long: `Delete a specific node by identifier and teardown any associated infrastructure`, 30 | Run: deleteNode, 31 | } 32 | 33 | func deleteNode(cmd *cobra.Command, args []string) { 34 | generalPrompt(cmd, args, promptStepDelete) 35 | } 36 | 37 | func deleteNodeRun(cmd *cobra.Command, args []string) { 38 | // FIXME!!! 39 | 40 | // token := common.RequireAPIToken() 41 | // status, _, err := provide.DeleteNetworkNode(token, common.NetworkID, common.NodeID) 42 | // if err != nil { 43 | // log.Printf("Failed to delete node with id: %s; %s", common.NodeID, err.Error()) 44 | // os.Exit(1) 45 | // } 46 | // if status != 204 { 47 | // log.Printf("Failed to delete node with id: %s; received status: %d", common.NodeID, status) 48 | // os.Exit(1) 49 | // } 50 | // fmt.Printf("Deleted node with id: %s", common.NodeID) 51 | } 52 | 53 | func init() { 54 | nodesDeleteCmd.Flags().StringVar(&common.NetworkID, "network", "", "network id") 55 | nodesDeleteCmd.MarkFlagRequired("network") 56 | 57 | nodesDeleteCmd.Flags().StringVar(&common.NodeID, "node", "", "id of the node") 58 | nodesDeleteCmd.MarkFlagRequired("node") 59 | } 60 | -------------------------------------------------------------------------------- /prvd/nodes/nodes_logs.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package nodes 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | // provide "github.com/provideplatform/provide-go/api/nchain" 22 | 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | var page uint64 27 | var rpp uint64 28 | 29 | var nodesLogsCmd = &cobra.Command{ 30 | Use: "logs", 31 | Short: "Retrieve logs for a node", 32 | Long: `Retrieve paginated log output for a specific node by identifier`, 33 | Run: nodeLogs, 34 | } 35 | 36 | func nodeLogs(cmd *cobra.Command, args []string) { 37 | generalPrompt(cmd, args, promptStepLogs) 38 | } 39 | 40 | func nodeLogsRun(cmd *cobra.Command, args []string) { 41 | // FIXME 42 | // token := common.RequireAPIToken() 43 | // resp, err := provide.GetNetworkNodeLogs(token, common.NetworkID, common.NodeID, map[string]interface{}{ 44 | // "page": page, 45 | // "rpp": rpp, 46 | // }) 47 | // if err != nil { 48 | // log.Printf("Failed to retrieve node logs for node with id: %s; %s", common.NodeID, err.Error()) 49 | // os.Exit(1) 50 | // } 51 | // if status != 200 { 52 | // log.Printf("Failed to retrieve node logs for node with id: %s; received status: %d", common.NodeID, status) 53 | // os.Exit(1) 54 | // } 55 | // logsResponse := resp.(map[string]interface{}) 56 | // if logs, logsOk := logsResponse["logs"].([]interface{}); logsOk { 57 | // for _, log := range logs { 58 | // fmt.Printf("%s\n", log) 59 | // } 60 | // } 61 | // if nextToken, nextTokenOk := logsResponse["next_token"].(string); nextTokenOk { 62 | // fmt.Printf("next token: %s", nextToken) 63 | // } 64 | } 65 | 66 | func init() { 67 | nodesLogsCmd.Flags().StringVar(&common.NetworkID, "network", "", "network id") 68 | nodesLogsCmd.MarkFlagRequired("network") 69 | 70 | nodesLogsCmd.Flags().StringVar(&common.NodeID, "node", "", "id of the node") 71 | nodesLogsCmd.MarkFlagRequired("node") 72 | 73 | nodesLogsCmd.Flags().Uint64Var(&page, "page", common.DefaultPage, "page number to retrieve") 74 | nodesLogsCmd.MarkFlagRequired("page") 75 | 76 | nodesLogsCmd.Flags().Uint64Var(&rpp, "rpp", 100, "number of log events to retrieve per page") 77 | nodesLogsCmd.MarkFlagRequired("rpp") 78 | } 79 | -------------------------------------------------------------------------------- /prvd/nodes/nodes_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package nodes 18 | 19 | import ( 20 | "fmt" 21 | "strconv" 22 | 23 | "github.com/provideplatform/provide-cli/prvd/common" 24 | "github.com/spf13/cobra" 25 | ) 26 | 27 | const promptStepLogs = "Logs" 28 | const promptStepInit = "Initialize" 29 | const promptStepDelete = "Delete" 30 | 31 | var emptyPromptArgs = []string{promptStepInit, promptStepLogs, promptStepDelete} 32 | var emptyPromptLabel = "What would you like to do" 33 | 34 | // General Endpoints 35 | func generalPrompt(cmd *cobra.Command, args []string, currentStep string) { 36 | switch step := currentStep; step { 37 | case promptStepInit: 38 | if common.NetworkID == "" { 39 | common.RequireL1Network() 40 | } 41 | if common.Image == "" { 42 | common.Image = common.FreeInput("Image", "", common.MandatoryValidation) 43 | } 44 | if role == "" { 45 | role = common.FreeInput("Role", "", common.MandatoryValidation) 46 | } 47 | if optional { 48 | fmt.Println("Optional Flags:") 49 | if common.HealthCheckPath == "" { 50 | common.HealthCheckPath = common.FreeInput("Health Check Path", "", common.NoValidation) 51 | } 52 | if common.TCPIngressPorts == "" { 53 | common.TCPIngressPorts = common.FreeInput("TCP Ingress Ports", "", common.NoValidation) 54 | } 55 | if common.UDPIngressPorts == "" { 56 | common.UDPIngressPorts = common.FreeInput("UDP Ingress Ports", "", common.NoValidation) 57 | } 58 | if common.TaskRole == "" { 59 | common.TaskRole = common.FreeInput("Task Role", "", common.NoValidation) 60 | 61 | } 62 | } 63 | CreateNodeRun(cmd, args) 64 | case promptStepDelete: 65 | if common.NetworkID == "" { 66 | common.RequireL1Network() 67 | } 68 | if common.NodeID == "" { 69 | common.NodeID = common.FreeInput("Node ID", "", common.MandatoryValidation) 70 | } 71 | deleteNodeRun(cmd, args) 72 | case promptStepLogs: 73 | if common.NetworkID == "" { 74 | common.RequireL1Network() 75 | } 76 | if common.NodeID == "" { 77 | common.NodeID = common.FreeInput("Node ID", "", common.MandatoryValidation) 78 | } 79 | // Validation Number 80 | if page == 1 { 81 | result := common.FreeInput("Page", "1", common.MandatoryNumberValidation) 82 | page, _ = strconv.ParseUint(result, 10, 64) 83 | } 84 | // Validation Number 85 | if rpp == 100 { 86 | result := common.FreeInput("RPP", "100", common.MandatoryValidation) 87 | rpp, _ = strconv.ParseUint(result, 10, 64) 88 | } 89 | nodeLogsRun(cmd, args) 90 | case "": 91 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 92 | generalPrompt(cmd, args, result) 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /prvd/organizations/organizations.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package organizations 18 | 19 | import ( 20 | "os" 21 | 22 | "github.com/provideplatform/provide-cli/prvd/common" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | var OrganizationsCmd = &cobra.Command{ 27 | Use: "organizations", 28 | Short: "Manage organizations", 29 | Long: `Create and manage organizations in the context of the following APIs: 30 | 31 | - Applications 32 | - Baseline Protocol 33 | - Tokens 34 | - Vaults`, 35 | Run: func(cmd *cobra.Command, args []string) { 36 | common.CmdExistsOrExit(cmd, args) 37 | 38 | generalPrompt(cmd, args, "") 39 | 40 | defer func() { 41 | if r := recover(); r != nil { 42 | os.Exit(1) 43 | } 44 | }() 45 | }, 46 | } 47 | 48 | func init() { 49 | OrganizationsCmd.AddCommand(organizationsListCmd) 50 | OrganizationsCmd.AddCommand(organizationsInitCmd) 51 | OrganizationsCmd.AddCommand(organizationsDetailsCmd) 52 | OrganizationsCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 53 | } 54 | -------------------------------------------------------------------------------- /prvd/organizations/organizations_details.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package organizations 18 | 19 | import ( 20 | "encoding/json" 21 | "fmt" 22 | "log" 23 | "os" 24 | 25 | "github.com/provideplatform/provide-cli/prvd/common" 26 | provide "github.com/provideplatform/provide-go/api/ident" 27 | 28 | "github.com/spf13/cobra" 29 | ) 30 | 31 | var organizationsDetailsCmd = &cobra.Command{ 32 | Use: "details", 33 | Short: "Retrieve a specific organization", 34 | Long: `Retrieve details for a specific organization by identifier, scoped to the authorized API token`, 35 | Run: fetchOrganizationDetails, 36 | } 37 | 38 | func fetchOrganizationDetails(cmd *cobra.Command, args []string) { 39 | generalPrompt(cmd, args, promptStepDetails) 40 | } 41 | 42 | func fetchOrganizationDetailsRun(cmd *cobra.Command, args []string) { 43 | if common.OrganizationID == "" { 44 | generalPrompt(cmd, args, "Details") 45 | } 46 | token := common.RequireUserAccessToken() 47 | params := map[string]interface{}{} 48 | organization, err := provide.GetOrganizationDetails(token, common.OrganizationID, params) 49 | if err != nil { 50 | log.Printf("Failed to retrieve details for organization with id: %s; %s", common.OrganizationID, err.Error()) 51 | os.Exit(1) 52 | } 53 | // if status != 200 { 54 | // log.Printf("Failed to retrieve details for organization with id: %s; %s", common.OrganizationID, organization) 55 | // os.Exit(1) 56 | // } 57 | 58 | result, _ := json.MarshalIndent(organization, "", "\t") 59 | fmt.Printf("%s\n", string(result)) 60 | } 61 | 62 | func init() { 63 | organizationsDetailsCmd.Flags().StringVar(&common.OrganizationID, "organization", "", "id of the organization") 64 | // organizationsDetailsCmd.MarkFlagRequired("organization") 65 | } 66 | -------------------------------------------------------------------------------- /prvd/organizations/organizations_init.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package organizations 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | "github.com/provideplatform/provide-go/api/ident" 26 | "github.com/provideplatform/provide-go/api/vault" 27 | 28 | "github.com/spf13/cobra" 29 | ) 30 | 31 | var organizationName string 32 | var paginate bool 33 | 34 | var organizationsInitCmd = &cobra.Command{ 35 | Use: "init --name 'Acme Inc.'", 36 | Short: "Initialize a new organization", 37 | Long: `Initialize a new organization`, 38 | Run: createOrganization, 39 | } 40 | 41 | func organizationConfigFactory() map[string]interface{} { 42 | cfg := map[string]interface{}{ 43 | "network_id": common.NetworkID, 44 | } 45 | 46 | return cfg 47 | } 48 | func createOrganization(cmd *cobra.Command, args []string) { 49 | generalPrompt(cmd, args, promptStepInit) 50 | } 51 | 52 | func createOrganizationRun(cmd *cobra.Command, args []string) { 53 | token := common.RequireAPIToken() 54 | params := map[string]interface{}{ 55 | "name": organizationName, 56 | "config": organizationConfigFactory(), 57 | } 58 | organization, err := ident.CreateOrganization(token, params) 59 | if err != nil { 60 | log.Printf("Failed to initialize organization; %s", err.Error()) 61 | os.Exit(1) 62 | } 63 | 64 | common.OrganizationID = *organization.ID 65 | 66 | orgToken, err := common.ResolveOrganizationToken() 67 | if err != nil { 68 | log.Printf("failed to initialize organization; %s", err.Error()) 69 | os.Exit(1) 70 | } 71 | 72 | if _, err := vault.CreateVault(*orgToken.AccessToken, map[string]interface{}{ 73 | "name": fmt.Sprintf("%s vault", organizationName), 74 | }); err != nil { 75 | log.Printf("failed to create organization vault; %s", err.Error()) 76 | os.Exit(1) 77 | } 78 | 79 | log.Printf("initialized organization: %s\t%s\n", organizationName, common.OrganizationID) 80 | } 81 | 82 | func init() { 83 | organizationsInitCmd.Flags().StringVar(&organizationName, "name", "", "name of the organization") 84 | } 85 | -------------------------------------------------------------------------------- /prvd/organizations/organizations_list.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package organizations 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | provide "github.com/provideplatform/provide-go/api/ident" 26 | 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | var page uint64 31 | var rpp uint64 32 | 33 | var organizationsListCmd = &cobra.Command{ 34 | Use: "list", 35 | Short: "Retrieve a list of organizations", 36 | Long: `Retrieve a list of organizations scoped to the authorized API token`, 37 | Run: listOrganizations, 38 | } 39 | 40 | func listOrganizations(cmd *cobra.Command, args []string) { 41 | generalPrompt(cmd, args, promptStepList) 42 | } 43 | 44 | func listOrganizationsRun(cmd *cobra.Command, args []string) { 45 | token := common.RequireAPIToken() 46 | params := map[string]interface{}{ 47 | "page": fmt.Sprintf("%d", page), 48 | "rpp": fmt.Sprintf("%d", rpp), 49 | } 50 | organizations, err := provide.ListOrganizations(token, params) 51 | if err != nil { 52 | log.Printf("Failed to retrieve organizations list; %s", err.Error()) 53 | os.Exit(1) 54 | } 55 | for i := range organizations { 56 | organization := organizations[i] 57 | address := "0x" 58 | if addr, addrOk := organization.Metadata["address"].(string); addrOk { 59 | address = addr 60 | } 61 | result := fmt.Sprintf("%s\t%s\t%s\n", *organization.ID, *organization.Name, address) 62 | fmt.Print(result) 63 | } 64 | } 65 | 66 | func init() { 67 | organizationsListCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 68 | organizationsListCmd.Flags().Uint64Var(&page, "page", common.DefaultPage, "page number to retrieve") 69 | organizationsListCmd.Flags().Uint64Var(&rpp, "rpp", common.DefaultRpp, "number of organizations to retrieve per page") 70 | } 71 | -------------------------------------------------------------------------------- /prvd/organizations/organizations_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package organizations 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | const promptStepDetails = "Details" 25 | const promptStepInit = "Initialize" 26 | const promptStepList = "List" 27 | 28 | var emptyPromptArgs = []string{promptStepInit, promptStepList, promptStepDetails} 29 | var emptyPromptLabel = "What would you like to do" 30 | 31 | // General Endpoints 32 | func generalPrompt(cmd *cobra.Command, args []string, step string) { 33 | switch step { 34 | case promptStepInit: 35 | organizationName = common.FreeInput("Organization Name", "", common.MandatoryValidation) 36 | createOrganizationRun(cmd, args) 37 | case promptStepList: 38 | page, rpp = common.PromptPagination(paginate, page, rpp) 39 | listOrganizationsRun(cmd, args) 40 | case promptStepDetails: 41 | common.RequireOrganization() 42 | fetchOrganizationDetailsRun(cmd, args) 43 | case "": 44 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 45 | generalPrompt(cmd, args, result) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /prvd/root.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package prvd 18 | 19 | import ( 20 | "fmt" 21 | "os" 22 | 23 | "github.com/spf13/cobra" 24 | 25 | "github.com/provideplatform/provide-cli/prvd/accounts" 26 | "github.com/provideplatform/provide-cli/prvd/api_tokens" 27 | "github.com/provideplatform/provide-cli/prvd/applications" 28 | axiom "github.com/provideplatform/provide-cli/prvd/axiom" 29 | "github.com/provideplatform/provide-cli/prvd/common" 30 | "github.com/provideplatform/provide-cli/prvd/connectors" 31 | "github.com/provideplatform/provide-cli/prvd/contracts" 32 | "github.com/provideplatform/provide-cli/prvd/networks" 33 | "github.com/provideplatform/provide-cli/prvd/nodes" 34 | "github.com/provideplatform/provide-cli/prvd/organizations" 35 | "github.com/provideplatform/provide-cli/prvd/shell" 36 | "github.com/provideplatform/provide-cli/prvd/users" 37 | "github.com/provideplatform/provide-cli/prvd/vaults" 38 | "github.com/provideplatform/provide-cli/prvd/wallets" 39 | ) 40 | 41 | var rootCmd = &cobra.Command{ 42 | Use: "prvd", 43 | Short: "Provide CLI", 44 | Long: fmt.Sprintf(`%s 45 | 46 | The Provide CLI exposes low-code tools to manage network, application and organization resources. 47 | 48 | Run with the --help flag to see available options`, common.ASCIIBanner), 49 | } 50 | 51 | // Execute the default command path 52 | func Execute() { 53 | if err := rootCmd.Execute(); err != nil { 54 | fmt.Println(err) 55 | os.Exit(1) 56 | } 57 | } 58 | 59 | func init() { 60 | cobra.OnInitialize(common.InitConfig) 61 | 62 | rootCmd.PersistentFlags().BoolVarP(&common.Verbose, "verbose", "v", false, "enable verbose output") 63 | rootCmd.PersistentFlags().StringVarP(&common.CfgFile, "config", "c", "", "config file (default is $HOME/.provide-cli.yaml)") 64 | 65 | rootCmd.AddCommand(accounts.AccountsCmd) 66 | rootCmd.AddCommand(api_tokens.APITokensCmd) 67 | rootCmd.AddCommand(applications.ApplicationsCmd) 68 | rootCmd.AddCommand(users.AuthenticateCmd) 69 | rootCmd.AddCommand(axiom.BaselineCmd) 70 | rootCmd.AddCommand(connectors.ConnectorsCmd) 71 | rootCmd.AddCommand(contracts.ContractsCmd) 72 | rootCmd.AddCommand(networks.NetworksCmd) 73 | rootCmd.AddCommand(nodes.NodesCmd) 74 | rootCmd.AddCommand(organizations.OrganizationsCmd) 75 | rootCmd.AddCommand(shell.ShellCmd) 76 | rootCmd.AddCommand(users.UsersCmd) 77 | rootCmd.AddCommand(vaults.VaultsCmd) 78 | rootCmd.AddCommand(wallets.WalletsCmd) 79 | 80 | common.CacheCommands(rootCmd) 81 | } 82 | -------------------------------------------------------------------------------- /prvd/shell/escape.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package shell 18 | 19 | func clear() { 20 | writeRaw([]byte("\033[H\033[2J"), true) 21 | } 22 | 23 | func clearScrollback() { 24 | writeRaw([]byte("\033[3J"), true) 25 | } 26 | 27 | func cursorUp() { 28 | writeRaw([]byte("\033[A"), true) 29 | } 30 | 31 | func cursorDown() { 32 | writeRaw([]byte("\033[B"), true) 33 | } 34 | 35 | func cursorRight() { 36 | writeRaw([]byte("\033[C"), true) 37 | } 38 | 39 | func cursorLeft() { 40 | writeRaw([]byte("\033[D"), true) 41 | } 42 | 43 | func cursorNextLine() { 44 | writeRaw([]byte("\033[E"), true) 45 | } 46 | 47 | func cursorPreviousLine() { 48 | writeRaw([]byte("\033[F"), true) 49 | } 50 | 51 | func defaultCursorPosition() { 52 | if writer != nil { 53 | writer.CursorGoTo(shellHeaderRows+1, 0) 54 | } 55 | } 56 | 57 | func eraseCursorToEnd() { 58 | writeRaw([]byte("\033[0J"), true) 59 | } 60 | 61 | func eraseCursorToLineEnd() { 62 | writeRaw([]byte("\033[0K"), true) 63 | } 64 | 65 | func eraseCurrentLineToCursor() { 66 | writeRaw([]byte("\033[1K"), true) 67 | } 68 | 69 | func eraseCurrentLine() { 70 | writeRaw([]byte("\033[2K"), true) 71 | } 72 | 73 | func hideCursor() { 74 | if writer != nil { 75 | writer.HideCursor() 76 | cursorHidden = true 77 | } 78 | } 79 | 80 | func saveCursor() { 81 | if writer != nil { 82 | writer.SaveCursor() 83 | } 84 | } 85 | 86 | func showCursor() { 87 | if writer != nil { 88 | writer.ShowCursor() 89 | cursorHidden = false 90 | } 91 | } 92 | 93 | func stripEscapeSequences(in string) string { 94 | if len(in) > 0 { 95 | // fmt.Printf("%s", in) 96 | // HACK 97 | return in[7:] 98 | } 99 | return in 100 | } 101 | 102 | func toggleAlternateBuffer() { 103 | if !viewingAlternateBuffer { 104 | writeRaw([]byte("\033[?1049h"), true) 105 | viewingAlternateBuffer = true 106 | } else { 107 | writeRaw([]byte("\033[?1049l"), true) 108 | viewingAlternateBuffer = false 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /prvd/shell/native.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package shell 18 | 19 | import ( 20 | "bytes" 21 | "os" 22 | "sync" 23 | 24 | "github.com/manifoldco/promptui" 25 | ) 26 | 27 | const nativeCommandTop = "top" 28 | 29 | type NoopCloser struct { 30 | buf *bytes.Buffer 31 | } 32 | 33 | func (nc *NoopCloser) Write(buf []byte) (int, error) { 34 | // fmt.Printf("write %d-byte buffer...", len(buf)) 35 | // writer.WriteRaw([]byte("\033[0J")) 36 | // raw := stripEscapeSequences(string(buf)) 37 | // writer.WriteRaw([]byte(raw)) 38 | // // writer.UnSaveCursor() 39 | // writer.Flush() 40 | 41 | return nc.buf.Write(buf) 42 | } 43 | 44 | func (nc *NoopCloser) Close() error { 45 | return nil 46 | } 47 | 48 | var nativeCommands = map[string]interface{}{ 49 | nativeCommandTop: func(argv []string) (*REPL, error) { 50 | 51 | buf := &bytes.Buffer{} 52 | i := 0 53 | var pending bool 54 | 55 | saveCursor() 56 | hideCursor() 57 | eraseCursorToEnd() 58 | 59 | repl, _ = NewREPL(func(wg *sync.WaitGroup) error { 60 | if !pending { 61 | pending = true 62 | toggleAlternateBuffer() 63 | go shellOut("docker", []string{"stats"}, buf) 64 | } 65 | 66 | if buf.Len() > 0 { 67 | mutex.Lock() 68 | defer mutex.Unlock() 69 | 70 | writer.SaveCursor() 71 | writer.CursorGoTo(shellHeaderRows+1, 0) 72 | writer.WriteRaw([]byte("\033[0J")) 73 | raw := stripEscapeSequences(string(buf.Bytes()[i:])) 74 | writer.WriteRaw([]byte(raw)) 75 | writer.UnSaveCursor() 76 | writer.Flush() 77 | 78 | i += buf.Len() - i 79 | } 80 | 81 | return nil 82 | }) 83 | 84 | go repl.run() 85 | return repl, nil 86 | }, 87 | } 88 | 89 | // MarshalPromptIO marshals IO from promptui text or select prompt 90 | func MarshalPromptIO(sel *promptui.Select) { 91 | buf := &bytes.Buffer{} 92 | sel.Stdin = os.Stdin 93 | // sel.Stdout = &NoopCloser{ 94 | // buf: buf, 95 | // } 96 | 97 | i := 0 98 | repl, _ := NewREPL(func(wg *sync.WaitGroup) error { 99 | if buf.Len() > 0 { 100 | mutex.Lock() 101 | defer mutex.Unlock() 102 | 103 | // writer.SaveCursor() 104 | // writer.HideCursor() 105 | eraseCurrentLine() 106 | // writer.CursorGoTo(shellHeaderRows+1, 0) 107 | writer.WriteRaw([]byte("\033[0J")) 108 | raw := stripEscapeSequences(string(buf.Bytes()[i:])) 109 | writer.WriteRaw([]byte(raw)) 110 | // writer.UnSaveCursor() 111 | // writer.ShowCursor() 112 | writer.Flush() 113 | 114 | i += buf.Len() - i 115 | } 116 | 117 | return nil 118 | }) 119 | 120 | // TODO-- don't leak this... 121 | go repl.run() 122 | } 123 | 124 | func resolveNativeCommand(argv []string) func([]string) (*REPL, error) { 125 | if len(argv) > 0 { 126 | if fn, fnOk := nativeCommands[argv[0]].(func([]string) (*REPL, error)); fnOk { 127 | return fn 128 | } 129 | } 130 | return nil 131 | } 132 | 133 | func supportedNativeCommand(argv []string) bool { 134 | if len(argv) > 0 { 135 | return resolveNativeCommand(argv) != nil 136 | } 137 | return false 138 | } 139 | -------------------------------------------------------------------------------- /prvd/users/authenticate.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package users 18 | 19 | import ( 20 | "log" 21 | "os" 22 | 23 | "github.com/provideplatform/provide-cli/prvd/common" 24 | provide "github.com/provideplatform/provide-go/api/ident" 25 | 26 | "github.com/spf13/cobra" 27 | "github.com/spf13/viper" 28 | ) 29 | 30 | // authenticateCmd represents the authenticate command 31 | var AuthenticateCmd = &cobra.Command{ 32 | Use: "authenticate", 33 | Short: "Authenticate using your credentials", 34 | Long: `Authenticate using user credentials and receive a 35 | valid access/refresh token pair which can be used to make API calls.`, 36 | Run: authenticate, 37 | } 38 | 39 | func authenticate(cmd *cobra.Command, args []string) { 40 | email = common.FreeInput("Email", "", common.MandatoryValidation) 41 | passwd = common.FreeInput("Password", "", common.MandatoryValidation) 42 | 43 | resp, err := provide.Authenticate(email, passwd) 44 | if err != nil { 45 | log.Println(err) 46 | os.Exit(1) 47 | } 48 | 49 | if resp.Token.AccessToken != nil && resp.Token.RefreshToken != nil { 50 | common.CacheAccessRefreshToken(resp.Token, nil) 51 | } else if resp.Token.Token != nil { 52 | viper.Set(common.AccessTokenConfigKey, *resp.Token.Token) 53 | viper.WriteConfig() 54 | } 55 | 56 | log.Printf("Authentication successful") 57 | } 58 | -------------------------------------------------------------------------------- /prvd/users/init.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package users 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | provide "github.com/provideplatform/provide-go/api/ident" 26 | 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | // initCmd creates a new user 31 | var initCmd = &cobra.Command{ 32 | Use: "init", 33 | Short: "Create a new user", 34 | Long: `Create a new user in the configured ident instance; defaults to ident.provide.services.`, 35 | Run: create, 36 | } 37 | 38 | var firstName string 39 | var lastName string 40 | var email string 41 | var passwd string 42 | 43 | func create(cmd *cobra.Command, args []string) { 44 | firstName = common.FreeInput("First Name", "", common.MandatoryValidation) 45 | lastName = common.FreeInput("Last Name", "", common.MandatoryValidation) 46 | email = common.FreeInput("Email", "", common.EmailValidation) 47 | passwd = common.FreeInput("Password", "", common.MandatoryValidation) 48 | 49 | resp, err := provide.CreateUser("", map[string]interface{}{ 50 | "email": email, 51 | "password": passwd, 52 | "first_name": firstName, 53 | "last_name": lastName, 54 | }) 55 | if err != nil { 56 | log.Println(err) 57 | os.Exit(1) 58 | } 59 | 60 | _, err = provide.Authenticate(email, passwd) 61 | if err != nil { 62 | log.Println(err) 63 | os.Exit(1) 64 | } 65 | 66 | fmt.Printf("created user: %s", *resp.ID) 67 | } 68 | -------------------------------------------------------------------------------- /prvd/users/users.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package users 18 | 19 | import ( 20 | "os" 21 | 22 | "github.com/provideplatform/provide-cli/prvd/common" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | var UsersCmd = &cobra.Command{ 27 | Use: "users", 28 | Short: "Manage users", 29 | Long: `Create and manage users and authenticate`, 30 | Run: func(cmd *cobra.Command, args []string) { 31 | common.CmdExistsOrExit(cmd, args) 32 | 33 | generalPrompt(cmd, args, "") 34 | defer func() { 35 | if r := recover(); r != nil { 36 | os.Exit(1) 37 | } 38 | }() 39 | }, 40 | } 41 | 42 | func init() { 43 | UsersCmd.AddCommand(initCmd) 44 | } 45 | -------------------------------------------------------------------------------- /prvd/users/users_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package users 18 | 19 | import ( 20 | "github.com/provideplatform/provide-cli/prvd/common" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var promptStepCreate = "Create" 25 | var promptStepAuthenticate = "Authenticate" 26 | 27 | var emptyPromptArgs = []string{promptStepCreate, promptStepAuthenticate} 28 | var emptyPromptLabel = "What would you like to do" 29 | 30 | // General Endpoints 31 | func generalPrompt(cmd *cobra.Command, args []string, currentStep string) { 32 | switch step := currentStep; step { 33 | case promptStepAuthenticate: 34 | authenticate(cmd, args) 35 | case promptStepCreate: 36 | create(cmd, args) 37 | case "": 38 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 39 | generalPrompt(cmd, args, result) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /prvd/vaults/keys/keys.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package keys 18 | 19 | import ( 20 | "os" 21 | 22 | "github.com/spf13/cobra" 23 | ) 24 | 25 | var KeysCmd = &cobra.Command{ 26 | Use: "keys", 27 | Short: "Manage keys", 28 | Long: `Create and manage cryptographic keys. 29 | 30 | Supports symmetric and asymmetric key specs with encrypt/decrypt and sign/verify operations. 31 | 32 | Docs: https://docs.provide.services/vault/api-reference/keys`, 33 | Run: func(cmd *cobra.Command, args []string) { 34 | generalPrompt(cmd, args, "") 35 | 36 | defer func() { 37 | if r := recover(); r != nil { 38 | os.Exit(1) 39 | } 40 | }() 41 | }, 42 | } 43 | 44 | func init() { 45 | KeysCmd.AddCommand(keysListCmd) 46 | KeysCmd.AddCommand(keysInitCmd) 47 | KeysCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 48 | } 49 | -------------------------------------------------------------------------------- /prvd/vaults/keys/keys_init.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package keys 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | vault "github.com/provideplatform/provide-go/api/vault" 26 | 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | var name string 31 | var description string 32 | var keyspec string 33 | var keytype string 34 | var keyusage string 35 | var paginate bool 36 | 37 | var keysInitCmd = &cobra.Command{ 38 | Use: "init --name 'My Key' --description 'not your keys, not your crypto'", 39 | Short: "Create a new key", 40 | Long: `Initialize a new key`, 41 | Run: createKey, 42 | } 43 | 44 | func createKey(cmd *cobra.Command, args []string) { 45 | generalPrompt(cmd, args, promptStepInit) 46 | } 47 | 48 | func createKeyRun(cmd *cobra.Command, args []string) { 49 | token := common.RequireAPIToken() 50 | params := map[string]interface{}{ 51 | "name": name, 52 | "description": description, 53 | "spec": keyspec, 54 | "type": keytype, 55 | "usage": keyusage, 56 | } 57 | vlt, err := vault.CreateKey(token, common.VaultID, params) 58 | if err != nil { 59 | log.Printf("failed to create key in vault: %s; %s", common.VaultID, err.Error()) 60 | os.Exit(1) 61 | } 62 | result := fmt.Sprintf("%s\t%s\t%s\n", vlt.ID.String(), *vlt.Name, *vlt.Description) 63 | fmt.Print(result) 64 | } 65 | 66 | func init() { 67 | keysInitCmd.Flags().StringVar(&name, "name", "", "name of the key") 68 | keysInitCmd.Flags().StringVar(&description, "description", "", "description of the key") 69 | keysInitCmd.Flags().StringVar(&keyspec, "spec", "", "key spec to use for the key") 70 | keysInitCmd.Flags().StringVar(&keytype, "type", "", "key type; must be symmetric or asymmetric") 71 | keysInitCmd.Flags().StringVar(&keyusage, "usage", "", "intended usage for the key; must be encrypt/decrypt or sign/verify") 72 | 73 | keysInitCmd.Flags().StringVar(&common.ApplicationID, "application", "", "application identifier for which the key will be created") 74 | keysInitCmd.Flags().StringVar(&common.OrganizationID, "organization", "", "organization identifier for which the key will be created") 75 | } 76 | -------------------------------------------------------------------------------- /prvd/vaults/keys/keys_list.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package keys 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | vault "github.com/provideplatform/provide-go/api/vault" 26 | 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | var page uint64 31 | var rpp uint64 32 | 33 | var keysListCmd = &cobra.Command{ 34 | Use: "list", 35 | Short: "Retrieve a list of keys", 36 | Long: `Retrieve a list of keys scoped to the authorized API token`, 37 | Run: listKeys, 38 | } 39 | 40 | func listKeys(cmd *cobra.Command, args []string) { 41 | generalPrompt(cmd, args, promptStepList) 42 | } 43 | 44 | func listKeysRun(cmd *cobra.Command, args []string) { 45 | token := common.RequireAPIToken() 46 | params := map[string]interface{}{ 47 | "page": fmt.Sprintf("%d", page), 48 | "rpp": fmt.Sprintf("%d", rpp), 49 | } 50 | if common.ApplicationID != "" { 51 | params["application_id"] = common.ApplicationID 52 | } 53 | if common.OrganizationID != "" { 54 | params["organization_id"] = common.OrganizationID 55 | } 56 | resp, err := vault.ListKeys(token, common.VaultID, params) 57 | if err != nil { 58 | log.Printf("failed to retrieve keys list; %s", err.Error()) 59 | os.Exit(1) 60 | } 61 | for i := range resp { 62 | vlt := resp[i] 63 | result := fmt.Sprintf("%s\t%s\t%s\n", vlt.ID.String(), *vlt.Name, *vlt.Description) 64 | fmt.Print(result) 65 | } 66 | } 67 | 68 | func init() { 69 | keysListCmd.Flags().StringVar(&common.ApplicationID, "application", "", "application identifier to filter keys") 70 | keysListCmd.Flags().StringVar(&common.OrganizationID, "organization", "", "organization identifier to filter keys") 71 | keysListCmd.Flags().StringVar(&common.VaultID, "vault", "", "identifier of the vault") 72 | 73 | keysListCmd.Flags().StringVar(&keyspec, "spec", "", "key spec query; non-matching keys are filtered") 74 | keysListCmd.Flags().StringVar(&keytype, "type", "", "key type query; non-matching keys are filtered") 75 | keysListCmd.Flags().StringVar(&keyusage, "usage", "", "key usage query; non-matching keys are filtered") 76 | 77 | keysListCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 78 | keysListCmd.Flags().Uint64Var(&page, "page", common.DefaultPage, "page number to retrieve") 79 | keysListCmd.Flags().Uint64Var(&rpp, "rpp", common.DefaultRpp, "number of keys to retrieve per page") 80 | } 81 | -------------------------------------------------------------------------------- /prvd/vaults/vaults.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package vaults 18 | 19 | import ( 20 | "os" 21 | 22 | "github.com/spf13/cobra" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | "github.com/provideplatform/provide-cli/prvd/vaults/keys" 26 | ) 27 | 28 | var VaultsCmd = &cobra.Command{ 29 | Use: "vaults", 30 | Short: "Manage vaults", 31 | Long: `Create and manage vaults and their associated keys and secrets. 32 | 33 | Vaults support select symmetric and asymmetric key specs for encrypt/decrypt and sign/verify operations. 34 | 35 | Docs: https://docs.provide.services/vault`, 36 | Run: func(cmd *cobra.Command, args []string) { 37 | common.CmdExistsOrExit(cmd, args) 38 | 39 | generalPrompt(cmd, args, "") 40 | 41 | defer func() { 42 | if r := recover(); r != nil { 43 | os.Exit(1) 44 | } 45 | }() 46 | }, 47 | } 48 | 49 | func init() { 50 | VaultsCmd.AddCommand(vaultsListCmd) 51 | VaultsCmd.AddCommand(vaultsInitCmd) 52 | 53 | VaultsCmd.AddCommand(keys.KeysCmd) 54 | VaultsCmd.Flags().BoolVarP(&optional, "optional", "", false, "List all the optional flags") 55 | VaultsCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 56 | } 57 | -------------------------------------------------------------------------------- /prvd/vaults/vaults_init.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package vaults 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | provide "github.com/provideplatform/provide-go/api/vault" 26 | 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | var name string 31 | var description string 32 | var optional bool 33 | var paginate bool 34 | 35 | var vaultsInitCmd = &cobra.Command{ 36 | Use: "init --name 'My Vault' --description 'not your keys, not your crypto'", 37 | Short: "Create a new vault", 38 | Long: `Initialize a new vault`, 39 | Run: createVault, 40 | } 41 | 42 | func createVault(cmd *cobra.Command, args []string) { 43 | generalPrompt(cmd, args, promptStepInit) 44 | } 45 | 46 | func createVaultRun(cmd *cobra.Command, args []string) { 47 | 48 | token := common.RequireAPIToken() 49 | params := map[string]interface{}{ 50 | "name": name, 51 | "description": description, 52 | } 53 | vlt, err := provide.CreateVault(token, params) 54 | if err != nil { 55 | log.Printf("Failed to genereate HD wallet; %s", err.Error()) 56 | os.Exit(1) 57 | } 58 | result := fmt.Sprintf("%s\t%s\t%s\n", vlt.ID.String(), *vlt.Name, *vlt.Description) 59 | fmt.Print(result) 60 | } 61 | 62 | func init() { 63 | vaultsInitCmd.Flags().StringVar(&name, "name", "", "name of the vault") 64 | vaultsInitCmd.Flags().StringVar(&description, "description", "", "description of the vault") 65 | 66 | vaultsInitCmd.Flags().StringVar(&common.ApplicationID, "application", "", "application identifier for which the vault will be created") 67 | vaultsInitCmd.Flags().StringVar(&common.OrganizationID, "organization", "", "organization identifier for which the vault will be created") 68 | vaultsInitCmd.Flags().BoolVarP(&optional, "optional", "", false, "List all the optional flags") 69 | } 70 | -------------------------------------------------------------------------------- /prvd/vaults/vaults_list.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package vaults 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | provide "github.com/provideplatform/provide-go/api/vault" 26 | 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | var page uint64 31 | var rpp uint64 32 | 33 | var vaultsListCmd = &cobra.Command{ 34 | Use: "list", 35 | Short: "Retrieve a list of vaults", 36 | Long: `Retrieve a list of vaults scoped to the authorized API token`, 37 | Run: listVaults, 38 | } 39 | 40 | func listVaults(cmd *cobra.Command, args []string) { 41 | generalPrompt(cmd, args, promptStepList) 42 | } 43 | 44 | func listVaultsRun(cmd *cobra.Command, args []string) { 45 | token := common.RequireAPIToken() 46 | params := map[string]interface{}{ 47 | "page": fmt.Sprintf("%d", page), 48 | "rpp": fmt.Sprintf("%d", rpp), 49 | } 50 | if common.ApplicationID != "" { 51 | params["application_id"] = common.ApplicationID 52 | } 53 | if common.OrganizationID != "" { 54 | params["organization_id"] = common.OrganizationID 55 | } 56 | resp, err := provide.ListVaults(token, params) 57 | if err != nil { 58 | log.Printf("failed to retrieve vaults list; %s", err.Error()) 59 | os.Exit(1) 60 | } 61 | for i := range resp { 62 | vlt := resp[i] 63 | result := fmt.Sprintf("%s\t%s\t%s\n", vlt.ID.String(), *vlt.Name, *vlt.Description) 64 | fmt.Print(result) 65 | } 66 | } 67 | 68 | func init() { 69 | vaultsListCmd.Flags().StringVar(&common.ApplicationID, "application", "", "application identifier to filter vaults") 70 | vaultsListCmd.Flags().StringVar(&common.OrganizationID, "organization", "", "organization identifier to filter vaults") 71 | vaultsListCmd.Flags().BoolVarP(&optional, "optional", "", false, "List all the optional flags") 72 | vaultsListCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 73 | vaultsListCmd.Flags().Uint64Var(&page, "page", common.DefaultPage, "page number to retrieve") 74 | vaultsListCmd.Flags().Uint64Var(&rpp, "rpp", common.DefaultRpp, "number of vaults to retrieve per page") 75 | } 76 | -------------------------------------------------------------------------------- /prvd/vaults/vaults_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package vaults 18 | 19 | import ( 20 | "fmt" 21 | 22 | "github.com/provideplatform/provide-cli/prvd/common" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | const promptStepInit = "Initialize" 27 | const promptStepList = "List" 28 | 29 | var emptyPromptArgs = []string{promptStepInit, promptStepList} 30 | var emptyPromptLabel = "What would you like to do" 31 | 32 | // General Endpoints 33 | func generalPrompt(cmd *cobra.Command, args []string, currentStep string) { 34 | switch step := currentStep; step { 35 | case promptStepInit: 36 | if name == "" { 37 | name = common.FreeInput("Vault Name", "", common.NoValidation) 38 | } 39 | if optional { 40 | fmt.Println("Optional Flags:") 41 | if description == "" { 42 | description = common.FreeInput("Vault Description", "", common.NoValidation) 43 | } 44 | if common.ApplicationID == "" { 45 | common.RequireApplication() 46 | } 47 | if common.OrganizationID == "" { 48 | common.RequireOrganization() 49 | } 50 | } 51 | createVaultRun(cmd, args) 52 | case promptStepList: 53 | if optional { 54 | fmt.Println("Optional Flags:") 55 | if common.ApplicationID == "" { 56 | common.RequireApplication() 57 | } 58 | if common.OrganizationID == "" { 59 | common.RequireOrganization() 60 | } 61 | } 62 | page, rpp = common.PromptPagination(paginate, page, rpp) 63 | listVaultsRun(cmd, args) 64 | case "": 65 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 66 | generalPrompt(cmd, args, result) 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /prvd/wallets/wallets.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wallets 18 | 19 | import ( 20 | "os" 21 | 22 | "github.com/provideplatform/provide-cli/prvd/common" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | var WalletsCmd = &cobra.Command{ 27 | Use: "wallets", 28 | Short: "Manage HD wallets and accounts", 29 | Long: `Generate hierarchical deterministic (HD) wallets and sign transactions. 30 | 31 | More documentation forthcoming.`, 32 | Run: func(cmd *cobra.Command, args []string) { 33 | common.CmdExistsOrExit(cmd, args) 34 | generalPrompt(cmd, args, "") 35 | 36 | defer func() { 37 | if r := recover(); r != nil { 38 | os.Exit(1) 39 | } 40 | }() 41 | }, 42 | } 43 | 44 | func init() { 45 | WalletsCmd.AddCommand(walletsListCmd) 46 | WalletsCmd.AddCommand(walletsInitCmd) 47 | WalletsCmd.Flags().BoolVarP(&optional, "optional", "", false, "List all the optional flags") 48 | WalletsCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 49 | } 50 | -------------------------------------------------------------------------------- /prvd/wallets/wallets_init.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wallets 18 | 19 | import ( 20 | "encoding/hex" 21 | "fmt" 22 | "log" 23 | "os" 24 | 25 | "github.com/provideplatform/provide-cli/prvd/common" 26 | provide "github.com/provideplatform/provide-go/api/nchain" 27 | providecrypto "github.com/provideplatform/provide-go/crypto" 28 | 29 | "github.com/spf13/cobra" 30 | "github.com/spf13/viper" 31 | ) 32 | 33 | var nonCustodial bool 34 | var walletName string 35 | var purpose int 36 | var optional bool 37 | var paginate bool 38 | 39 | var walletsInitCmd = &cobra.Command{ 40 | Use: "init [--non-custodial|-nc]", 41 | Short: "Generate a new HD wallet for deterministically managing accounts, signing transactions and storing value", 42 | Long: `Initialize a new HD wallet, which may be managed by Provide or you`, 43 | Run: CreateWallet, 44 | } 45 | 46 | func CreateWallet(cmd *cobra.Command, args []string) { 47 | generalPrompt(cmd, args, promptStepInit) 48 | } 49 | 50 | func CreateWalletRun(cmd *cobra.Command, args []string) { 51 | if nonCustodial { 52 | createNonCustodialWallet() 53 | return 54 | } 55 | createCustodialWallet(cmd, args) 56 | } 57 | 58 | func createNonCustodialWallet() { 59 | publicKey, privateKey, err := providecrypto.EVMGenerateKeyPair() 60 | if err != nil { 61 | log.Printf("Failed to genereate non-custodial HD wallet; %s", err.Error()) 62 | os.Exit(1) 63 | } 64 | secret := hex.EncodeToString(providecrypto.FromECDSA(privateKey)) 65 | walletJSON, err := providecrypto.EVMMarshalEncryptedKey(providecrypto.HexToAddress(*publicKey), privateKey, secret) 66 | if err != nil { 67 | log.Printf("Failed to genereate non-custodial HD wallet; %s", err.Error()) 68 | os.Exit(1) 69 | } 70 | result := fmt.Sprintf("%s\t%s\n", *publicKey, string(walletJSON)) 71 | fmt.Print(result) 72 | } 73 | 74 | func createCustodialWallet(cmd *cobra.Command, args []string) { 75 | token := common.RequireAPIToken() 76 | params := map[string]interface{}{ 77 | "purpose": purpose, 78 | } 79 | 80 | wallet, err := provide.CreateWallet(token, params) 81 | if err != nil { 82 | log.Printf("Failed to genereate custodial HD wallet; %s", err.Error()) 83 | os.Exit(1) 84 | } 85 | common.WalletID = wallet.ID.String() 86 | result := fmt.Sprintf("Wallet %s\t%s\n", wallet.ID.String(), *wallet.PublicKey) 87 | 88 | if common.ApplicationID != "" { 89 | appWalletKey := common.BuildConfigKeyWithID(common.WalletConfigKeyPartial, common.ApplicationID) 90 | if !viper.IsSet(appWalletKey) { 91 | viper.Set(appWalletKey, wallet.ID.String()) 92 | viper.WriteConfig() 93 | } 94 | } else if common.OrganizationID != "" { 95 | orgWalletKey := common.BuildConfigKeyWithID(common.WalletConfigKeyPartial, common.OrganizationID) 96 | if !viper.IsSet(orgWalletKey) { 97 | viper.Set(orgWalletKey, wallet.ID.String()) 98 | viper.WriteConfig() 99 | } 100 | } 101 | 102 | fmt.Print(result) 103 | } 104 | 105 | func init() { 106 | walletsInitCmd.Flags().BoolVarP(&nonCustodial, "non-custodial", "", false, "if the generated HD wallet is custodial") 107 | walletsInitCmd.Flags().StringVarP(&walletName, "name", "n", "", "human-readable name to associate with the generated HD wallet") 108 | walletsInitCmd.Flags().IntVarP(&purpose, "purpose", "p", 44, "purpose of the HD wallet per BIP44") 109 | walletsInitCmd.Flags().BoolVarP(&optional, "optional", "", false, "List all the optional flags") 110 | } 111 | -------------------------------------------------------------------------------- /prvd/wallets/wallets_list.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wallets 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "os" 23 | 24 | "github.com/provideplatform/provide-cli/prvd/common" 25 | provide "github.com/provideplatform/provide-go/api/nchain" 26 | 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | var page uint64 31 | var rpp uint64 32 | 33 | var walletsListCmd = &cobra.Command{ 34 | Use: "list", 35 | Short: "Retrieve a list of custodial HD wallets", 36 | Long: `Retrieve a list of HD wallets scoped to the authorized API token`, 37 | Run: listWallets, 38 | } 39 | 40 | func listWallets(cmd *cobra.Command, args []string) { 41 | generalPrompt(cmd, args, promptStepList) 42 | } 43 | 44 | func listWalletsRun(cmd *cobra.Command, args []string) { 45 | token := common.RequireAPIToken() 46 | params := map[string]interface{}{ 47 | "page": fmt.Sprintf("%d", page), 48 | "rpp": fmt.Sprintf("%d", rpp), 49 | } 50 | if common.ApplicationID != "" { 51 | params["application_id"] = common.ApplicationID 52 | } 53 | resp, err := provide.ListWallets(token, params) 54 | if err != nil { 55 | log.Printf("Failed to retrieve wallets list; %s", err.Error()) 56 | os.Exit(1) 57 | } 58 | for i := range resp { 59 | wallet := resp[i] 60 | result := fmt.Sprintf("%s\t%s\n", wallet.ID.String(), *wallet.PublicKey) 61 | // FIXME-- when wallet.Name exists... result = fmt.Sprintf("Wallet %s\t%s - %s\n", wallet.Name, wallet.ID.String(), *wallet.Address) 62 | fmt.Print(result) 63 | } 64 | } 65 | 66 | func init() { 67 | walletsListCmd.Flags().StringVar(&common.ApplicationID, "application", "", "application identifier to filter HD wallets") 68 | walletsListCmd.Flags().BoolVarP(&optional, "optional", "", false, "List all the optional flags") 69 | walletsListCmd.Flags().BoolVarP(&paginate, "paginate", "", false, "List pagination flags") 70 | walletsListCmd.Flags().Uint64Var(&page, "page", common.DefaultPage, "page number to retrieve") 71 | walletsListCmd.Flags().Uint64Var(&rpp, "rpp", common.DefaultRpp, "number of wallets to retrieve per page") 72 | } 73 | -------------------------------------------------------------------------------- /prvd/wallets/wallets_prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package wallets 18 | 19 | import ( 20 | "fmt" 21 | "strconv" 22 | 23 | "github.com/provideplatform/provide-cli/prvd/common" 24 | 25 | "github.com/spf13/cobra" 26 | ) 27 | 28 | const promptStepCustody = "Custody" 29 | const promptStepInit = "Initialize" 30 | const promptStepList = "List" 31 | 32 | var custodyPromptArgs = []string{"No", "Yes"} 33 | var custodyPromptLabel = "Would you like your wallet to be non-custodial?" 34 | 35 | var walletTypePromptArgs = []string{"Managed", "Decentralised"} 36 | var walletTypeLabel = "What type of Wallet would you like to create" 37 | 38 | var emptyPromptArgs = []string{promptStepInit, promptStepList} 39 | var emptyPromptLabel = "What would you like to do" 40 | 41 | // General Endpoints 42 | func generalPrompt(cmd *cobra.Command, args []string, step string) { 43 | switch step { 44 | case promptStepInit: 45 | common.SelectInput(walletTypePromptArgs, walletTypeLabel) 46 | generalPrompt(cmd, args, promptStepCustody) 47 | case promptStepCustody: 48 | if optional { 49 | fmt.Println("Optional Flags:") 50 | if !nonCustodial { 51 | nonCustodial = common.SelectInput(custodyPromptArgs, custodyPromptLabel) == "Yes" 52 | } 53 | if walletName == "" { 54 | walletName = common.FreeInput("Wallet Name", "", common.NoValidation) 55 | } 56 | if purpose == 44 { 57 | purpose, _ = strconv.Atoi(common.FreeInput("Wallet Purpose", "44", common.NumberValidation)) 58 | } 59 | } 60 | CreateWalletRun(cmd, args) 61 | case promptStepList: 62 | if optional { 63 | fmt.Println("Optional Flags:") 64 | if common.ApplicationID == "" { 65 | common.RequireApplication() 66 | } 67 | } 68 | page, rpp = common.PromptPagination(paginate, page, rpp) 69 | listWalletsRun(cmd, args) 70 | case "": 71 | result := common.SelectInput(emptyPromptArgs, emptyPromptLabel) 72 | generalPrompt(cmd, args, result) 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /prvdnetwork/root.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package prvdnetwork 18 | 19 | import ( 20 | "fmt" 21 | "os" 22 | 23 | "github.com/spf13/cobra" 24 | 25 | "github.com/provideplatform/provide-cli/prvd/accounts" 26 | "github.com/provideplatform/provide-cli/prvd/common" 27 | "github.com/provideplatform/provide-cli/prvd/vaults" 28 | ) 29 | 30 | var rootCmd = &cobra.Command{ 31 | Use: "prvdnetwork", 32 | Short: "provide.network cli", 33 | Long: fmt.Sprintf(`%s 34 | 35 | The provide.network CLI exposes commands to run and manage full and validator nodes on permissionless provide.network. 36 | 37 | Run with the --help flag to see available options`, common.ASCIIBanner), 38 | } 39 | 40 | // Execute the default command path 41 | func Execute() { 42 | if err := rootCmd.Execute(); err != nil { 43 | fmt.Println(err) 44 | os.Exit(1) 45 | } 46 | } 47 | 48 | func init() { 49 | cobra.OnInitialize(common.InitConfig) 50 | 51 | rootCmd.PersistentFlags().BoolVarP(&common.Verbose, "verbose", "v", false, "enable verbose output") 52 | rootCmd.PersistentFlags().StringVarP(&common.CfgFile, "config", "c", "", "config file (default is $HOME/.provide-cli.yaml)") 53 | 54 | rootCmd.AddCommand(accounts.AccountsCmd) 55 | // rootCmd.AddCommand(axiom.BaselineCmd) 56 | // rootCmd.AddCommand(networks.NetworksCmd) 57 | // rootCmd.AddCommand(nodes.NodesCmd) 58 | // rootCmd.AddCommand(shell.ShellCmd) 59 | rootCmd.AddCommand(vaults.VaultsCmd) 60 | // rootCmd.AddCommand(wallets.WalletsCmd) 61 | 62 | common.CacheCommands(rootCmd) 63 | } 64 | -------------------------------------------------------------------------------- /test/shell_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Provide Technologies Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package test 18 | 19 | import ( 20 | "testing" 21 | 22 | "github.com/provideplatform/provide-cli/prvd/shell" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | func TestShell(t *testing.T) { 27 | type args struct { 28 | cmd *cobra.Command 29 | args []string 30 | } 31 | tests := []struct { 32 | name string 33 | args args 34 | }{ 35 | { 36 | name: "prvd wallets", 37 | args: args{ 38 | cmd: shell.ShellCmd, 39 | args: []string{}, 40 | }, 41 | }, 42 | } 43 | for _, tt := range tests { 44 | t.Run(tt.name, func(t *testing.T) { 45 | tt.args.cmd.SetArgs(tt.args.args) 46 | tt.args.cmd.Execute() 47 | // tt.args.cmd.RunE(tt.args.cmd, tt.args.args) 48 | }) 49 | } 50 | } 51 | --------------------------------------------------------------------------------