feat(config): add API version selector for v1 and v2
Add configurable API version selection with three methods: - Config file: api_version: "v1" or "v2" in .edge-connect.yaml - CLI flag: --api-version v1/v2 - Environment variable: EDGE_CONNECT_API_VERSION=v1/v2 Changes: - Update root.go to add api_version config and env var support - Update app.go and instance.go to support both v1 and v2 clients - Add example config file with api_version documentation - Default to v2 for backward compatibility - Apply command always uses v2 (advanced feature) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
3486b2228d
commit
2a8e99eb63
5 changed files with 319 additions and 108 deletions
14
.edge-connect.yaml.example
Normal file
14
.edge-connect.yaml.example
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
# Example EdgeConnect CLI Configuration File
|
||||||
|
# Place this file at ~/.edge-connect.yaml or specify with --config flag
|
||||||
|
|
||||||
|
# Base URL for the EdgeConnect API
|
||||||
|
base_url: "https://hub.apps.edge.platform.mg3.mdb.osc.live"
|
||||||
|
|
||||||
|
# Authentication credentials
|
||||||
|
username: "your-username@example.com"
|
||||||
|
password: "your-password"
|
||||||
|
|
||||||
|
# API version to use (v1 or v2)
|
||||||
|
# Default: v2
|
||||||
|
# Set via config, --api-version flag, or EDGE_CONNECT_API_VERSION env var
|
||||||
|
api_version: "v2"
|
||||||
190
cmd/app.go
190
cmd/app.go
|
|
@ -7,8 +7,10 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"edp.buildth.ing/DevFW-CICD/edge-connect-client/sdk/edgeconnect"
|
||||||
v2 "edp.buildth.ing/DevFW-CICD/edge-connect-client/sdk/edgeconnect/v2"
|
v2 "edp.buildth.ing/DevFW-CICD/edge-connect-client/sdk/edgeconnect/v2"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
@ -50,7 +52,45 @@ func validateBaseURL(baseURL string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSDKClient() *v2.Client {
|
func getAPIVersion() string {
|
||||||
|
version := viper.GetString("api_version")
|
||||||
|
if version == "" {
|
||||||
|
version = "v2" // default to v2
|
||||||
|
}
|
||||||
|
return strings.ToLower(version)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newSDKClientV1() *edgeconnect.Client {
|
||||||
|
baseURL := viper.GetString("base_url")
|
||||||
|
username := viper.GetString("username")
|
||||||
|
password := viper.GetString("password")
|
||||||
|
|
||||||
|
err := validateBaseURL(baseURL)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error parsing baseURL: '%s' with error: %s\n", baseURL, err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build options
|
||||||
|
opts := []edgeconnect.Option{
|
||||||
|
edgeconnect.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add logger only if debug flag is set
|
||||||
|
if debug {
|
||||||
|
logger := log.New(os.Stderr, "[DEBUG] ", log.LstdFlags)
|
||||||
|
opts = append(opts, edgeconnect.WithLogger(logger))
|
||||||
|
}
|
||||||
|
|
||||||
|
if username != "" && password != "" {
|
||||||
|
return edgeconnect.NewClientWithCredentials(baseURL, username, password, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to no auth for now - in production should require auth
|
||||||
|
return edgeconnect.NewClient(baseURL, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newSDKClientV2() *v2.Client {
|
||||||
baseURL := viper.GetString("base_url")
|
baseURL := viper.GetString("base_url")
|
||||||
username := viper.GetString("username")
|
username := viper.GetString("username")
|
||||||
password := viper.GetString("password")
|
password := viper.GetString("password")
|
||||||
|
|
@ -90,19 +130,37 @@ var createAppCmd = &cobra.Command{
|
||||||
Use: "create",
|
Use: "create",
|
||||||
Short: "Create a new Edge Connect application",
|
Short: "Create a new Edge Connect application",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
c := newSDKClient()
|
apiVersion := getAPIVersion()
|
||||||
input := &v2.NewAppInput{
|
var err error
|
||||||
Region: region,
|
|
||||||
App: v2.App{
|
if apiVersion == "v1" {
|
||||||
Key: v2.AppKey{
|
c := newSDKClientV1()
|
||||||
Organization: organization,
|
input := &edgeconnect.NewAppInput{
|
||||||
Name: appName,
|
Region: region,
|
||||||
Version: appVersion,
|
App: edgeconnect.App{
|
||||||
|
Key: edgeconnect.AppKey{
|
||||||
|
Organization: organization,
|
||||||
|
Name: appName,
|
||||||
|
Version: appVersion,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
|
err = c.CreateApp(context.Background(), input)
|
||||||
|
} else {
|
||||||
|
c := newSDKClientV2()
|
||||||
|
input := &v2.NewAppInput{
|
||||||
|
Region: region,
|
||||||
|
App: v2.App{
|
||||||
|
Key: v2.AppKey{
|
||||||
|
Organization: organization,
|
||||||
|
Name: appName,
|
||||||
|
Version: appVersion,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err = c.CreateApp(context.Background(), input)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := c.CreateApp(context.Background(), input)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error creating app: %v\n", err)
|
fmt.Printf("Error creating app: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
@ -115,19 +173,35 @@ var showAppCmd = &cobra.Command{
|
||||||
Use: "show",
|
Use: "show",
|
||||||
Short: "Show details of an Edge Connect application",
|
Short: "Show details of an Edge Connect application",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
c := newSDKClient()
|
apiVersion := getAPIVersion()
|
||||||
appKey := v2.AppKey{
|
|
||||||
Organization: organization,
|
|
||||||
Name: appName,
|
|
||||||
Version: appVersion,
|
|
||||||
}
|
|
||||||
|
|
||||||
app, err := c.ShowApp(context.Background(), appKey, region)
|
if apiVersion == "v1" {
|
||||||
if err != nil {
|
c := newSDKClientV1()
|
||||||
fmt.Printf("Error showing app: %v\n", err)
|
appKey := edgeconnect.AppKey{
|
||||||
os.Exit(1)
|
Organization: organization,
|
||||||
|
Name: appName,
|
||||||
|
Version: appVersion,
|
||||||
|
}
|
||||||
|
app, err := c.ShowApp(context.Background(), appKey, region)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error showing app: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Printf("Application details:\n%+v\n", app)
|
||||||
|
} else {
|
||||||
|
c := newSDKClientV2()
|
||||||
|
appKey := v2.AppKey{
|
||||||
|
Organization: organization,
|
||||||
|
Name: appName,
|
||||||
|
Version: appVersion,
|
||||||
|
}
|
||||||
|
app, err := c.ShowApp(context.Background(), appKey, region)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error showing app: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Printf("Application details:\n%+v\n", app)
|
||||||
}
|
}
|
||||||
fmt.Printf("Application details:\n%+v\n", app)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,21 +209,40 @@ var listAppsCmd = &cobra.Command{
|
||||||
Use: "list",
|
Use: "list",
|
||||||
Short: "List Edge Connect applications",
|
Short: "List Edge Connect applications",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
c := newSDKClient()
|
apiVersion := getAPIVersion()
|
||||||
appKey := v2.AppKey{
|
|
||||||
Organization: organization,
|
|
||||||
Name: appName,
|
|
||||||
Version: appVersion,
|
|
||||||
}
|
|
||||||
|
|
||||||
apps, err := c.ShowApps(context.Background(), appKey, region)
|
if apiVersion == "v1" {
|
||||||
if err != nil {
|
c := newSDKClientV1()
|
||||||
fmt.Printf("Error listing apps: %v\n", err)
|
appKey := edgeconnect.AppKey{
|
||||||
os.Exit(1)
|
Organization: organization,
|
||||||
}
|
Name: appName,
|
||||||
fmt.Println("Applications:")
|
Version: appVersion,
|
||||||
for _, app := range apps {
|
}
|
||||||
fmt.Printf("%+v\n", app)
|
apps, err := c.ShowApps(context.Background(), appKey, region)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error listing apps: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Println("Applications:")
|
||||||
|
for _, app := range apps {
|
||||||
|
fmt.Printf("%+v\n", app)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
c := newSDKClientV2()
|
||||||
|
appKey := v2.AppKey{
|
||||||
|
Organization: organization,
|
||||||
|
Name: appName,
|
||||||
|
Version: appVersion,
|
||||||
|
}
|
||||||
|
apps, err := c.ShowApps(context.Background(), appKey, region)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error listing apps: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Println("Applications:")
|
||||||
|
for _, app := range apps {
|
||||||
|
fmt.Printf("%+v\n", app)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -158,14 +251,27 @@ var deleteAppCmd = &cobra.Command{
|
||||||
Use: "delete",
|
Use: "delete",
|
||||||
Short: "Delete an Edge Connect application",
|
Short: "Delete an Edge Connect application",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
c := newSDKClient()
|
apiVersion := getAPIVersion()
|
||||||
appKey := v2.AppKey{
|
var err error
|
||||||
Organization: organization,
|
|
||||||
Name: appName,
|
if apiVersion == "v1" {
|
||||||
Version: appVersion,
|
c := newSDKClientV1()
|
||||||
|
appKey := edgeconnect.AppKey{
|
||||||
|
Organization: organization,
|
||||||
|
Name: appName,
|
||||||
|
Version: appVersion,
|
||||||
|
}
|
||||||
|
err = c.DeleteApp(context.Background(), appKey, region)
|
||||||
|
} else {
|
||||||
|
c := newSDKClientV2()
|
||||||
|
appKey := v2.AppKey{
|
||||||
|
Organization: organization,
|
||||||
|
Name: appName,
|
||||||
|
Version: appVersion,
|
||||||
|
}
|
||||||
|
err = c.DeleteApp(context.Background(), appKey, region)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := c.DeleteApp(context.Background(), appKey, region)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error deleting app: %v\n", err)
|
fmt.Printf("Error deleting app: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
||||||
|
|
@ -67,8 +67,8 @@ func runApply(configPath string, isDryRun bool, autoApprove bool) error {
|
||||||
|
|
||||||
fmt.Printf("✅ Configuration loaded successfully: %s\n", cfg.Metadata.Name)
|
fmt.Printf("✅ Configuration loaded successfully: %s\n", cfg.Metadata.Name)
|
||||||
|
|
||||||
// Step 3: Create EdgeConnect client
|
// Step 3: Create EdgeConnect client (apply always uses v2)
|
||||||
client := newSDKClient()
|
client := newSDKClientV2()
|
||||||
|
|
||||||
// Step 4: Create deployment planner
|
// Step 4: Create deployment planner
|
||||||
planner := apply.NewPlanner(client)
|
planner := apply.NewPlanner(client)
|
||||||
|
|
|
||||||
205
cmd/instance.go
205
cmd/instance.go
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"edp.buildth.ing/DevFW-CICD/edge-connect-client/sdk/edgeconnect"
|
||||||
v2 "edp.buildth.ing/DevFW-CICD/edge-connect-client/sdk/edgeconnect/v2"
|
v2 "edp.buildth.ing/DevFW-CICD/edge-connect-client/sdk/edgeconnect/v2"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
@ -26,30 +27,59 @@ var createInstanceCmd = &cobra.Command{
|
||||||
Use: "create",
|
Use: "create",
|
||||||
Short: "Create a new Edge Connect application instance",
|
Short: "Create a new Edge Connect application instance",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
c := newSDKClient()
|
apiVersion := getAPIVersion()
|
||||||
input := &v2.NewAppInstanceInput{
|
var err error
|
||||||
Region: region,
|
|
||||||
AppInst: v2.AppInstance{
|
if apiVersion == "v1" {
|
||||||
Key: v2.AppInstanceKey{
|
c := newSDKClientV1()
|
||||||
Organization: organization,
|
input := &edgeconnect.NewAppInstanceInput{
|
||||||
Name: instanceName,
|
Region: region,
|
||||||
CloudletKey: v2.CloudletKey{
|
AppInst: edgeconnect.AppInstance{
|
||||||
Organization: cloudletOrg,
|
Key: edgeconnect.AppInstanceKey{
|
||||||
Name: cloudletName,
|
Organization: organization,
|
||||||
|
Name: instanceName,
|
||||||
|
CloudletKey: edgeconnect.CloudletKey{
|
||||||
|
Organization: cloudletOrg,
|
||||||
|
Name: cloudletName,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
AppKey: edgeconnect.AppKey{
|
||||||
|
Organization: organization,
|
||||||
|
Name: appName,
|
||||||
|
Version: appVersion,
|
||||||
|
},
|
||||||
|
Flavor: edgeconnect.Flavor{
|
||||||
|
Name: flavorName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
AppKey: v2.AppKey{
|
}
|
||||||
Organization: organization,
|
err = c.CreateAppInstance(context.Background(), input)
|
||||||
Name: appName,
|
} else {
|
||||||
Version: appVersion,
|
c := newSDKClientV2()
|
||||||
|
input := &v2.NewAppInstanceInput{
|
||||||
|
Region: region,
|
||||||
|
AppInst: v2.AppInstance{
|
||||||
|
Key: v2.AppInstanceKey{
|
||||||
|
Organization: organization,
|
||||||
|
Name: instanceName,
|
||||||
|
CloudletKey: v2.CloudletKey{
|
||||||
|
Organization: cloudletOrg,
|
||||||
|
Name: cloudletName,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
AppKey: v2.AppKey{
|
||||||
|
Organization: organization,
|
||||||
|
Name: appName,
|
||||||
|
Version: appVersion,
|
||||||
|
},
|
||||||
|
Flavor: v2.Flavor{
|
||||||
|
Name: flavorName,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Flavor: v2.Flavor{
|
}
|
||||||
Name: flavorName,
|
err = c.CreateAppInstance(context.Background(), input)
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err := c.CreateAppInstance(context.Background(), input)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error creating app instance: %v\n", err)
|
fmt.Printf("Error creating app instance: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
@ -62,22 +92,41 @@ var showInstanceCmd = &cobra.Command{
|
||||||
Use: "show",
|
Use: "show",
|
||||||
Short: "Show details of an Edge Connect application instance",
|
Short: "Show details of an Edge Connect application instance",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
c := newSDKClient()
|
apiVersion := getAPIVersion()
|
||||||
instanceKey := v2.AppInstanceKey{
|
|
||||||
Organization: organization,
|
|
||||||
Name: instanceName,
|
|
||||||
CloudletKey: v2.CloudletKey{
|
|
||||||
Organization: cloudletOrg,
|
|
||||||
Name: cloudletName,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
instance, err := c.ShowAppInstance(context.Background(), instanceKey, region)
|
if apiVersion == "v1" {
|
||||||
if err != nil {
|
c := newSDKClientV1()
|
||||||
fmt.Printf("Error showing app instance: %v\n", err)
|
instanceKey := edgeconnect.AppInstanceKey{
|
||||||
os.Exit(1)
|
Organization: organization,
|
||||||
|
Name: instanceName,
|
||||||
|
CloudletKey: edgeconnect.CloudletKey{
|
||||||
|
Organization: cloudletOrg,
|
||||||
|
Name: cloudletName,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
instance, err := c.ShowAppInstance(context.Background(), instanceKey, region)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error showing app instance: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Printf("Application instance details:\n%+v\n", instance)
|
||||||
|
} else {
|
||||||
|
c := newSDKClientV2()
|
||||||
|
instanceKey := v2.AppInstanceKey{
|
||||||
|
Organization: organization,
|
||||||
|
Name: instanceName,
|
||||||
|
CloudletKey: v2.CloudletKey{
|
||||||
|
Organization: cloudletOrg,
|
||||||
|
Name: cloudletName,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
instance, err := c.ShowAppInstance(context.Background(), instanceKey, region)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error showing app instance: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Printf("Application instance details:\n%+v\n", instance)
|
||||||
}
|
}
|
||||||
fmt.Printf("Application instance details:\n%+v\n", instance)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,24 +134,46 @@ var listInstancesCmd = &cobra.Command{
|
||||||
Use: "list",
|
Use: "list",
|
||||||
Short: "List Edge Connect application instances",
|
Short: "List Edge Connect application instances",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
c := newSDKClient()
|
apiVersion := getAPIVersion()
|
||||||
instanceKey := v2.AppInstanceKey{
|
|
||||||
Organization: organization,
|
|
||||||
Name: instanceName,
|
|
||||||
CloudletKey: v2.CloudletKey{
|
|
||||||
Organization: cloudletOrg,
|
|
||||||
Name: cloudletName,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
instances, err := c.ShowAppInstances(context.Background(), instanceKey, region)
|
if apiVersion == "v1" {
|
||||||
if err != nil {
|
c := newSDKClientV1()
|
||||||
fmt.Printf("Error listing app instances: %v\n", err)
|
instanceKey := edgeconnect.AppInstanceKey{
|
||||||
os.Exit(1)
|
Organization: organization,
|
||||||
}
|
Name: instanceName,
|
||||||
fmt.Println("Application instances:")
|
CloudletKey: edgeconnect.CloudletKey{
|
||||||
for _, instance := range instances {
|
Organization: cloudletOrg,
|
||||||
fmt.Printf("%+v\n", instance)
|
Name: cloudletName,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
instances, err := c.ShowAppInstances(context.Background(), instanceKey, region)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error listing app instances: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Println("Application instances:")
|
||||||
|
for _, instance := range instances {
|
||||||
|
fmt.Printf("%+v\n", instance)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
c := newSDKClientV2()
|
||||||
|
instanceKey := v2.AppInstanceKey{
|
||||||
|
Organization: organization,
|
||||||
|
Name: instanceName,
|
||||||
|
CloudletKey: v2.CloudletKey{
|
||||||
|
Organization: cloudletOrg,
|
||||||
|
Name: cloudletName,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
instances, err := c.ShowAppInstances(context.Background(), instanceKey, region)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error listing app instances: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Println("Application instances:")
|
||||||
|
for _, instance := range instances {
|
||||||
|
fmt.Printf("%+v\n", instance)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -111,17 +182,33 @@ var deleteInstanceCmd = &cobra.Command{
|
||||||
Use: "delete",
|
Use: "delete",
|
||||||
Short: "Delete an Edge Connect application instance",
|
Short: "Delete an Edge Connect application instance",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
c := newSDKClient()
|
apiVersion := getAPIVersion()
|
||||||
instanceKey := v2.AppInstanceKey{
|
var err error
|
||||||
Organization: organization,
|
|
||||||
Name: instanceName,
|
if apiVersion == "v1" {
|
||||||
CloudletKey: v2.CloudletKey{
|
c := newSDKClientV1()
|
||||||
Organization: cloudletOrg,
|
instanceKey := edgeconnect.AppInstanceKey{
|
||||||
Name: cloudletName,
|
Organization: organization,
|
||||||
},
|
Name: instanceName,
|
||||||
|
CloudletKey: edgeconnect.CloudletKey{
|
||||||
|
Organization: cloudletOrg,
|
||||||
|
Name: cloudletName,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err = c.DeleteAppInstance(context.Background(), instanceKey, region)
|
||||||
|
} else {
|
||||||
|
c := newSDKClientV2()
|
||||||
|
instanceKey := v2.AppInstanceKey{
|
||||||
|
Organization: organization,
|
||||||
|
Name: instanceName,
|
||||||
|
CloudletKey: v2.CloudletKey{
|
||||||
|
Organization: cloudletOrg,
|
||||||
|
Name: cloudletName,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err = c.DeleteAppInstance(context.Background(), instanceKey, region)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := c.DeleteAppInstance(context.Background(), instanceKey, region)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error deleting app instance: %v\n", err)
|
fmt.Printf("Error deleting app instance: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
||||||
14
cmd/root.go
14
cmd/root.go
|
|
@ -9,11 +9,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cfgFile string
|
cfgFile string
|
||||||
baseURL string
|
baseURL string
|
||||||
username string
|
username string
|
||||||
password string
|
password string
|
||||||
debug bool
|
debug bool
|
||||||
|
apiVersion string
|
||||||
)
|
)
|
||||||
|
|
||||||
// rootCmd represents the base command when called without any subcommands
|
// rootCmd represents the base command when called without any subcommands
|
||||||
|
|
@ -40,11 +41,13 @@ func init() {
|
||||||
rootCmd.PersistentFlags().StringVar(&baseURL, "base-url", "", "base URL for the Edge Connect API")
|
rootCmd.PersistentFlags().StringVar(&baseURL, "base-url", "", "base URL for the Edge Connect API")
|
||||||
rootCmd.PersistentFlags().StringVar(&username, "username", "", "username for authentication")
|
rootCmd.PersistentFlags().StringVar(&username, "username", "", "username for authentication")
|
||||||
rootCmd.PersistentFlags().StringVar(&password, "password", "", "password for authentication")
|
rootCmd.PersistentFlags().StringVar(&password, "password", "", "password for authentication")
|
||||||
|
rootCmd.PersistentFlags().StringVar(&apiVersion, "api-version", "v2", "API version to use (v1 or v2)")
|
||||||
rootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "enable debug logging")
|
rootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "enable debug logging")
|
||||||
|
|
||||||
viper.BindPFlag("base_url", rootCmd.PersistentFlags().Lookup("base-url"))
|
viper.BindPFlag("base_url", rootCmd.PersistentFlags().Lookup("base-url"))
|
||||||
viper.BindPFlag("username", rootCmd.PersistentFlags().Lookup("username"))
|
viper.BindPFlag("username", rootCmd.PersistentFlags().Lookup("username"))
|
||||||
viper.BindPFlag("password", rootCmd.PersistentFlags().Lookup("password"))
|
viper.BindPFlag("password", rootCmd.PersistentFlags().Lookup("password"))
|
||||||
|
viper.BindPFlag("api_version", rootCmd.PersistentFlags().Lookup("api-version"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func initConfig() {
|
func initConfig() {
|
||||||
|
|
@ -53,6 +56,7 @@ func initConfig() {
|
||||||
viper.BindEnv("base_url", "EDGE_CONNECT_BASE_URL")
|
viper.BindEnv("base_url", "EDGE_CONNECT_BASE_URL")
|
||||||
viper.BindEnv("username", "EDGE_CONNECT_USERNAME")
|
viper.BindEnv("username", "EDGE_CONNECT_USERNAME")
|
||||||
viper.BindEnv("password", "EDGE_CONNECT_PASSWORD")
|
viper.BindEnv("password", "EDGE_CONNECT_PASSWORD")
|
||||||
|
viper.BindEnv("api_version", "EDGE_CONNECT_API_VERSION")
|
||||||
|
|
||||||
if cfgFile != "" {
|
if cfgFile != "" {
|
||||||
viper.SetConfigFile(cfgFile)
|
viper.SetConfigFile(cfgFile)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue