-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add rudder-cli source and rm binaries (#3872)
- Loading branch information
Showing
22 changed files
with
1,405 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/olekukonko/tablewriter" | ||
|
||
"github.com/rudderlabs/rudder-server/cmd/rudder-cli/config" | ||
) | ||
|
||
type SourceT struct { | ||
ID string | ||
Name string | ||
SourceDefinition SourceDefinitionT | ||
Config interface{} | ||
Enabled bool | ||
Destinations []DestinationT | ||
WriteKey string | ||
} | ||
|
||
type DestinationT struct { | ||
ID string | ||
Name string | ||
DestinationDefinition DestinationDefinitionT | ||
Config interface{} | ||
Enabled bool | ||
Transformations []TransformationT | ||
} | ||
type TransformationT struct { | ||
ID string | ||
Name string | ||
Description string | ||
VersionID string | ||
} | ||
type SourcesT struct { | ||
Sources []SourceT `json:"sources"` | ||
} | ||
|
||
type DestinationDefinitionT struct { | ||
ID string | ||
Name string | ||
DisplayName string | ||
} | ||
|
||
type SourceDefinitionT struct { | ||
ID string | ||
Name string | ||
} | ||
|
||
func getWorkspaceConfig() (SourcesT, bool) { | ||
baseUrl := config.GetEnv(config.ConfigBackendURLKey) | ||
configBackendToken := config.GetEnv(config.ConfigBackendWorkSpaceToken) | ||
|
||
client := &http.Client{} | ||
url := fmt.Sprintf("%s/workspace-config?workspaceToken=%s", baseUrl, configBackendToken) | ||
resp, err := client.Get(url) | ||
|
||
var respBody []byte | ||
if resp != nil && resp.Body != nil { | ||
respBody, _ = io.ReadAll(resp.Body) | ||
defer resp.Body.Close() | ||
} | ||
|
||
if err != nil { | ||
fmt.Println("Errored when sending request to the server", err) | ||
return SourcesT{}, false | ||
} | ||
var sources SourcesT | ||
err = json.Unmarshal(respBody, &sources) | ||
if err != nil { | ||
fmt.Println("Errored while parsing request", err, string(respBody), resp.StatusCode) | ||
return SourcesT{}, false | ||
} | ||
|
||
return sources, true | ||
} | ||
|
||
func DisplayConfig() { | ||
sourceList, ok := getWorkspaceConfig() | ||
if !ok { | ||
return | ||
} | ||
sources := sourceList.Sources | ||
|
||
table := tablewriter.NewWriter(os.Stdout) | ||
|
||
table.SetAutoWrapText(false) | ||
table.SetHeader([]string{"Source", "Destination"}) | ||
|
||
for i := 0; i < len(sources); i++ { | ||
for j := 0; j < len(sources[i].Destinations); j++ { | ||
sourceName := sources[i].Name | ||
if j > 0 { | ||
sourceName = "" | ||
} | ||
table.Append([]string{ | ||
sourceName, | ||
sources[i].Destinations[j].Name, | ||
}) | ||
} | ||
} | ||
|
||
table.Render() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package client | ||
|
||
import ( | ||
"log" | ||
"net/rpc" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// Setup Unix Domain socket client to communicate with | ||
// the rudder server running on the same machine as this cli | ||
func GetUDSClient() *rpc.Client { | ||
tmpdirPath := os.Getenv("RUDDER_TMPDIR") | ||
if tmpdirPath == "" { | ||
tmpdirPath = "/tmp" | ||
} | ||
client, err := rpc.DialHTTP("unix", filepath.Join(tmpdirPath, "rudder-server.sock")) | ||
if err != nil { | ||
log.Fatal("dialing:", err) | ||
} | ||
return client | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package config | ||
|
||
// RudderServerPathKey : | ||
const RudderServerPathKey = "RUDDER_SERVER_PATH" | ||
|
||
// RudderEnvFilePathKey : | ||
const RudderEnvFilePathKey = "RUDDER_ENV_FILE_PATH" | ||
|
||
const ( | ||
JobsDBHostKey = "JOBS_DB_HOST" | ||
JobsDBPortKey = "JOBS_DB_PORT" | ||
JobsDBNameKey = "JOBS_DB_DB_NAME" | ||
JobsDBUserKey = "JOBS_DB_USER" | ||
JobsDBPasswordKey = "JOBS_DB_PASSWORD" | ||
) | ||
|
||
const ( | ||
JobsS3BucketKey = "JOBS_BACKUP_BUCKET" | ||
AWSAccessKey = "AWS_ACCESS_KEY_ID" | ||
AWSSecretKey = "AWS_SECRET_ACCESS_KEY" | ||
) | ||
|
||
const DefaultEnvFile = ".env" | ||
|
||
const DestTransformURLKey = "DEST_TRANSFORM_URL" | ||
|
||
const ( | ||
ConfigBackendURLKey = "CONFIG_BACKEND_URL" | ||
ConfigBackendTokenKey = "CONFIG_BACKEND_TOKEN" | ||
ConfigBackendWorkSpaceToken = "WORKSPACE_TOKEN" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/joho/godotenv" | ||
) | ||
|
||
var initialized = false | ||
|
||
func SetEnvFile(path string) { | ||
} | ||
|
||
func getServerDirPath() string { | ||
envServerDirPath, ok := os.LookupEnv(RudderServerPathKey) | ||
|
||
if !ok { | ||
return "." | ||
} | ||
return envServerDirPath | ||
} | ||
|
||
func getEnvFilePath() string { | ||
envFilePath, ok := os.LookupEnv(RudderEnvFilePathKey) | ||
if !ok { | ||
return fmt.Sprintf("%s/%s", getServerDirPath(), DefaultEnvFile) | ||
} | ||
return envFilePath | ||
} | ||
|
||
func GetEnv(key string) string { | ||
if !initialized { | ||
// Load the .env file, if it exists | ||
_ = godotenv.Load(getEnvFilePath()) | ||
initialized = true | ||
} | ||
|
||
return os.Getenv(key) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package db | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
|
||
_ "github.com/lib/pq" | ||
"github.com/olekukonko/tablewriter" | ||
|
||
"github.com/rudderlabs/rudder-server/cmd/rudder-cli/util" | ||
) | ||
|
||
func getRowCount(db *sql.DB, tableName string) int64 { | ||
totalCount := int64(-1) | ||
sqlStatement := fmt.Sprintf(`SELECT COUNT(*) FROM %s`, tableName) | ||
row := db.QueryRow(sqlStatement) | ||
_ = row.Scan(&totalCount) | ||
return totalCount | ||
} | ||
|
||
func DisplayAllTables() { | ||
table := tablewriter.NewWriter(os.Stdout) | ||
|
||
table.SetAutoWrapText(false) | ||
table.SetHeader([]string{"Name", "Count"}) | ||
|
||
db, err := util.GetDbHandle() | ||
if err != nil { | ||
// Write to console | ||
fmt.Println(err) | ||
} | ||
|
||
pgTableNames, err := util.GetAllTableNames(db) | ||
if err != nil { | ||
// Write to console | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
for i := 0; i < len(pgTableNames); i++ { | ||
tableName := pgTableNames[i] | ||
table.Append([]string{ | ||
tableName, | ||
strconv.FormatInt(getRowCount(db, tableName), 10), | ||
}) | ||
} | ||
|
||
table.Render() | ||
} |
Oops, something went wrong.