Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ linters-settings:
gocyclo:
min-complexity: 15
govet:
check-shadowing: true
enable:
- shadow
settings:
printf:
funcs:
Expand Down Expand Up @@ -83,7 +84,6 @@ linters:
- gochecknoinits
- goconst
- gocyclo
- godot
- gofmt
- goimports
- goprintffuncname
Expand Down
5 changes: 5 additions & 0 deletions cmd/meroxa/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ func buildCommandWithBasicClient(cmd *cobra.Command, c Command) {
return err
}
}
err := global.PersistentPreRunE(cmd)
if err != nil {
return err
}

cl, err := global.NewBasicClient()
if err != nil {
return err
Expand Down
42 changes: 1 addition & 41 deletions cmd/meroxa/global/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package global

import (
"fmt"
"net/url"
"os"
"path/filepath"
"strings"
Expand All @@ -34,52 +33,13 @@ const (
)

func GetMeroxaTenantURL() string {
return getEnvVal([]string{"MEROXA_API_URL"}, "https://api.meroxa.io")
return getEnvVal([]string{"TENANT_URL"}, "https://test.na1.meroxa.cloud")
}

func GetMeroxaTenantUser() string {
return getEnvVal([]string{"TENANT_EMAIL_ADDRESS"}, "")
}

func GetMeroxaAuthAudience() string {
return getEnvVal([]string{"MEROXA_AUTH_AUDIENCE", "MEROXA_AUDIENCE"}, "https://api.meroxa.io/v1")
}

func GetMeroxaAuthDomain() string {
return getEnvVal([]string{"MEROXA_AUTH_DOMAIN", "MEROXA_DOMAIN"}, "auth.meroxa.io")
}

func GetMeroxaAuthClientID() string {
return getEnvVal([]string{"MEROXA_AUTH_CLIENT_ID", "MEROXA_CLIENT_ID"}, "2VC9z0ZxtzTcQLDNygeEELV3lYFRZwpb")
}

func getMeroxaAuthCallbackPort() string {
return getEnvVal([]string{MeroxaAuthCallbackPort}, "21900")
}

// getMeroxaAuthCallbackHost will return the callback host.
// Note: If port is desired, it'll need to be included here.
func getMeroxaAuthCallbackHost() string {
defaultHost := fmt.Sprintf("localhost:%s", getMeroxaAuthCallbackPort())
// check if port was included or not
return getEnvVal([]string{MeroxaAuthCallbackHost}, defaultHost)
}

func getMeroxaAuthCallbackProtocol() string {
return getEnvVal([]string{MeroxaAuthCallbackProtocol}, "http")
}

// GetMeroxaAuthCallbackURL will return either the user configured oauth callback url
// or a default one: "http://localhost:21900/oauth/callback".
func GetMeroxaAuthCallbackURL() string {
callback := url.URL{
Scheme: getMeroxaAuthCallbackProtocol(),
Host: getMeroxaAuthCallbackHost(),
Path: "/oauth/callback",
}
return getEnvVal([]string{MeroxaAuthCallbackURL}, callback.String())
}

// getEnvVal returns the value of either the first existing key specified in keys, or defaultVal if none were present.
func getEnvVal(keys []string, defaultVal string) string {
for _, key := range keys {
Expand Down
86 changes: 0 additions & 86 deletions cmd/meroxa/global/config_test.go
Original file line number Diff line number Diff line change
@@ -1,87 +1 @@
package global

import (
"testing"

"github.com/spf13/viper"
)

func TestGetMeroxaMeroxaAuthCallbackURL(t *testing.T) {
oldConfig := Config

testCases := []struct {
name string
config func() *viper.Viper
want string
}{
{
name: "when MEROXA_AUTH_CALLBACK_URL is not set",
config: func() *viper.Viper {
cfg := viper.New()
return cfg
},
want: "http://localhost:21900/oauth/callback",
},
{
name: "when MEROXA_AUTH_CALLBACK_URL is set",
config: func() *viper.Viper {
cfg := viper.New()
cfg.Set(MeroxaAuthCallbackURL, "https://nimbus.meroxa.io:3000/oauth/callback")
return cfg
},
want: "https://nimbus.meroxa.io:3000/oauth/callback",
},
{
name: "when MEROXA_AUTH_CALLBACK_PROTOCOL is set",
config: func() *viper.Viper {
cfg := viper.New()
cfg.Set(MeroxaAuthCallbackProtocol, "https")
return cfg
},
want: "https://localhost:21900/oauth/callback",
},
{
name: "when MEROXA_AUTH_CALLBACK_HOST is set",
config: func() *viper.Viper {
cfg := viper.New()
cfg.Set(MeroxaAuthCallbackHost, "nimbus.meroxa.io:3000")
return cfg
},
want: "http://nimbus.meroxa.io:3000/oauth/callback",
},
{
name: "when MEROXA_AUTH_CALLBACK_PORT is set",
config: func() *viper.Viper {
cfg := viper.New()
cfg.Set(MeroxaAuthCallbackPort, "3000")
return cfg
},
want: "http://localhost:3000/oauth/callback",
},
{
name: "when MEROXA_AUTH_CALLBACK_URL, MEROXA_AUTH_CALLBACK_PROTOCOL, and MEROXA_AUTH_CALLBACK_HOST are set",
config: func() *viper.Viper {
cfg := viper.New()
cfg.Set(MeroxaAuthCallbackURL, "https://nimbus.meroxa.io:3000/oauth/callback")
cfg.Set(MeroxaAuthCallbackPort, "https")
cfg.Set(MeroxaAuthCallbackHost, "nimbus.meroxa.io")

return cfg
},
want: "https://nimbus.meroxa.io:3000/oauth/callback",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Config = tc.config()
got := GetMeroxaAuthCallbackURL()

if got != tc.want {
t.Errorf("expected MEROXA_AUTH_CALLBACK_URL to be %q, got %q", tc.want, got)
}
})
}

Config = oldConfig
}
2 changes: 0 additions & 2 deletions cmd/meroxa/global/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ func handleAPIErrors(resp *http.Response) error {
if err != nil {
return err
}

// API error returned by Meroxa Platform API
return apiError
}
return nil
Expand Down
10 changes: 2 additions & 8 deletions cmd/meroxa/global/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,13 @@ const (
CasedPublishKeyEnv = "CASED_PUBLISH_KEY"
LatestCLIVersionUpdatedAtEnv = "LATEST_CLI_VERSION_UPDATED_AT"
DisableNotificationsUpdate = "DISABLE_NOTIFICATIONS_UPDATE"
MeroxaAuthCallbackHost = "MEROXA_AUTH_CALLBACK_HOST"
MeroxaAuthCallbackURL = "MEROXA_AUTH_CALLBACK_URL"
MeroxaAuthCallbackPort = "MEROXA_AUTH_CALLBACK_PORT"
MeroxaAuthCallbackProtocol = "MEROXA_AUTH_CALLBACK_PROTOCOL"
PublishMetricsEnv = "PUBLISH_METRICS"
RefreshTokenEnv = "REFRESH_TOKEN"
UserFeatureFlagsEnv = "USER_FEATURE_FLAGS"
UserInfoUpdatedAtEnv = "USER_INFO_UPDATED_AT"
TenantSubdomainEnv = "TENANT_SUBDOMAIN"
TenantEmailAddress = "TENANT_EMAIL_ADDRESS"
TenantPassword = "TENANT_PASSWORD"
TenantURL = "TENANT_URL"
defaultClientTimeout = time.Second * 10

defaultClientTimeout = time.Second * 10
)

func RegisterGlobalFlags(cmd *cobra.Command) {
Expand Down
78 changes: 56 additions & 22 deletions cmd/meroxa/root/apps/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

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

"github.com/meroxa/cli/cmd/meroxa/global"
pb "github.com/pocketbase/pocketbase/tools/types"

Expand All @@ -35,34 +36,66 @@ import (
type ApplicationState string

const (
ApplicationStateInitialized ApplicationState = "initialized"
ApplicationStateDeploying ApplicationState = "deploying"
ApplicationStatePending ApplicationState = "pending"
ApplicationStateRunning ApplicationState = "running"
ApplicationStateDegraded ApplicationState = "degraded"
ApplicationStateFailed ApplicationState = "failed"

collectionName = "apps"
AppProvisioningState ApplicationState = "provisioning"
AppProvisionedState ApplicationState = "provisioned"
AppDeprovisioningState ApplicationState = "deprovisioning"
AppDeprovisionedState ApplicationState = "deprovisioned"
AppDegradedState ApplicationState = "degraded"

deploymentCollection = "conduit_deployments"
applicationCollection = "conduit_apps"
)

var displayDetails = display.Details{
"Name": "name",
"State": "state",
"SpecVersion": "specVersion",
"Created": "created",
"Updated": "updated",
"Name": "name",
"State": "state",
"Application Spec": "stream_tech",
"Config": "config",
"Pipeline Filename": "pipeline_filename",
"Stream Provider": "stream_provider",
// "PipelineEnriched": "pipeline_enriched",
// "PipelineOriginal": "pipeline_original",
"Created": "created",
"Updated": "updated",
}

type Deployment struct {
ID string `json:"id,omitempty"`
Archive string `json:"archive"`
State string `json:"state,omitempty"`
ApplicationSpec string `json:"app_spec,omitempty"`

Created AppTime `json:"created,omitempty"`
Updated AppTime `json:"updated,omitempty"`
ProcessorPlugins string `json:"processors_plugins,omitempty"`
ProcessorFilenames string `json:"processors_filenames,omitempty"`
PipelineFilenames string `json:"pipeline_filenames,omitempty"`
}

type Deployments struct {
Page int `json:"page"`
PerPage int `json:"perPage"`
TotalItems int `json:"totalItems"`
TotalPages int `json:"totalPages"`
Items []Deployment `json:"items"`
}

// Application represents the Meroxa Application type within the Meroxa API.
type Application struct {
ID string `json:"id"`
Name string `json:"name"`
State ApplicationState `json:"state"`
Spec map[string]interface{} `json:"spec"`
SpecVersion string `json:"specVersion"`
Created AppTime `json:"created"`
Updated AppTime `json:"updated"`
Image string `json:"imageArchive"`
ID string `json:"id"`
DeploymentID []string `json:"deployment_id"`
Name string `json:"name"`
State string `json:"state"`
ApplicationSpec string `json:"stream_provider"`
Config string `json:"config"`
PipelineFilenames string `json:"pipeline_filename"`
PipelineEnriched string `json:"pipeline_enriched"`
PipelineOriginal string `json:"pipeline_original"`
PipelineDraft string `json:"pipeline_draft"`

Created AppTime `json:"created"`
Updated AppTime `json:"updated"`
Archive string `json:"archive"`
}

type Applications struct {
Expand Down Expand Up @@ -124,6 +157,7 @@ func (*Apps) Docs() builder.Docs {

func (*Apps) SubCommands() []*cobra.Command {
return []*cobra.Command{
// TODO - commenting out run and init until implemented
builder.BuildCobraCommand(&Deploy{}),
builder.BuildCobraCommand(&Describe{}),
builder.BuildCobraCommand(&List{}),
Expand All @@ -138,7 +172,7 @@ func RetrieveApplicationByNameOrID(ctx context.Context, client global.BasicClien
a := &url.Values{}
a.Add("filter", fmt.Sprintf("(id='%s' || name='%s')", nameOrID, nameOrID))

response, err := client.CollectionRequest(ctx, "GET", collectionName, "", nil, *a)
response, err := client.CollectionRequest(ctx, "GET", applicationCollection, "", nil, *a)
if err != nil {
return nil, err
}
Expand Down
Loading