Skip to content

Commit

Permalink
Merge pull request #509 from turbot/cloud
Browse files Browse the repository at this point in the history
RenameCloudMetadata to PipesMetadata, move to pipe fittings pipes package
  • Loading branch information
kaidaguerre authored Oct 16, 2024
2 parents 7aaffb2 + 68968da commit da7215b
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 33 deletions.
4 changes: 2 additions & 2 deletions internal/cmd/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
"github.com/spf13/viper"
"github.com/thediveo/enumflag/v2"
"github.com/turbot/go-kit/helpers"
"github.com/turbot/pipe-fittings/cloud"
"github.com/turbot/pipe-fittings/cmdconfig"
"github.com/turbot/pipe-fittings/constants"
"github.com/turbot/pipe-fittings/contexthelpers"
"github.com/turbot/pipe-fittings/error_helpers"
"github.com/turbot/pipe-fittings/export"
"github.com/turbot/pipe-fittings/modconfig"
"github.com/turbot/pipe-fittings/pipes"
"github.com/turbot/pipe-fittings/schema"
"github.com/turbot/pipe-fittings/statushooks"
"github.com/turbot/pipe-fittings/steampipeconfig"
Expand Down Expand Up @@ -210,7 +210,7 @@ func publishSnapshotIfNeeded(ctx context.Context, snapshot *steampipeconfig.Stea
return nil
}

message, err := cloud.PublishSnapshot(ctx, snapshot, shouldShare)
message, err := pipes.PublishSnapshot(ctx, snapshot, shouldShare)
if err != nil {
// reword "402 Payment Required" error
return handlePublishSnapshotError(err)
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"bufio"
"context"
"fmt"
"github.com/turbot/pipe-fittings/pipes"
"log"
"os"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/turbot/pipe-fittings/cloud"
"github.com/turbot/pipe-fittings/cmdconfig"
"github.com/turbot/pipe-fittings/constants"
"github.com/turbot/pipe-fittings/error_helpers"
Expand Down Expand Up @@ -43,7 +43,7 @@ func runLoginCmd(cmd *cobra.Command, _ []string) {
log.Printf("[TRACE] login, cloud host %s", viper.Get(constants.ArgPipesHost))
log.Printf("[TRACE] opening login web page")
// start login flow - this will open a web page prompting user to login, and will give the user a code to enter
var id, err = cloud.WebLogin(ctx)
var id, err = pipes.WebLogin(ctx)
if err != nil {
error_helpers.ShowError(ctx, err)
exitCode = constants.ExitCodeLoginCloudConnectionFailed
Expand All @@ -58,7 +58,7 @@ func runLoginCmd(cmd *cobra.Command, _ []string) {
}

// save token
err = cloud.SaveToken(token)
err = pipes.SaveToken(token)
if err != nil {
error_helpers.ShowError(ctx, err)
exitCode = constants.ExitCodeLoginCloudConnectionFailed
Expand All @@ -81,7 +81,7 @@ func getToken(ctx context.Context, id string) (loginToken string, err error) {
if code != "" {
log.Printf("[TRACE] get login token")
// use this code to get a login token and store it
loginToken, err = cloud.GetLoginToken(ctx, id, code)
loginToken, err = pipes.GetLoginToken(ctx, id, code)
if err == nil {
return loginToken, nil
}
Expand All @@ -105,7 +105,7 @@ func getToken(ctx context.Context, id string) (loginToken string, err error) {
}

func displayLoginMessage(ctx context.Context, token string) {
userName, err := cloud.GetUserName(ctx, token)
userName, err := pipes.GetUserName(ctx, token)
error_helpers.FailOnError(sperr.WrapWithMessage(err, "failed to read user name"))

//nolint:forbidigo // intentional
Expand Down
6 changes: 3 additions & 3 deletions internal/cmdconfig/cmd_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
"github.com/spf13/viper"
"github.com/turbot/go-kit/helpers"
"github.com/turbot/pipe-fittings/app_specific"
"github.com/turbot/pipe-fittings/cloud"
"github.com/turbot/pipe-fittings/cmdconfig"
"github.com/turbot/pipe-fittings/constants"
"github.com/turbot/pipe-fittings/error_helpers"
"github.com/turbot/pipe-fittings/filepaths"
"github.com/turbot/pipe-fittings/parse"
"github.com/turbot/pipe-fittings/pipes"
"github.com/turbot/pipe-fittings/task"
"github.com/turbot/pipe-fittings/utils"
"github.com/turbot/pipe-fittings/workspace_profile"
Expand Down Expand Up @@ -168,7 +168,7 @@ func initGlobalConfig() error_helpers.ErrorAndWarnings {

// if the configured workspace is a cloud workspace, create cloud metadata and set the default connection
if wp != nil && wp.IsCloudWorkspace() {
defaultConnection, ew := wp.GetCloudMetadata()
defaultConnection, ew := wp.GetPipesMetadata()
if ew.GetError() != nil {
return ew
}
Expand All @@ -188,7 +188,7 @@ func setPipesTokenDefault(loader *parse.WorkspaceProfileLoader[*workspace_profil
*/
// set viper defaults in order of increasing precedence
// 1) saved cloud token
savedToken, err := cloud.LoadToken()
savedToken, err := pipes.LoadToken()
if err != nil {
return err
}
Expand Down
16 changes: 7 additions & 9 deletions internal/cmdconfig/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@ package cmdconfig
import (
"context"
"fmt"
"github.com/turbot/pipe-fittings/connection"
"strings"

"github.com/spf13/viper"
filehelpers "github.com/turbot/go-kit/files"
"github.com/turbot/pipe-fittings/cloud"
"github.com/turbot/pipe-fittings/connection"
"github.com/turbot/pipe-fittings/constants"
"github.com/turbot/pipe-fittings/error_helpers"
"github.com/turbot/pipe-fittings/pipes"
"github.com/turbot/pipe-fittings/steampipeconfig"
"github.com/turbot/powerpipe/internal/powerpipeconfig"
)

// ValidateDatabaseArg validates the connection and database arg
// if both or neither are set, returns an error
// if connection is set, verify it is in the config and update the database arg with the connection string
// ValidateDatabaseArg checks if the database arg is a connection reference and resolves it if so
func ValidateDatabaseArg() error {
databaseArg := viper.GetString(constants.ArgDatabase)
if databaseArg == "" {
Expand Down Expand Up @@ -65,8 +63,8 @@ func ValidateSnapshotArgs(ctx context.Context) error {
}

// if workspace-database or snapshot-location are a cloud workspace handle, cloud token must be set
requireCloudToken := steampipeconfig.IsCloudWorkspaceIdentifier(viper.GetString(constants.ArgDatabase)) ||
steampipeconfig.IsCloudWorkspaceIdentifier(viper.GetString(constants.ArgSnapshotLocation))
requireCloudToken := steampipeconfig.IsPipesWorkspaceIdentifier(viper.GetString(constants.ArgDatabase)) ||
steampipeconfig.IsPipesWorkspaceIdentifier(viper.GetString(constants.ArgSnapshotLocation))

// verify cloud token and workspace has been set
if requireCloudToken && token == "" {
Expand Down Expand Up @@ -94,7 +92,7 @@ func validateSnapshotLocation(ctx context.Context, cloudToken string) error {

// if it is NOT a workspace handle, assume it is a local file location:
// tildefy it and ensure it exists
if !steampipeconfig.IsCloudWorkspaceIdentifier(snapshotLocation) {
if !steampipeconfig.IsPipesWorkspaceIdentifier(snapshotLocation) {
var err error
snapshotLocation, err = filehelpers.Tildefy(snapshotLocation)
if err != nil {
Expand All @@ -112,7 +110,7 @@ func validateSnapshotLocation(ctx context.Context, cloudToken string) error {
}

func setSnapshotLocationFromDefaultWorkspace(ctx context.Context, cloudToken string) error {
workspaceHandle, err := cloud.GetUserWorkspaceHandle(ctx, cloudToken)
workspaceHandle, err := pipes.GetUserWorkspaceHandle(ctx, cloudToken)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions internal/controldisplay/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package controldisplay
import (
"context"
"fmt"
"github.com/turbot/pipe-fittings/steampipeconfig"

"github.com/turbot/pipe-fittings/cloud"
"github.com/turbot/pipe-fittings/modconfig"
"github.com/turbot/pipe-fittings/pipes"
"github.com/turbot/pipe-fittings/statushooks"
"github.com/turbot/pipe-fittings/steampipeconfig"
"github.com/turbot/powerpipe/internal/controlexecute"
"github.com/turbot/powerpipe/internal/dashboardexecute"
"github.com/turbot/powerpipe/internal/dashboardworkspace"
Expand Down Expand Up @@ -69,7 +69,7 @@ func PublishSnapshot(ctx context.Context, e *controlexecute.ExecutionTree, shoul
return err
}

message, err := cloud.PublishSnapshot(ctx, snapshot, shouldShare)
message, err := pipes.PublishSnapshot(ctx, snapshot, shouldShare)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/dashboardserver/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/turbot/steampipe-plugin-sdk/v5/sperr"
)

func buildServerMetadataPayload(workspaceResources *modconfig.ResourceMaps, cloudMetadata *steampipeconfig.CloudMetadata) ([]byte, error) {
func buildServerMetadataPayload(workspaceResources *modconfig.ResourceMaps, pipesMetadata *steampipeconfig.PipesMetadata) ([]byte, error) {
installedMods := make(map[string]*ModMetadata)
for _, mod := range workspaceResources.Mods {
// Ignore current mod
Expand Down Expand Up @@ -79,7 +79,7 @@ func buildServerMetadataPayload(workspaceResources *modconfig.ResourceMaps, clou
}
// if telemetry is enabled, send cloud metadata
if payload.Metadata.Telemetry != constants.TelemetryNone {
payload.Metadata.Cloud = cloudMetadata
payload.Metadata.Cloud = pipesMetadata
}

return json.Marshal(payload)
Expand Down
4 changes: 2 additions & 2 deletions internal/dashboardserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (s *Server) HandleDashboardEvent(ctx context.Context, event dashboardevents

// Emit dashboard metadata event in case there is a new mod - else the UI won't know about this mod
// TODO KAI verify we are ok to NOT send the cloud metadata here
payload, payloadError = buildServerMetadataPayload(s.workspace.GetResourceMaps(), &steampipeconfig.CloudMetadata{}) //s.workspace.CloudMetadata)
payload, payloadError = buildServerMetadataPayload(s.workspace.GetResourceMaps(), &steampipeconfig.PipesMetadata{}) //s.workspace.PipesMetadata)
if payloadError != nil {
return
}
Expand Down Expand Up @@ -346,7 +346,7 @@ func (s *Server) handleMessageFunc(ctx context.Context) func(session *melody.Ses
switch request.Action {
case "get_server_metadata":
// TODO KAI verify we are ok to NOT send the cloud metadata here
payload, err := buildServerMetadataPayload(s.workspace.GetResourceMaps(), &steampipeconfig.CloudMetadata{}) //s.workspace.CloudMetadata)
payload, err := buildServerMetadataPayload(s.workspace.GetResourceMaps(), &steampipeconfig.PipesMetadata{}) //s.workspace.PipesMetadata)
if err != nil {
OutputError(ctx, sperr.WrapWithMessage(err, "error building payload for get_metadata"))
}
Expand Down
2 changes: 1 addition & 1 deletion internal/dashboardserver/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ type ServerMetadata struct {
Mod *ModMetadata `json:"mod,omitempty"`
InstalledMods map[string]*ModMetadata `json:"installed_mods,omitempty"`
CLI DashboardCLIMetadata `json:"cli"`
Cloud *steampipeconfig.CloudMetadata `json:"cloud,omitempty"`
Cloud *steampipeconfig.PipesMetadata `json:"cloud,omitempty"`
Telemetry string `json:"telemetry"`
SearchPath *SearchPathMetadata `json:"search_path"`
}
Expand Down
9 changes: 5 additions & 4 deletions internal/db_client/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package db_client

import (
"context"

"github.com/spf13/viper"
"github.com/turbot/pipe-fittings/cloud"
"github.com/turbot/pipe-fittings/constants"
"github.com/turbot/pipe-fittings/error_helpers"
"github.com/turbot/pipe-fittings/pipes"
"github.com/turbot/powerpipe/internal/powerpipeconfig"
)

Expand All @@ -19,12 +20,12 @@ func GetCloudWorkspaceConnectionString(workspace string) (string, error) {
if token == "" {
return "", error_helpers.MissingCloudTokenError()
}
cloudMetadata, err := cloud.GetCloudMetadata(context.Background(), workspace, token)
pipesMetadata, err := pipes.GetPipesMetadata(context.Background(), workspace, token)
if err != nil {
return "", err
}
// cache
powerpipeconfig.GlobalConfig.SetCloudConnectionString(workspace, cloudMetadata.ConnectionString)
powerpipeconfig.GlobalConfig.SetCloudConnectionString(workspace, pipesMetadata.ConnectionString)

return cloudMetadata.ConnectionString, nil
return pipesMetadata.ConnectionString, nil
}
4 changes: 2 additions & 2 deletions internal/db_client/database_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func GetDatabaseConfigForResource(resource modconfig.ModTreeItem, workspaceMod *
}

// if the database is a cloud workspace, resolve the connection string
if steampipeconfig.IsCloudWorkspaceIdentifier(database) {
if steampipeconfig.IsPipesWorkspaceIdentifier(database) {
var err error
database, err = GetCloudWorkspaceConnectionString(database)
if err != nil {
Expand Down Expand Up @@ -88,7 +88,7 @@ func GetDefaultDatabaseConfig(opts ...backend.ConnectOption) (string, backend.Se
}

// if the database is a cloud workspace, resolve the connection string
if steampipeconfig.IsCloudWorkspaceIdentifier(defaultDatabase) {
if steampipeconfig.IsPipesWorkspaceIdentifier(defaultDatabase) {
var err error
defaultDatabase, err = GetCloudWorkspaceConnectionString(defaultDatabase)
if err != nil {
Expand Down

0 comments on commit da7215b

Please sign in to comment.