Skip to content

Commit

Permalink
Merge pull request #842 from meroxa/mdpx-remove-meroxa-go
Browse files Browse the repository at this point in the history
Mdpx remove meroxa go
  • Loading branch information
anna-cross authored Oct 30, 2023
2 parents 7bf0bd8 + e99df36 commit d29f204
Show file tree
Hide file tree
Showing 111 changed files with 101 additions and 18,861 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Prerequisite Tools:

To build from source:

1. The CLI depends on [meroxa-go](github.com/meroxa/meroxa-go). To update vendoring the dependency, you'll need to run the following:
1. To update vendoring the dependency, you'll need to run the following:

```
make gomod
Expand Down
31 changes: 0 additions & 31 deletions cmd/meroxa/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"github.com/meroxa/cli/cmd/meroxa/global"
"github.com/meroxa/cli/config"
"github.com/meroxa/cli/log"
"github.com/meroxa/meroxa-go/pkg/meroxa"
)

type Command interface {
Expand Down Expand Up @@ -64,12 +63,6 @@ type CommandWithArgs interface {
ParseArgs([]string) error
}

type CommandWithClient interface {
Command
// Client provides the meroxa client to the command.
Client(meroxa.Client)
}

type CommandWithBasicClient interface {
Command
// Client provides the basic client to the command.
Expand Down Expand Up @@ -205,7 +198,6 @@ func BuildCobraCommand(c Command) *cobra.Command {

buildCommandWithAliases(cmd, c)
buildCommandWithArgs(cmd, c)
buildCommandWithClient(cmd, c)
buildCommandWithBasicClient(cmd, c)
buildCommandWithConfig(cmd, c)

Expand Down Expand Up @@ -260,29 +252,6 @@ func buildCommandWithArgs(cmd *cobra.Command, c Command) {
}
}

func buildCommandWithClient(cmd *cobra.Command, c Command) {
v, ok := c.(CommandWithClient)
if !ok {
return
}

old := cmd.PreRunE
cmd.PreRunE = func(cmd *cobra.Command, args []string) error {
if old != nil {
err := old(cmd, args)
if err != nil {
return err
}
}
c, err := global.NewOauthClient()
if err != nil {
return err
}
v.Client(c)
return nil
}
}

func buildCommandWithBasicClient(cmd *cobra.Command, c Command) {
v, ok := c.(CommandWithBasicClient)
if !ok {
Expand Down
13 changes: 12 additions & 1 deletion cmd/meroxa/global/basic_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -202,7 +203,7 @@ func (r *client) newRequest(
// No need to check for a valid token when trying to authenticate.
// TODO: Need to change this once we integrate with OAuth2
if path != "/api/collections/users/auth-with-password" {
accessToken, _, err := GetUserToken()
accessToken, err := GetUserToken()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -245,3 +246,13 @@ func (r *client) encodeBody(w io.Writer, v interface{}) error {
return json.NewEncoder(w).Encode(v)
}
}

func GetUserToken() (accessToken string, err error) {
accessToken = Config.GetString(AccessTokenEnv)
if accessToken == "" {
// we need at least one token for creating an authenticated client
return "", errors.New("please login or signup by running 'meroxa login'")
}

return accessToken, nil
}
151 changes: 0 additions & 151 deletions cmd/meroxa/global/client.go

This file was deleted.

7 changes: 3 additions & 4 deletions cmd/meroxa/global/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ const (
RefreshTokenEnv = "REFRESH_TOKEN"
UserFeatureFlagsEnv = "USER_FEATURE_FLAGS"
UserInfoUpdatedAtEnv = "USER_INFO_UPDATED_AT"

TenantSubdomainEnv = "TENANT_SUBDOMAIN"
TenantEmailAddress = "TENANT_EMAIL_ADDRESS"
TenantPassword = "TENANT_PASSWORD"
TenantSubdomainEnv = "TENANT_SUBDOMAIN"
TenantEmailAddress = "TENANT_EMAIL_ADDRESS"
TenantPassword = "TENANT_PASSWORD"
)

func RegisterGlobalFlags(cmd *cobra.Command) {
Expand Down
31 changes: 13 additions & 18 deletions cmd/meroxa/root/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,31 @@ import (
"encoding/json"
"errors"
"io"
"net/http"
"net/url"
"strings"

"github.com/meroxa/cli/log"
"github.com/meroxa/meroxa-go/pkg/meroxa"

"github.com/meroxa/cli/cmd/meroxa/builder"
"github.com/meroxa/cli/cmd/meroxa/global"
)

var (
_ builder.CommandWithDocs = (*API)(nil)
_ builder.CommandWithArgs = (*API)(nil)
_ builder.CommandWithClient = (*API)(nil)
_ builder.CommandWithLogger = (*API)(nil)
_ builder.CommandWithExecute = (*API)(nil)
_ builder.CommandWithDocs = (*API)(nil)
_ builder.CommandWithArgs = (*API)(nil)
_ builder.CommandWithBasicClient = (*API)(nil)
_ builder.CommandWithLogger = (*API)(nil)
_ builder.CommandWithExecute = (*API)(nil)
)

type apiClient interface {
MakeRequest(ctx context.Context, method, path string, body interface{}, params url.Values, headers http.Header) (*http.Response, error)
}

type API struct {
client apiClient
client global.BasicClient
logger log.Logger

args struct {
Method string
Path string
Body string
Body interface{}
ID string
}
}

Expand All @@ -63,12 +58,12 @@ func (a *API) Docs() builder.Docs {
return builder.Docs{
Short: "Invoke Meroxa API",
Example: `
meroxa api GET /v1/resources
meroxa api POST /v1/resources '{"type":"postgres", "name":"pg", "url":"postgres://.."}'`,
meroxa api GET {collection} {id}
meroxa api POST {collection} {id} '{"type":"postgres", "name":"pg", "url":"postgres://.."}'`,
}
}

func (a *API) Client(client meroxa.Client) {
func (a *API) BasicClient(client global.BasicClient) {
a.client = client
}

Expand All @@ -92,7 +87,7 @@ func (a *API) ParseArgs(args []string) error {
}

func (a *API) Execute(ctx context.Context) error {
resp, err := a.client.MakeRequest(ctx, a.args.Method, a.args.Path, a.args.Body, nil, nil)
resp, err := a.client.URLRequest(ctx, a.args.Method, a.args.Path, a.args.Body, nil, nil, nil)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit d29f204

Please sign in to comment.