2025-09-18 13:51:09 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
|
2025-10-21 11:40:35 +02:00
|
|
|
"edp.buildth.ing/DevFW-CICD/edge-connect-client/v2/sdk/edgeconnect"
|
|
|
|
|
v2 "edp.buildth.ing/DevFW-CICD/edge-connect-client/v2/sdk/edgeconnect/v2"
|
2025-09-18 13:51:09 +02:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
cloudletName string
|
|
|
|
|
cloudletOrg string
|
|
|
|
|
instanceName string
|
|
|
|
|
flavorName string
|
2025-11-13 15:40:36 +01:00
|
|
|
appId string
|
2025-09-18 13:51:09 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var appInstanceCmd = &cobra.Command{
|
|
|
|
|
Use: "instance",
|
|
|
|
|
Short: "Manage Edge Connect application instances",
|
|
|
|
|
Long: `Create, show, list, and delete Edge Connect application instances.`,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var createInstanceCmd = &cobra.Command{
|
|
|
|
|
Use: "create",
|
|
|
|
|
Short: "Create a new Edge Connect application instance",
|
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2025-10-20 13:41:50 +02:00
|
|
|
apiVersion := getAPIVersion()
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
|
|
if apiVersion == "v1" {
|
|
|
|
|
c := newSDKClientV1()
|
|
|
|
|
input := &edgeconnect.NewAppInstanceInput{
|
|
|
|
|
Region: region,
|
|
|
|
|
AppInst: edgeconnect.AppInstance{
|
|
|
|
|
Key: edgeconnect.AppInstanceKey{
|
|
|
|
|
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,
|
2025-09-18 13:51:09 +02:00
|
|
|
},
|
|
|
|
|
},
|
2025-10-20 13:41:50 +02:00
|
|
|
}
|
|
|
|
|
err = c.CreateAppInstance(context.Background(), input)
|
|
|
|
|
} else {
|
|
|
|
|
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,
|
|
|
|
|
},
|
2025-09-18 13:51:09 +02:00
|
|
|
},
|
2025-10-20 13:41:50 +02:00
|
|
|
}
|
|
|
|
|
err = c.CreateAppInstance(context.Background(), input)
|
2025-09-18 13:51:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Printf("Error creating app instance: %v\n", err)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
fmt.Println("Application instance created successfully")
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var showInstanceCmd = &cobra.Command{
|
|
|
|
|
Use: "show",
|
|
|
|
|
Short: "Show details of an Edge Connect application instance",
|
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2025-10-20 13:41:50 +02:00
|
|
|
apiVersion := getAPIVersion()
|
2025-09-18 13:51:09 +02:00
|
|
|
|
2025-10-20 13:41:50 +02:00
|
|
|
if apiVersion == "v1" {
|
|
|
|
|
c := newSDKClientV1()
|
|
|
|
|
instanceKey := edgeconnect.AppInstanceKey{
|
|
|
|
|
Organization: organization,
|
|
|
|
|
Name: instanceName,
|
|
|
|
|
CloudletKey: edgeconnect.CloudletKey{
|
|
|
|
|
Organization: cloudletOrg,
|
|
|
|
|
Name: cloudletName,
|
|
|
|
|
},
|
|
|
|
|
}
|
2025-11-13 15:40:36 +01:00
|
|
|
appkey := edgeconnect.AppKey{Name: appId}
|
|
|
|
|
instance, err := c.ShowAppInstance(context.Background(), instanceKey, appkey, region)
|
2025-10-20 13:41:50 +02:00
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
}
|
2025-11-13 15:40:36 +01:00
|
|
|
appkey := v2.AppKey{Name: appId}
|
|
|
|
|
instance, err := c.ShowAppInstance(context.Background(), instanceKey, appkey, region)
|
2025-10-20 13:41:50 +02:00
|
|
|
if err != nil {
|
|
|
|
|
fmt.Printf("Error showing app instance: %v\n", err)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
fmt.Printf("Application instance details:\n%+v\n", instance)
|
2025-09-18 13:51:09 +02:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var listInstancesCmd = &cobra.Command{
|
|
|
|
|
Use: "list",
|
|
|
|
|
Short: "List Edge Connect application instances",
|
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2025-10-20 13:41:50 +02:00
|
|
|
apiVersion := getAPIVersion()
|
2025-09-18 13:51:09 +02:00
|
|
|
|
2025-10-20 13:41:50 +02:00
|
|
|
if apiVersion == "v1" {
|
|
|
|
|
c := newSDKClientV1()
|
|
|
|
|
instanceKey := edgeconnect.AppInstanceKey{
|
|
|
|
|
Organization: organization,
|
|
|
|
|
Name: instanceName,
|
|
|
|
|
CloudletKey: edgeconnect.CloudletKey{
|
|
|
|
|
Organization: cloudletOrg,
|
|
|
|
|
Name: cloudletName,
|
|
|
|
|
},
|
|
|
|
|
}
|
2025-11-13 16:59:38 +01:00
|
|
|
appKey := edgeconnect.AppKey{Name: appId}
|
|
|
|
|
instances, err := c.ShowAppInstances(context.Background(), instanceKey, appKey, region)
|
2025-10-20 13:41:50 +02:00
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
}
|
2025-11-13 16:59:38 +01:00
|
|
|
appKey := v2.AppKey{Name: appId}
|
|
|
|
|
instances, err := c.ShowAppInstances(context.Background(), instanceKey, appKey, region)
|
2025-10-20 13:41:50 +02:00
|
|
|
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)
|
|
|
|
|
}
|
2025-09-18 13:51:09 +02:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var deleteInstanceCmd = &cobra.Command{
|
|
|
|
|
Use: "delete",
|
|
|
|
|
Short: "Delete an Edge Connect application instance",
|
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2025-10-20 13:41:50 +02:00
|
|
|
apiVersion := getAPIVersion()
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
|
|
if apiVersion == "v1" {
|
|
|
|
|
c := newSDKClientV1()
|
|
|
|
|
instanceKey := edgeconnect.AppInstanceKey{
|
|
|
|
|
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)
|
2025-09-18 13:51:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Printf("Error deleting app instance: %v\n", err)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
fmt.Println("Application instance deleted successfully")
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
rootCmd.AddCommand(appInstanceCmd)
|
|
|
|
|
appInstanceCmd.AddCommand(createInstanceCmd, showInstanceCmd, listInstancesCmd, deleteInstanceCmd)
|
|
|
|
|
|
|
|
|
|
// Add flags to all instance commands
|
|
|
|
|
instanceCmds := []*cobra.Command{createInstanceCmd, showInstanceCmd, listInstancesCmd, deleteInstanceCmd}
|
|
|
|
|
for _, cmd := range instanceCmds {
|
|
|
|
|
cmd.Flags().StringVarP(&organization, "org", "o", "", "organization name (required)")
|
|
|
|
|
cmd.Flags().StringVarP(&instanceName, "name", "n", "", "instance name (required)")
|
|
|
|
|
cmd.Flags().StringVarP(&cloudletName, "cloudlet", "c", "", "cloudlet name (required)")
|
|
|
|
|
cmd.Flags().StringVarP(&cloudletOrg, "cloudlet-org", "", "", "cloudlet organization (required)")
|
|
|
|
|
cmd.Flags().StringVarP(®ion, "region", "r", "", "region (required)")
|
2025-11-13 15:40:36 +01:00
|
|
|
cmd.Flags().StringVarP(&appId, "app-id", "i", "", "application id")
|
2025-09-18 13:51:09 +02:00
|
|
|
|
2025-10-22 12:47:15 +02:00
|
|
|
if err := cmd.MarkFlagRequired("org"); err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
if err := cmd.MarkFlagRequired("name"); err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
if err := cmd.MarkFlagRequired("cloudlet"); err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
if err := cmd.MarkFlagRequired("cloudlet-org"); err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
if err := cmd.MarkFlagRequired("region"); err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
2025-09-18 13:51:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add additional flags for create command
|
|
|
|
|
createInstanceCmd.Flags().StringVarP(&appName, "app", "a", "", "application name (required)")
|
|
|
|
|
createInstanceCmd.Flags().StringVarP(&appVersion, "version", "v", "", "application version")
|
|
|
|
|
createInstanceCmd.Flags().StringVarP(&flavorName, "flavor", "f", "", "flavor name (required)")
|
2025-10-22 12:47:15 +02:00
|
|
|
if err := createInstanceCmd.MarkFlagRequired("app"); err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
if err := createInstanceCmd.MarkFlagRequired("flavor"); err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
2025-09-18 13:51:09 +02:00
|
|
|
}
|