diff --git a/cmd/add.go b/cmd/add.go index e1450f821..570346992 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -29,7 +29,7 @@ import ( const clientTimeOut = 5 * time.Second -var resName, resType, resURL, resCredentials, resMetadata string +var resName, resType string var addCmd = &cobra.Command{ Use: "add", @@ -58,7 +58,7 @@ var addResourceCmd = &cobra.Command{ return err } - r := meroxa.Resource{ + r := meroxa.CreateResourceInput{ Type: resType, Name: resName, URL: resURL, diff --git a/cmd/root.go b/cmd/root.go index 2a2481591..8b81877b3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -17,10 +17,11 @@ package cmd import ( "fmt" - "github.com/spf13/pflag" "os" "strings" + "github.com/spf13/pflag" + "github.com/spf13/cobra" homedir "github.com/mitchellh/go-homedir" @@ -41,6 +42,9 @@ var ( cfgFile string source string destination string + resURL string + resMetadata string + resCredentials string flagRootOutputJSON bool cfg *viper.Viper ) diff --git a/cmd/update.go b/cmd/update.go index 7998208d3..823b9299b 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -2,10 +2,13 @@ package cmd import ( "context" + "encoding/json" "errors" "fmt" "time" + "github.com/meroxa/meroxa-go" + "github.com/meroxa/cli/display" "github.com/spf13/cobra" ) @@ -65,6 +68,82 @@ var updateConnectorCmd = &cobra.Command{ }, } +var updateResourceCmd = &cobra.Command{ + Use: "resource ", + Short: "Update a resource", + Long: `Use the update command to update various Meroxa resources.`, + Aliases: []string{"resources"}, + // TODO: Change the design so a new name for the resource could be set + // meroxa update resource --name + PreRunE: func(cmd *cobra.Command, args []string) error { + if len(args) < 1 || (resURL == "" && resMetadata == "" && resCredentials == "") { + return errors.New("requires a resource name and either `--metadata`, `--url` or `--credentials` to update the resource \n\nUsage:\n meroxa update resource [--url | --metadata | --credentials ]") + } + + return nil + }, + RunE: func(cmd *cobra.Command, args []string) error { + // Resource Name + resName = args[0] + c, err := client() + + if err != nil { + return err + } + ctx := context.Background() + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + + var res meroxa.UpdateResourceInput + + // If url was provided, update it + if resURL != "" { + res.URL = resURL + } + + // TODO: Figure out best way to handle creds and metadata + // Get credentials (expect a JSON string) + if resCredentials != "" { + var creds meroxa.Credentials + err = json.Unmarshal([]byte(resCredentials), &creds) + if err != nil { + return err + } + + res.Credentials = &creds + } + + // If metadata was provided, update it + if resMetadata != "" { + var metadata map[string]string + err = json.Unmarshal([]byte(resMetadata), &metadata) + if err != nil { + return err + } + + res.Metadata = metadata + } + + // call meroxa-go to update resource + if !flagRootOutputJSON { + fmt.Printf("Updating %s resource...\n", resName) + } + + resource, err := c.UpdateResource(ctx, resName, res) + if err != nil { + return err + } + + if flagRootOutputJSON { + display.JSONPrint(resource) + } else { + fmt.Printf("Resource %s successfully updated!\n", resName) + } + + return nil + }, +} + var updatePipelineCmd = &cobra.Command{ Use: "pipeline --state ", Aliases: []string{"pipelines"}, @@ -130,4 +209,11 @@ func init() { updateCmd.AddCommand(updatePipelineCmd) updatePipelineCmd.Flags().StringVarP(&state, "state", "", "", "pipeline state") updatePipelineCmd.MarkFlagRequired("state") + + updateCmd.AddCommand(updateResourceCmd) + RootCmd.AddCommand(updateCmd) + + updateResourceCmd.Flags().StringVarP(&resURL, "url", "u", "", "resource url") + updateResourceCmd.Flags().StringVarP(&resMetadata, "metadata", "m", "", "resource metadata") + updateResourceCmd.Flags().StringVarP(&resCredentials, "credentials", "", "", "resource credentials") } diff --git a/display/display.go b/display/display.go index f51e2c667..8dca3783c 100644 --- a/display/display.go +++ b/display/display.go @@ -70,8 +70,8 @@ func PrintResourcesTable(resources []*meroxa.Resource) { table.Header = &simpletable.Header{ Cells: []*simpletable.Cell{ {Align: simpletable.AlignCenter, Text: "ID"}, - {Align: simpletable.AlignCenter, Text: "TYPE"}, {Align: simpletable.AlignCenter, Text: "NAME"}, + {Align: simpletable.AlignCenter, Text: "TYPE"}, {Align: simpletable.AlignCenter, Text: "URL"}, }, } @@ -79,8 +79,8 @@ func PrintResourcesTable(resources []*meroxa.Resource) { for _, res := range resources { r := []*simpletable.Cell{ {Align: simpletable.AlignRight, Text: fmt.Sprintf("%d", res.ID)}, - {Text: res.Type}, {Text: res.Name}, + {Text: res.Type}, {Text: res.URL}, } diff --git a/docs/commands/meroxa.md b/docs/commands/meroxa.md index 25964a828..467c00467 100644 --- a/docs/commands/meroxa.md +++ b/docs/commands/meroxa.md @@ -36,6 +36,7 @@ meroxa list resource-types * [meroxa open](meroxa_open.md) - Open in a web browser * [meroxa remove](meroxa_remove.md) - Remove a component * [meroxa update](meroxa_update.md) - Update a component +* [meroxa update](meroxa_update.md) - Update a component * [meroxa version](meroxa_version.md) - Display the Meroxa CLI version -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_add.md b/docs/commands/meroxa_add.md index 9fb53812b..9a41373b0 100644 --- a/docs/commands/meroxa_add.md +++ b/docs/commands/meroxa_add.md @@ -20,4 +20,4 @@ Add a resource to your Meroxa resource catalog * [meroxa](meroxa.md) - The Meroxa CLI * [meroxa add resource](meroxa_add_resource.md) - Add a resource to your Meroxa resource catalog -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_add_resource.md b/docs/commands/meroxa_add_resource.md index e4672286e..826eb792f 100644 --- a/docs/commands/meroxa_add_resource.md +++ b/docs/commands/meroxa_add_resource.md @@ -42,4 +42,4 @@ meroxa add resource slack --type url -u $WEBHOOK_URL * [meroxa add](meroxa_add.md) - Add a resource to your Meroxa resource catalog -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_api.md b/docs/commands/meroxa_api.md index d9fb62786..f6373a8aa 100644 --- a/docs/commands/meroxa_api.md +++ b/docs/commands/meroxa_api.md @@ -31,4 +31,4 @@ meroxa api POST /v1/endpoints '{"protocol": "HTTP", "stream": "resource-2-499379 * [meroxa](meroxa.md) - The Meroxa CLI -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_billing.md b/docs/commands/meroxa_billing.md index d484ec46d..4cf56ee83 100644 --- a/docs/commands/meroxa_billing.md +++ b/docs/commands/meroxa_billing.md @@ -23,4 +23,4 @@ meroxa billing [flags] * [meroxa](meroxa.md) - The Meroxa CLI -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_completion.md b/docs/commands/meroxa_completion.md index 34e6b3605..53142ae59 100644 --- a/docs/commands/meroxa_completion.md +++ b/docs/commands/meroxa_completion.md @@ -57,4 +57,4 @@ meroxa completion [bash|zsh|fish|powershell] * [meroxa](meroxa.md) - The Meroxa CLI -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_connect.md b/docs/commands/meroxa_connect.md index 26225e20f..a05365fac 100644 --- a/docs/commands/meroxa_connect.md +++ b/docs/commands/meroxa_connect.md @@ -42,4 +42,4 @@ meroxa connect --from --to [flags] * [meroxa](meroxa.md) - The Meroxa CLI -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_create.md b/docs/commands/meroxa_create.md index 0e50093cb..cab2e4f2f 100644 --- a/docs/commands/meroxa_create.md +++ b/docs/commands/meroxa_create.md @@ -27,4 +27,4 @@ including connectors. * [meroxa create endpoint](meroxa_create_endpoint.md) - Create an endpoint * [meroxa create pipeline](meroxa_create_pipeline.md) - Create a pipeline -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_create_connector.md b/docs/commands/meroxa_create_connector.md index 98e6e8305..a8a051c18 100644 --- a/docs/commands/meroxa_create_connector.md +++ b/docs/commands/meroxa_create_connector.md @@ -38,4 +38,4 @@ meroxa create connector [] --to pg2redshift --input order * [meroxa create](meroxa_create.md) - Create Meroxa pipeline components -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_create_endpoint.md b/docs/commands/meroxa_create_endpoint.md index e20c72bcf..2750485da 100644 --- a/docs/commands/meroxa_create_endpoint.md +++ b/docs/commands/meroxa_create_endpoint.md @@ -36,4 +36,4 @@ meroxa create endpoint my-endpoint --protocol http --stream my-stream * [meroxa create](meroxa_create.md) - Create Meroxa pipeline components -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_create_pipeline.md b/docs/commands/meroxa_create_pipeline.md index 52c791e0f..e01d77b04 100644 --- a/docs/commands/meroxa_create_pipeline.md +++ b/docs/commands/meroxa_create_pipeline.md @@ -24,4 +24,4 @@ meroxa create pipeline [flags] * [meroxa create](meroxa_create.md) - Create Meroxa pipeline components -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_delete.md b/docs/commands/meroxa_delete.md deleted file mode 100644 index 563afe001..000000000 --- a/docs/commands/meroxa_delete.md +++ /dev/null @@ -1,29 +0,0 @@ -## meroxa delete - -Delete a component - -### Synopsis - -Deprovision a component of the Meroxa platform, including pipelines, - resources, connectors, functions, etc... - -### Options - -``` - -h, --help help for delete -``` - -### Options inherited from parent commands - -``` - --json output json -``` - -### SEE ALSO - -* [meroxa](meroxa.md) - The Meroxa CLI -* [meroxa delete connector](meroxa_delete_connector.md) - Delete connector -* [meroxa delete pipeline](meroxa_delete_pipeline.md) - Delete pipeline -* [meroxa delete resource](meroxa_delete_resource.md) - Delete resource - -###### Auto generated by spf13/cobra on 17-Feb-2021 diff --git a/docs/commands/meroxa_delete_connector.md b/docs/commands/meroxa_delete_connector.md deleted file mode 100644 index 2e0163f8b..000000000 --- a/docs/commands/meroxa_delete_connector.md +++ /dev/null @@ -1,25 +0,0 @@ -## meroxa delete connector - -Delete connector - -``` -meroxa delete connector [flags] -``` - -### Options - -``` - -h, --help help for connector -``` - -### Options inherited from parent commands - -``` - --json output json -``` - -### SEE ALSO - -* [meroxa delete](meroxa_delete.md) - Delete a component - -###### Auto generated by spf13/cobra on 17-Feb-2021 diff --git a/docs/commands/meroxa_delete_pipeline.md b/docs/commands/meroxa_delete_pipeline.md deleted file mode 100644 index b3a2129eb..000000000 --- a/docs/commands/meroxa_delete_pipeline.md +++ /dev/null @@ -1,25 +0,0 @@ -## meroxa delete pipeline - -Delete pipeline - -``` -meroxa delete pipeline [flags] -``` - -### Options - -``` - -h, --help help for pipeline -``` - -### Options inherited from parent commands - -``` - --json output json -``` - -### SEE ALSO - -* [meroxa delete](meroxa_delete.md) - Delete a component - -###### Auto generated by spf13/cobra on 17-Feb-2021 diff --git a/docs/commands/meroxa_delete_resource.md b/docs/commands/meroxa_delete_resource.md deleted file mode 100644 index 19c8b8c0b..000000000 --- a/docs/commands/meroxa_delete_resource.md +++ /dev/null @@ -1,25 +0,0 @@ -## meroxa delete resource - -Delete resource - -``` -meroxa delete resource [flags] -``` - -### Options - -``` - -h, --help help for resource -``` - -### Options inherited from parent commands - -``` - --json output json -``` - -### SEE ALSO - -* [meroxa delete](meroxa_delete.md) - Delete a component - -###### Auto generated by spf13/cobra on 17-Feb-2021 diff --git a/docs/commands/meroxa_describe.md b/docs/commands/meroxa_describe.md index 3a034569e..64472e0df 100644 --- a/docs/commands/meroxa_describe.md +++ b/docs/commands/meroxa_describe.md @@ -26,4 +26,4 @@ Describe a component of the Meroxa data platform, including resources and connec * [meroxa describe endpoint](meroxa_describe_endpoint.md) - Describe Endpoint * [meroxa describe resource](meroxa_describe_resource.md) - Describe resource -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_describe_connector.md b/docs/commands/meroxa_describe_connector.md index 85180ccd7..6c9d9e4c0 100644 --- a/docs/commands/meroxa_describe_connector.md +++ b/docs/commands/meroxa_describe_connector.md @@ -23,4 +23,4 @@ meroxa describe connector [name] [flags] * [meroxa describe](meroxa_describe.md) - Describe a component -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_describe_endpoint.md b/docs/commands/meroxa_describe_endpoint.md index 7d0d776bf..97a248d77 100644 --- a/docs/commands/meroxa_describe_endpoint.md +++ b/docs/commands/meroxa_describe_endpoint.md @@ -23,4 +23,4 @@ meroxa describe endpoint [flags] * [meroxa describe](meroxa_describe.md) - Describe a component -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_describe_resource.md b/docs/commands/meroxa_describe_resource.md index b49e41eb4..cae696491 100644 --- a/docs/commands/meroxa_describe_resource.md +++ b/docs/commands/meroxa_describe_resource.md @@ -23,4 +23,4 @@ meroxa describe resource [flags] * [meroxa describe](meroxa_describe.md) - Describe a component -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_list.md b/docs/commands/meroxa_list.md index 227ef056c..a49724d28 100644 --- a/docs/commands/meroxa_list.md +++ b/docs/commands/meroxa_list.md @@ -30,4 +30,4 @@ List the components of the Meroxa platform, including pipelines, * [meroxa list resources](meroxa_list_resources.md) - List resources * [meroxa list transforms](meroxa_list_transforms.md) - List transforms -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_list_connectors.md b/docs/commands/meroxa_list_connectors.md index c8e796d02..5783a733d 100644 --- a/docs/commands/meroxa_list_connectors.md +++ b/docs/commands/meroxa_list_connectors.md @@ -23,4 +23,4 @@ meroxa list connectors [flags] * [meroxa list](meroxa_list.md) - List components -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_list_endpoint.md b/docs/commands/meroxa_list_endpoint.md index a70c6ca97..9498370cd 100644 --- a/docs/commands/meroxa_list_endpoint.md +++ b/docs/commands/meroxa_list_endpoint.md @@ -23,4 +23,4 @@ meroxa list endpoint [flags] * [meroxa list](meroxa_list.md) - List components -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_list_pipelines.md b/docs/commands/meroxa_list_pipelines.md index 63ea45eb6..53f1f4871 100644 --- a/docs/commands/meroxa_list_pipelines.md +++ b/docs/commands/meroxa_list_pipelines.md @@ -23,4 +23,4 @@ meroxa list pipelines [flags] * [meroxa list](meroxa_list.md) - List components -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_list_resource-types.md b/docs/commands/meroxa_list_resource-types.md index 3b95ec280..bbce6f2ec 100644 --- a/docs/commands/meroxa_list_resource-types.md +++ b/docs/commands/meroxa_list_resource-types.md @@ -23,4 +23,4 @@ meroxa list resource-types [flags] * [meroxa list](meroxa_list.md) - List components -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_list_resources.md b/docs/commands/meroxa_list_resources.md index 5043453a5..77f0acf8c 100644 --- a/docs/commands/meroxa_list_resources.md +++ b/docs/commands/meroxa_list_resources.md @@ -23,4 +23,4 @@ meroxa list resources [flags] * [meroxa list](meroxa_list.md) - List components -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_list_transforms.md b/docs/commands/meroxa_list_transforms.md index 61495553c..ea0c037c8 100644 --- a/docs/commands/meroxa_list_transforms.md +++ b/docs/commands/meroxa_list_transforms.md @@ -23,4 +23,4 @@ meroxa list transforms [flags] * [meroxa list](meroxa_list.md) - List components -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_login.md b/docs/commands/meroxa_login.md index 8206b5874..9a9c0ff2a 100644 --- a/docs/commands/meroxa_login.md +++ b/docs/commands/meroxa_login.md @@ -23,4 +23,4 @@ meroxa login [flags] * [meroxa](meroxa.md) - The Meroxa CLI -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_login_whoami.md b/docs/commands/meroxa_login_whoami.md deleted file mode 100644 index 341b14620..000000000 --- a/docs/commands/meroxa_login_whoami.md +++ /dev/null @@ -1,27 +0,0 @@ -## meroxa login whoami - -Display effective username - -``` -meroxa login whoami [flags] -``` - -### Options - -``` - -h, --help help for whoami -``` - -### Options inherited from parent commands - -``` - --json output json - --password string password - --username string username -``` - -### SEE ALSO - -* [meroxa login](meroxa_login.md) - Log into the Meroxa platform - -###### Auto generated by spf13/cobra on 2-Mar-2021 diff --git a/docs/commands/meroxa_logout.md b/docs/commands/meroxa_logout.md index 45257d041..8525e989a 100644 --- a/docs/commands/meroxa_logout.md +++ b/docs/commands/meroxa_logout.md @@ -23,4 +23,4 @@ meroxa logout [flags] * [meroxa](meroxa.md) - The Meroxa CLI -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_logs.md b/docs/commands/meroxa_logs.md index e9826610c..df3ebd18e 100644 --- a/docs/commands/meroxa_logs.md +++ b/docs/commands/meroxa_logs.md @@ -20,4 +20,4 @@ Print logs for a component * [meroxa](meroxa.md) - The Meroxa CLI * [meroxa logs connector](meroxa_logs_connector.md) - Print logs for a connector -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_logs_connector.md b/docs/commands/meroxa_logs_connector.md index b792cd34f..47b533a2f 100644 --- a/docs/commands/meroxa_logs_connector.md +++ b/docs/commands/meroxa_logs_connector.md @@ -23,4 +23,4 @@ meroxa logs connector [flags] * [meroxa logs](meroxa_logs.md) - Print logs for a component -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_open.md b/docs/commands/meroxa_open.md index 70c154f77..a8f999222 100644 --- a/docs/commands/meroxa_open.md +++ b/docs/commands/meroxa_open.md @@ -20,4 +20,4 @@ Open in a web browser * [meroxa](meroxa.md) - The Meroxa CLI * [meroxa open billing](meroxa_open_billing.md) - Open your billing page in a web browser -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_open_billing.md b/docs/commands/meroxa_open_billing.md index b0d4638f0..37e2ea789 100644 --- a/docs/commands/meroxa_open_billing.md +++ b/docs/commands/meroxa_open_billing.md @@ -23,4 +23,4 @@ meroxa open billing [flags] * [meroxa open](meroxa_open.md) - Open in a web browser -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_remove.md b/docs/commands/meroxa_remove.md index 217b7ffba..3ed1e05d1 100644 --- a/docs/commands/meroxa_remove.md +++ b/docs/commands/meroxa_remove.md @@ -28,4 +28,4 @@ Deprovision a component of the Meroxa platform, including pipelines, * [meroxa remove pipeline](meroxa_remove_pipeline.md) - Remove pipeline * [meroxa remove resource](meroxa_remove_resource.md) - Remove resource -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_remove_connector.md b/docs/commands/meroxa_remove_connector.md index 79869f03f..e5a13aac6 100644 --- a/docs/commands/meroxa_remove_connector.md +++ b/docs/commands/meroxa_remove_connector.md @@ -23,4 +23,4 @@ meroxa remove connector [flags] * [meroxa remove](meroxa_remove.md) - Remove a component -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_remove_endpoint.md b/docs/commands/meroxa_remove_endpoint.md index b4c5094b2..04f195eab 100644 --- a/docs/commands/meroxa_remove_endpoint.md +++ b/docs/commands/meroxa_remove_endpoint.md @@ -23,4 +23,4 @@ meroxa remove endpoint [flags] * [meroxa remove](meroxa_remove.md) - Remove a component -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_remove_pipeline.md b/docs/commands/meroxa_remove_pipeline.md index 4aba437ba..a9bd93c70 100644 --- a/docs/commands/meroxa_remove_pipeline.md +++ b/docs/commands/meroxa_remove_pipeline.md @@ -23,4 +23,4 @@ meroxa remove pipeline [flags] * [meroxa remove](meroxa_remove.md) - Remove a component -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_remove_resource.md b/docs/commands/meroxa_remove_resource.md index febf9b00a..e2b87a633 100644 --- a/docs/commands/meroxa_remove_resource.md +++ b/docs/commands/meroxa_remove_resource.md @@ -23,4 +23,4 @@ meroxa remove resource [flags] * [meroxa remove](meroxa_remove.md) - Remove a component -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_signup.md b/docs/commands/meroxa_signup.md deleted file mode 100644 index dc8a244f8..000000000 --- a/docs/commands/meroxa_signup.md +++ /dev/null @@ -1,28 +0,0 @@ -## meroxa signup - -Sign up to the Meroxa platform - -``` -meroxa signup [flags] -``` - -### Options - -``` - --email string email - -h, --help help for signup - --password string password - --username string username -``` - -### Options inherited from parent commands - -``` - --json output json -``` - -### SEE ALSO - -* [meroxa](meroxa.md) - The Meroxa CLI - -###### Auto generated by spf13/cobra on 2-Mar-2021 diff --git a/docs/commands/meroxa_update.md b/docs/commands/meroxa_update.md index 6cb1da3f5..d48ee85a5 100644 --- a/docs/commands/meroxa_update.md +++ b/docs/commands/meroxa_update.md @@ -24,5 +24,6 @@ Update a component of the Meroxa platform, including connectors * [meroxa](meroxa.md) - The Meroxa CLI * [meroxa update connector](meroxa_update_connector.md) - Update connector state * [meroxa update pipeline](meroxa_update_pipeline.md) - Update pipeline state +* [meroxa update resource](meroxa_update_resource.md) - Update a resource -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_update_connector.md b/docs/commands/meroxa_update_connector.md index 166da149b..2f4d1168f 100644 --- a/docs/commands/meroxa_update_connector.md +++ b/docs/commands/meroxa_update_connector.md @@ -24,4 +24,4 @@ meroxa update connector --state [flags] * [meroxa update](meroxa_update.md) - Update a component -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_update_pipeline.md b/docs/commands/meroxa_update_pipeline.md index 0c436bd6a..f003b2207 100644 --- a/docs/commands/meroxa_update_pipeline.md +++ b/docs/commands/meroxa_update_pipeline.md @@ -24,4 +24,4 @@ meroxa update pipeline --state [flags] * [meroxa update](meroxa_update.md) - Update a component -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_update_resource.md b/docs/commands/meroxa_update_resource.md new file mode 100644 index 000000000..228180edd --- /dev/null +++ b/docs/commands/meroxa_update_resource.md @@ -0,0 +1,33 @@ +## meroxa update resource + +Update a resource + +### Synopsis + +Use the update command to update various Meroxa resources. + +``` +meroxa update resource [flags] +``` + +### Options + +``` + --credentials string resource credentials + -h, --help help for resource + -m, --metadata string resource metadata + -u, --url string resource url +``` + +### Options inherited from parent commands + +``` + --config string config file (default is $HOME/meroxa.env) + --json output json +``` + +### SEE ALSO + +* [meroxa update](meroxa_update.md) - Update a component + +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/docs/commands/meroxa_version.md b/docs/commands/meroxa_version.md index b2db885bf..94b0b6c22 100644 --- a/docs/commands/meroxa_version.md +++ b/docs/commands/meroxa_version.md @@ -23,4 +23,4 @@ meroxa version [flags] * [meroxa](meroxa.md) - The Meroxa CLI -###### Auto generated by spf13/cobra on 8-Mar-2021 +###### Auto generated by spf13/cobra on 10-Mar-2021 diff --git a/go.mod b/go.mod index 9f49a883f..96580bf59 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/magiconair/properties v1.8.4 // indirect github.com/mattn/go-colorable v0.1.8 // indirect github.com/mattn/go-runewidth v0.0.10 // indirect - github.com/meroxa/meroxa-go v0.0.0-20210305201333-97108881ba68 + github.com/meroxa/meroxa-go v0.0.0-20210310192144-e8c597791043 github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/mapstructure v1.4.1 // indirect github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20170819232839-0fbfe93532da diff --git a/go.sum b/go.sum index 8e8009ca7..ed1d86d9f 100644 --- a/go.sum +++ b/go.sum @@ -134,8 +134,20 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg= github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/meroxa/meroxa-go v0.0.0-20210305201333-97108881ba68 h1:4mqC6rk0qnILN7g5exZn0+Hk0aM47ZvViEN5ftOzwXk= -github.com/meroxa/meroxa-go v0.0.0-20210305201333-97108881ba68/go.mod h1:yzdHMk8vDvV8iODTBDpkhpGoZed2aB+WR7y7fIN88pc= +github.com/meroxa/meroxa-go v0.0.0-20210309114201-3ed87e1ff88b h1:4CNeZ1/4OiNfeUhDT21MRGiXWgOmRjJdfyZZhqYDa+k= +github.com/meroxa/meroxa-go v0.0.0-20210309114201-3ed87e1ff88b/go.mod h1:yzdHMk8vDvV8iODTBDpkhpGoZed2aB+WR7y7fIN88pc= +github.com/meroxa/meroxa-go v0.0.0-20210309125454-78b90cd6af61 h1:stfeTt0418Xw0OflxIVlxOD25Dz423E41wCkqjeNBLQ= +github.com/meroxa/meroxa-go v0.0.0-20210309125454-78b90cd6af61/go.mod h1:yzdHMk8vDvV8iODTBDpkhpGoZed2aB+WR7y7fIN88pc= +github.com/meroxa/meroxa-go v0.0.0-20210309143530-5dee50a9ca16 h1:bSznkjHkVkuEIlbrTwe0UENkS2rMDEwoAB4TYlHUatQ= +github.com/meroxa/meroxa-go v0.0.0-20210309143530-5dee50a9ca16/go.mod h1:yzdHMk8vDvV8iODTBDpkhpGoZed2aB+WR7y7fIN88pc= +github.com/meroxa/meroxa-go v0.0.0-20210309173620-858a7c0fe213 h1:Xsu+SvY2Wmizkva7ycV+avmY27PzT0nS10mR+6GHhk0= +github.com/meroxa/meroxa-go v0.0.0-20210309173620-858a7c0fe213/go.mod h1:yzdHMk8vDvV8iODTBDpkhpGoZed2aB+WR7y7fIN88pc= +github.com/meroxa/meroxa-go v0.0.0-20210310110921-bbd1a6045180 h1:9/Zi6yjEI11evW2YthAOocmn2E09zk0khSpPbSINiCE= +github.com/meroxa/meroxa-go v0.0.0-20210310110921-bbd1a6045180/go.mod h1:yzdHMk8vDvV8iODTBDpkhpGoZed2aB+WR7y7fIN88pc= +github.com/meroxa/meroxa-go v0.0.0-20210310111217-25506b3fff85 h1:0ulO5q5wNEx21rSq/GdojzqoFytE+DVqBneUW4VGmQg= +github.com/meroxa/meroxa-go v0.0.0-20210310111217-25506b3fff85/go.mod h1:yzdHMk8vDvV8iODTBDpkhpGoZed2aB+WR7y7fIN88pc= +github.com/meroxa/meroxa-go v0.0.0-20210310192144-e8c597791043 h1:kzCaObyQltuIByPUguvReWtUGwC10WPI0g6QB0Auzsc= +github.com/meroxa/meroxa-go v0.0.0-20210310192144-e8c597791043/go.mod h1:yzdHMk8vDvV8iODTBDpkhpGoZed2aB+WR7y7fIN88pc= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= @@ -163,7 +175,6 @@ github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4/go.mod h1:N6UoU20jOqgg github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= @@ -189,9 +200,7 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 h1:JIAuq3EEf9cgbU6AtGPK4CTG3Zf6CKMNqf0MHTggAUA= github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= @@ -217,7 +226,6 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= @@ -344,7 +352,6 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= diff --git a/vendor/github.com/meroxa/meroxa-go/api_errors.go b/vendor/github.com/meroxa/meroxa-go/api_errors.go index 79b8e72be..0a4e61eb0 100644 --- a/vendor/github.com/meroxa/meroxa-go/api_errors.go +++ b/vendor/github.com/meroxa/meroxa-go/api_errors.go @@ -33,7 +33,7 @@ func parseErrorFromBody(resp *http.Response) (error, error) { if err != nil { // In cases we didn't receive a proper JSON response if _, ok := err.(*json.SyntaxError); ok { - return nil, errors.New(fmt.Sprintf("error: %s %s", resp.Proto, resp.Status)) + return nil, errors.New(fmt.Sprintf("%s %s", resp.Proto, resp.Status)) } return nil, err diff --git a/vendor/github.com/meroxa/meroxa-go/resource.go b/vendor/github.com/meroxa/meroxa-go/resource.go index 54fbe8b72..825c46677 100644 --- a/vendor/github.com/meroxa/meroxa-go/resource.go +++ b/vendor/github.com/meroxa/meroxa-go/resource.go @@ -10,7 +10,7 @@ import ( "strings" ) -const resourcesBasePath = "/v1/resources" +const ResourcesBasePath = "/v1/resources" var ErrMissingScheme = errors.New("URL scheme required") @@ -25,6 +25,16 @@ type Credentials struct { UseSSL bool `json:"ssl"` } +// CreateResourceInput represents the input for a Meroxa Resource type we're creating within the Meroxa API +type CreateResourceInput struct { + ID int `json:"id"` + Type string `json:"type"` + Name string `json:"name"` + URL string `json:"url"` + Credentials *Credentials `json:"credentials,omitempty"` + Metadata map[string]string `json:"metadata,omitempty"` +} + // Resource represents the Meroxa Resource type within the Meroxa API type Resource struct { ID int `json:"id"` @@ -35,8 +45,16 @@ type Resource struct { Metadata map[string]string `json:"metadata,omitempty"` } -// CreateResource provisions a new Resource from the given Resource struct -func (c *Client) CreateResource(ctx context.Context, resource *Resource) (*Resource, error) { +// UpdateResourceInput represents the Meroxa Resource we're updating in the Meroxa API +type UpdateResourceInput struct { + Name string `json:"name,omitempty"` // TODO: Update this via CLI + URL string `json:"url,omitempty"` + Metadata map[string]string `json:"metadata,omitempty"` + Credentials *Credentials `json:"credentials,omitempty"` +} + +// CreateResource provisions a new Resource from the given CreateResourceInput struct +func (c *Client) CreateResource(ctx context.Context, resource *CreateResourceInput) (*Resource, error) { // url encode url username/password if needed var err error resource.URL, err = encodeURLCreds(resource.URL) @@ -44,7 +62,38 @@ func (c *Client) CreateResource(ctx context.Context, resource *Resource) (*Resou return nil, err } - resp, err := c.makeRequest(ctx, http.MethodPost, resourcesBasePath, resource, nil) + resp, err := c.makeRequest(ctx, http.MethodPost, ResourcesBasePath, resource, nil) + if err != nil { + return nil, err + } + + err = handleAPIErrors(resp) + if err != nil { + return nil, err + } + + var r Resource + err = json.NewDecoder(resp.Body).Decode(&r) + if err != nil { + return nil, err + } + + return &r, nil +} + +func (c *Client) UpdateResource(ctx context.Context, key string, resourceToUpdate UpdateResourceInput) (*Resource, error) { + // url encode url username/password if needed + var err error + + if resourceToUpdate.URL != "" { + resourceToUpdate.URL, err = encodeURLCreds(resourceToUpdate.URL) + + if err != nil { + return nil, err + } + } + + resp, err := c.makeRequest(ctx, http.MethodPatch, fmt.Sprintf("%s/%s", ResourcesBasePath, key), resourceToUpdate, nil) if err != nil { return nil, err } @@ -65,7 +114,7 @@ func (c *Client) CreateResource(ctx context.Context, resource *Resource) (*Resou // ListResources returns an array of Resources (scoped to the calling user) func (c *Client) ListResources(ctx context.Context) ([]*Resource, error) { - resp, err := c.makeRequest(ctx, http.MethodGet, resourcesBasePath, nil, nil) + resp, err := c.makeRequest(ctx, http.MethodGet, ResourcesBasePath, nil, nil) if err != nil { return nil, err } @@ -86,7 +135,7 @@ func (c *Client) ListResources(ctx context.Context) ([]*Resource, error) { // GetResource returns a Resource with the given id func (c *Client) GetResource(ctx context.Context, id int) (*Resource, error) { - path := fmt.Sprintf("%s/%d", resourcesBasePath, id) + path := fmt.Sprintf("%s/%d", ResourcesBasePath, id) resp, err := c.makeRequest(ctx, http.MethodGet, path, nil, nil) if err != nil { @@ -113,7 +162,7 @@ func (c *Client) GetResourceByName(ctx context.Context, name string) (*Resource, "name": []string{name}, } - resp, err := c.makeRequest(ctx, http.MethodGet, resourcesBasePath, nil, params) + resp, err := c.makeRequest(ctx, http.MethodGet, ResourcesBasePath, nil, params) if err != nil { return nil, err } @@ -134,7 +183,7 @@ func (c *Client) GetResourceByName(ctx context.Context, name string) (*Resource, // DeleteResource deletes the Resource with the given id func (c *Client) DeleteResource(ctx context.Context, id int) error { - path := fmt.Sprintf("%s/%d", resourcesBasePath, id) + path := fmt.Sprintf("%s/%d", ResourcesBasePath, id) resp, err := c.makeRequest(ctx, http.MethodDelete, path, nil, nil) if err != nil { @@ -151,7 +200,7 @@ func (c *Client) DeleteResource(ctx context.Context, id int) error { // ListResourceConnections returns an array of Connectors for a given Resource func (c *Client) ListResourceConnections(ctx context.Context, id int) ([]*Connector, error) { - path := fmt.Sprintf("%s/%d/connections", resourcesBasePath, id) + path := fmt.Sprintf("%s/%d/connections", ResourcesBasePath, id) resp, err := c.makeRequest(ctx, http.MethodGet, path, nil, nil) if err != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index 9a7d94f55..8f536abed 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -31,7 +31,7 @@ github.com/mattn/go-colorable github.com/mattn/go-isatty # github.com/mattn/go-runewidth v0.0.10 github.com/mattn/go-runewidth -# github.com/meroxa/meroxa-go v0.0.0-20210305201333-97108881ba68 +# github.com/meroxa/meroxa-go v0.0.0-20210310192144-e8c597791043 github.com/meroxa/meroxa-go # github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/go-homedir