Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Endpoint command #78

Merged
merged 3 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,36 @@ var createCmd = &cobra.Command{
including connectors.`,
}

var (
flagEndpointCmdProtocol string
flagEndpointCmdStream string
)

var createEndpointCmd = &cobra.Command{
Use: "endpoint [<custom-endpoint-name>] [flags]",
Aliases: []string{"endpoints"},
Short: "Create an endpoint",
Long: "Use create endpoint to expose an endpoint to a connector stream",
Example: `
meroxa create endpoint my-endpoint --protocol http --stream my-stream`,
RunE: func(cmd *cobra.Command, args []string) error {
c, err := client()
if err != nil {
return err
}

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

var name string
if len(args) > 0 {
name = args[0]
}

return c.CreateEndpoint(ctx, name, flagEndpointCmdProtocol, flagEndpointCmdStream)
},
}

var createConnectorCmd = &cobra.Command{
Use: "connector [<custom-connector-name>] [flags]",
Short: "Create a connector",
Expand Down Expand Up @@ -184,6 +214,12 @@ func init() {

createCmd.AddCommand(createPipelineCmd)
createPipelineCmd.Flags().StringP("metadata", "m", "", "pipeline metadata")

createCmd.AddCommand(createEndpointCmd)
createEndpointCmd.Flags().StringVarP(&flagEndpointCmdProtocol, "protocol", "p", "", "protocol, value can be http or grpc (required)")
createEndpointCmd.Flags().StringVarP(&flagEndpointCmdStream, "stream", "s", "", "stream name (required)")
cobra.MarkFlagRequired(createEndpointCmd.Flags(), "protocol")
cobra.MarkFlagRequired(createEndpointCmd.Flags(), "stream")
}

func createConnector(connectorName string, resourceName string, config *Config, metadata map[string]string, input string) (*meroxa.Connector, error) {
Expand Down
38 changes: 37 additions & 1 deletion cmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ package cmd
import (
"context"
"errors"
"fmt"
"time"

"github.com/meroxa/cli/display"
"github.com/meroxa/meroxa-go"
"github.com/spf13/cobra"
"time"
)

// describeCmd represents the describe command
Expand All @@ -32,6 +34,39 @@ var describeCmd = &cobra.Command{
Long: `Describe a component of the Meroxa data platform, including resources and connectors`,
}

var describeEndpointCmd = &cobra.Command{
Use: "endpoint <name>",
Aliases: []string{"endpoints"},
Short: "Describe Endpoint",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("requires endpoint name\n\nUsage:\n meroxa describe endpoint <name> [flags]")
}
name := args[0]

c, err := client()
if err != nil {
return err
}
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()

end, err := c.GetEndpoint(ctx, name)
if err != nil {
return err
}

if flagRootOutputJSON {
display.JSONPrint(end)
} else {
display.PrintEndpointsTable([]meroxa.Endpoint{*end})
}
return nil

},
}

var describeResourceCmd = &cobra.Command{
Use: "resource <name>",
Short: "Describe resource",
Expand Down Expand Up @@ -104,4 +139,5 @@ func init() {
// Subcommands
describeCmd.AddCommand(describeResourceCmd)
describeCmd.AddCommand(describeConnectorCmd)
describeCmd.AddCommand(describeEndpointCmd)
}
32 changes: 31 additions & 1 deletion cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ limitations under the License.

import (
"context"
"github.com/meroxa/cli/display"
"time"

"github.com/meroxa/cli/display"

"github.com/spf13/cobra"
)

Expand All @@ -32,6 +33,34 @@ var listCmd = &cobra.Command{
resources, connectors, etc... You may also filter by type.`,
}

var listEndpointsCmd = &cobra.Command{
Use: "endpoint",
Aliases: []string{"endpoints"},
Short: "List endpoints",
RunE: func(cmd *cobra.Command, args []string) error {
c, err := client()
if err != nil {
return err
}

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

ends, err := c.ListEndpoints(ctx)
if err != nil {
return err
}

if flagRootOutputJSON {
display.JSONPrint(ends)
} else {
display.PrintEndpointsTable(ends)
}

return nil
},
}

var listResourcesCmd = &cobra.Command{
Use: "resources",
Short: "List resources",
Expand Down Expand Up @@ -181,4 +210,5 @@ func init() {
listCmd.AddCommand(listResourceTypesCmd)
listCmd.AddCommand(listPipelinesCmd)
listCmd.AddCommand(listTransformsCmd)
listCmd.AddCommand(listEndpointsCmd)
}
26 changes: 25 additions & 1 deletion cmd/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import (
"context"
"errors"
"fmt"
"time"

"github.com/meroxa/cli/display"
"github.com/spf13/cobra"
"time"
)

// removeCmd represents the remove command
Expand All @@ -35,6 +36,28 @@ var removeCmd = &cobra.Command{
Aliases: []string{"rm", "delete"},
}

var removeEndpointCmd = &cobra.Command{
Use: "endpoint <name>",
Aliases: []string{"endpoints"},
Short: "Remove endpoint",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("requires endpoint name\n\nUsage:\n meroxa remove endpoint <name> [flags]")
}
name := args[0]

c, err := client()
if err != nil {
return err
}
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()

return c.DeleteEndpoint(ctx, name)
},
}

var removeResourceCmd = &cobra.Command{
Use: "resource <name>",
Short: "Remove resource",
Expand Down Expand Up @@ -190,4 +213,5 @@ func init() {
removeCmd.AddCommand(removeResourceCmd)
removeCmd.AddCommand(removeConnectorCmd)
removeCmd.AddCommand(removePipelineCmd)
removeCmd.AddCommand(removeEndpointCmd)
}
50 changes: 48 additions & 2 deletions display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package display
import (
"encoding/json"
"fmt"
"github.com/alexeyco/simpletable"
"github.com/meroxa/meroxa-go"
"net/url"
"strconv"
"strings"

"github.com/alexeyco/simpletable"
"github.com/meroxa/meroxa-go"
)

func JSONPrint(data interface{}) {
Expand All @@ -18,6 +20,50 @@ func JSONPrint(data interface{}) {
fmt.Printf("%s\n", p)
}

func PrintEndpointsTable(ends []meroxa.Endpoint) {
if len(ends) == 0 {
return
}

table := simpletable.New()
table.Header = &simpletable.Header{
Cells: []*simpletable.Cell{
{Align: simpletable.AlignCenter, Text: "NAME"},
{Align: simpletable.AlignCenter, Text: "PROTOCOL"},
{Align: simpletable.AlignCenter, Text: "STREAM"},
{Align: simpletable.AlignCenter, Text: "URL"},
{Align: simpletable.AlignCenter, Text: "READY"},
},
}

for _, end := range ends {
var u string
switch end.Protocol {
case "HTTP":
host, err := url.ParseRequestURI(end.Host)
if err != nil {
continue
}
host.User = url.UserPassword(end.BasicAuthUsername, end.BasicAuthPassword)
u = host.String()
case "GRPC":
u = fmt.Sprintf("host=%s username=%s password=%s", end.Host, end.BasicAuthUsername, end.BasicAuthPassword)
}

r := []*simpletable.Cell{
{Align: simpletable.AlignRight, Text: end.Name},
{Text: end.Protocol},
{Text: end.Stream},
{Text: u},
{Text: strings.Title(strconv.FormatBool(end.Ready))},
}

table.Body.Cells = append(table.Body.Cells, r)
}
table.SetStyle(simpletable.StyleCompact)
fmt.Println(table.String())
}

func PrintResourcesTable(resources []*meroxa.Resource) {
if len(resources) != 0 {
table := simpletable.New()
Expand Down
1 change: 1 addition & 0 deletions docs/commands/meroxa_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ including connectors.

* [meroxa](meroxa.md) - The Meroxa CLI
* [meroxa create connector](meroxa_create_connector.md) - Create a connector
* [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 4-Mar-2021
39 changes: 39 additions & 0 deletions docs/commands/meroxa_create_endpoint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## meroxa create endpoint

Create an endpoint

### Synopsis

Use create endpoint to expose an endpoint to a connector stream

```
meroxa create endpoint [<custom-endpoint-name>] [flags]
```

### Examples

```

meroxa create endpoint my-endpoint --protocol http --stream my-stream
```

### Options

```
-h, --help help for endpoint
-p, --protocol string protocol, value can be http or grpc (required)
-s, --stream string stream name (required)
```

### Options inherited from parent commands

```
--config string config file (default is $HOME/meroxa.env)
--json output json
```

### SEE ALSO

* [meroxa create](meroxa_create.md) - Create Meroxa pipeline components

###### Auto generated by spf13/cobra on 4-Mar-2021
1 change: 1 addition & 0 deletions docs/commands/meroxa_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Describe a component of the Meroxa data platform, including resources and connec

* [meroxa](meroxa.md) - The Meroxa CLI
* [meroxa describe connector](meroxa_describe_connector.md) - Describe connector
* [meroxa describe endpoint](meroxa_describe_endpoint.md) - Describe Endpoint
* [meroxa describe resource](meroxa_describe_resource.md) - Describe resource

###### Auto generated by spf13/cobra on 4-Mar-2021
26 changes: 26 additions & 0 deletions docs/commands/meroxa_describe_endpoint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## meroxa describe endpoint

Describe Endpoint

```
meroxa describe endpoint <name> [flags]
```

### Options

```
-h, --help help for endpoint
```

### Options inherited from parent commands

```
--config string config file (default is $HOME/meroxa.env)
--json output json
```

### SEE ALSO

* [meroxa describe](meroxa_describe.md) - Describe a component

###### Auto generated by spf13/cobra on 4-Mar-2021
1 change: 1 addition & 0 deletions docs/commands/meroxa_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ List the components of the Meroxa platform, including pipelines,

* [meroxa](meroxa.md) - The Meroxa CLI
* [meroxa list connectors](meroxa_list_connectors.md) - List connectors
* [meroxa list endpoint](meroxa_list_endpoint.md) - List endpoints
* [meroxa list pipelines](meroxa_list_pipelines.md) - List pipelines
* [meroxa list resource-types](meroxa_list_resource-types.md) - List resources-types
* [meroxa list resources](meroxa_list_resources.md) - List resources
Expand Down
26 changes: 26 additions & 0 deletions docs/commands/meroxa_list_endpoint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## meroxa list endpoint

List endpoints

```
meroxa list endpoint [flags]
```

### Options

```
-h, --help help for endpoint
```

### Options inherited from parent commands

```
--config string config file (default is $HOME/meroxa.env)
--json output json
```

### SEE ALSO

* [meroxa list](meroxa_list.md) - List components

###### Auto generated by spf13/cobra on 4-Mar-2021
Loading