Renamed package and removed unused make calls

This commit is contained in:
Waldemar 2025-09-29 09:41:44 +02:00
parent 7c5db7fa39
commit 55e9f86759
16 changed files with 91 additions and 103 deletions

View file

@ -1,16 +1,12 @@
# ABOUTME: Build automation and code generation for EdgeXR SDK
# ABOUTME: Provides targets for generating types, testing, and building the CLI
.PHONY: generate test build clean install-tools
.PHONY: test build clean install-tools
# Install required tools
install-tools:
go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest
# Generate Go types from OpenAPI spec
generate:
oapi-codegen -config oapi-codegen.yaml api/swagger.json
# Run tests
test:
go test -v ./...
@ -35,7 +31,7 @@ lint:
golangci-lint run
# Run all checks (generate, test, lint)
check: generate test lint
check: test lint
# Default target
all: check build
all: check build

View file

@ -7,7 +7,7 @@ import (
"os"
"time"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/sdk/client"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/sdk/edgeconnect"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
@ -19,20 +19,20 @@ var (
region string
)
func newSDKClient() *client.Client {
func newSDKClient() *edgeconnect.Client {
baseURL := viper.GetString("base_url")
username := viper.GetString("username")
password := viper.GetString("password")
if username != "" && password != "" {
return client.NewClientWithCredentials(baseURL, username, password,
client.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
return edgeconnect.NewClientWithCredentials(baseURL, username, password,
edgeconnect.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
)
}
// Fallback to no auth for now - in production should require auth
return client.NewClient(baseURL,
client.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
return edgeconnect.NewClient(baseURL,
edgeconnect.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
)
}
@ -47,10 +47,10 @@ var createAppCmd = &cobra.Command{
Short: "Create a new Edge Connect application",
Run: func(cmd *cobra.Command, args []string) {
c := newSDKClient()
input := &client.NewAppInput{
input := &edgeconnect.NewAppInput{
Region: region,
App: client.App{
Key: client.AppKey{
App: edgeconnect.App{
Key: edgeconnect.AppKey{
Organization: organization,
Name: appName,
Version: appVersion,
@ -72,7 +72,7 @@ var showAppCmd = &cobra.Command{
Short: "Show details of an Edge Connect application",
Run: func(cmd *cobra.Command, args []string) {
c := newSDKClient()
appKey := client.AppKey{
appKey := edgeconnect.AppKey{
Organization: organization,
Name: appName,
Version: appVersion,
@ -92,7 +92,7 @@ var listAppsCmd = &cobra.Command{
Short: "List Edge Connect applications",
Run: func(cmd *cobra.Command, args []string) {
c := newSDKClient()
appKey := client.AppKey{
appKey := edgeconnect.AppKey{
Organization: organization,
Name: appName,
Version: appVersion,
@ -115,7 +115,7 @@ var deleteAppCmd = &cobra.Command{
Short: "Delete an Edge Connect application",
Run: func(cmd *cobra.Command, args []string) {
c := newSDKClient()
appKey := client.AppKey{
appKey := edgeconnect.AppKey{
Organization: organization,
Name: appName,
Version: appVersion,

View file

@ -5,7 +5,7 @@ import (
"fmt"
"os"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/sdk/client"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/sdk/edgeconnect"
"github.com/spf13/cobra"
)
@ -27,23 +27,23 @@ var createInstanceCmd = &cobra.Command{
Short: "Create a new Edge Connect application instance",
Run: func(cmd *cobra.Command, args []string) {
c := newSDKClient()
input := &client.NewAppInstanceInput{
input := &edgeconnect.NewAppInstanceInput{
Region: region,
AppInst: client.AppInstance{
Key: client.AppInstanceKey{
AppInst: edgeconnect.AppInstance{
Key: edgeconnect.AppInstanceKey{
Organization: organization,
Name: instanceName,
CloudletKey: client.CloudletKey{
CloudletKey: edgeconnect.CloudletKey{
Organization: cloudletOrg,
Name: cloudletName,
},
},
AppKey: client.AppKey{
AppKey: edgeconnect.AppKey{
Organization: organization,
Name: appName,
Version: appVersion,
},
Flavor: client.Flavor{
Flavor: edgeconnect.Flavor{
Name: flavorName,
},
},
@ -63,10 +63,10 @@ var showInstanceCmd = &cobra.Command{
Short: "Show details of an Edge Connect application instance",
Run: func(cmd *cobra.Command, args []string) {
c := newSDKClient()
instanceKey := client.AppInstanceKey{
instanceKey := edgeconnect.AppInstanceKey{
Organization: organization,
Name: instanceName,
CloudletKey: client.CloudletKey{
CloudletKey: edgeconnect.CloudletKey{
Organization: cloudletOrg,
Name: cloudletName,
},
@ -86,10 +86,10 @@ var listInstancesCmd = &cobra.Command{
Short: "List Edge Connect application instances",
Run: func(cmd *cobra.Command, args []string) {
c := newSDKClient()
instanceKey := client.AppInstanceKey{
instanceKey := edgeconnect.AppInstanceKey{
Organization: organization,
Name: instanceName,
CloudletKey: client.CloudletKey{
CloudletKey: edgeconnect.CloudletKey{
Organization: cloudletOrg,
Name: cloudletName,
},
@ -112,10 +112,10 @@ var deleteInstanceCmd = &cobra.Command{
Short: "Delete an Edge Connect application instance",
Run: func(cmd *cobra.Command, args []string) {
c := newSDKClient()
instanceKey := client.AppInstanceKey{
instanceKey := edgeconnect.AppInstanceKey{
Organization: organization,
Name: instanceName,
CloudletKey: client.CloudletKey{
CloudletKey: edgeconnect.CloudletKey{
Organization: cloudletOrg,
Name: cloudletName,
},

View file

@ -1,8 +0,0 @@
package: client
output: sdk/client/types_generated.go
generate:
models: true
client: false
embedded-spec: false
output-options:
skip-prune: true

View file

@ -1,7 +1,7 @@
// ABOUTME: Application instance lifecycle management APIs for EdgeXR Master Controller
// ABOUTME: Provides typed methods for creating, querying, and deleting application instances
package client
package edgeconnect
import (
"context"

View file

@ -1,7 +1,7 @@
// ABOUTME: Unit tests for AppInstance management APIs using httptest mock server
// ABOUTME: Tests create, show, list, refresh, and delete operations with error conditions
package client
package edgeconnect
import (
"context"

View file

@ -1,7 +1,7 @@
// ABOUTME: Application lifecycle management APIs for EdgeXR Master Controller
// ABOUTME: Provides typed methods for creating, querying, and deleting applications
package client
package edgeconnect
import (
"context"

View file

@ -1,7 +1,7 @@
// ABOUTME: Unit tests for App management APIs using httptest mock server
// ABOUTME: Tests create, show, list, and delete operations with error conditions
package client
package edgeconnect
import (
"context"

View file

@ -1,7 +1,7 @@
// ABOUTME: Authentication providers for EdgeXR Master Controller API
// ABOUTME: Supports Bearer token authentication with pluggable provider interface
package client
package edgeconnect
import (
"bytes"
@ -181,4 +181,4 @@ func NewNoAuthProvider() *NoAuthProvider {
// Attach does nothing (no authentication)
func (n *NoAuthProvider) Attach(ctx context.Context, req *http.Request) error {
return nil
}
}

View file

@ -1,7 +1,7 @@
// ABOUTME: Unit tests for authentication providers including username/password token flow
// ABOUTME: Tests token caching, login flow, and error conditions with mock servers
package client
package edgeconnect
import (
"context"
@ -223,4 +223,4 @@ func TestNewClientWithCredentials(t *testing.T) {
assert.Equal(t, "testuser", authProvider.Username)
assert.Equal(t, "testpass", authProvider.Password)
assert.Equal(t, "https://example.com", authProvider.BaseURL)
}
}

View file

@ -1,7 +1,7 @@
// ABOUTME: Core EdgeXR Master Controller SDK client with HTTP transport and auth
// ABOUTME: Provides typed APIs for app, instance, and cloudlet management operations
package client
package edgeconnect
import (
"net/http"
@ -20,10 +20,10 @@ type Client struct {
// RetryOptions configures retry behavior for API calls
type RetryOptions struct {
MaxRetries int
InitialDelay time.Duration
MaxDelay time.Duration
Multiplier float64
MaxRetries int
InitialDelay time.Duration
MaxDelay time.Duration
Multiplier float64
RetryableHTTPStatusCodes []int
}
@ -119,4 +119,4 @@ func (c *Client) logf(format string, v ...interface{}) {
if c.Logger != nil {
c.Logger.Printf(format, v...)
}
}
}

View file

@ -1,7 +1,7 @@
// ABOUTME: Cloudlet management APIs for EdgeXR Master Controller
// ABOUTME: Provides typed methods for creating, querying, and managing edge cloudlets
package client
package edgeconnect
import (
"context"

View file

@ -1,7 +1,7 @@
// ABOUTME: Unit tests for Cloudlet management APIs using httptest mock server
// ABOUTME: Tests create, show, list, delete, manifest, and resource usage operations
package client
package edgeconnect
import (
"context"

View file

@ -1,7 +1,7 @@
// ABOUTME: Core type definitions for EdgeXR Master Controller SDK
// ABOUTME: These types are based on the swagger API specification and existing client patterns
package client
package edgeconnect
import (
"encoding/json"

View file

@ -12,7 +12,7 @@ import (
"strings"
"time"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/sdk/client"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/sdk/edgeconnect"
)
func main() {
@ -24,20 +24,20 @@ func main() {
username := getEnvOrDefault("EDGEXR_USERNAME", "")
password := getEnvOrDefault("EDGEXR_PASSWORD", "")
var edgeClient *client.Client
var client *edgeconnect.Client
if token != "" {
fmt.Println("🔐 Using Bearer token authentication")
edgeClient = client.NewClient(baseURL,
client.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
client.WithAuthProvider(client.NewStaticTokenProvider(token)),
client.WithLogger(log.Default()),
client = edgeconnect.NewClient(baseURL,
edgeconnect.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
edgeconnect.WithAuthProvider(edgeconnect.NewStaticTokenProvider(token)),
edgeconnect.WithLogger(log.Default()),
)
} else if username != "" && password != "" {
fmt.Println("🔐 Using username/password authentication")
edgeClient = client.NewClientWithCredentials(baseURL, username, password,
client.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
client.WithLogger(log.Default()),
client = edgeconnect.NewClientWithCredentials(baseURL, username, password,
edgeconnect.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
edgeconnect.WithLogger(log.Default()),
)
} else {
log.Fatal("Authentication required: Set either EDGEXR_TOKEN or both EDGEXR_USERNAME and EDGEXR_PASSWORD")
@ -61,7 +61,7 @@ func main() {
fmt.Printf("Organization: %s, Region: %s\n\n", config.Organization, config.Region)
// Run the complete workflow
if err := runComprehensiveWorkflow(ctx, edgeClient, config); err != nil {
if err := runComprehensiveWorkflow(ctx, client, config); err != nil {
log.Fatalf("Workflow failed: %v", err)
}
@ -85,15 +85,15 @@ type WorkflowConfig struct {
FlavorName string
}
func runComprehensiveWorkflow(ctx context.Context, c *client.Client, config WorkflowConfig) error {
func runComprehensiveWorkflow(ctx context.Context, c *edgeconnect.Client, config WorkflowConfig) error {
fmt.Println("═══ Phase 1: Application Management ═══")
// 1. Create Application
fmt.Println("\n1⃣ Creating application...")
app := &client.NewAppInput{
app := &edgeconnect.NewAppInput{
Region: config.Region,
App: client.App{
Key: client.AppKey{
App: edgeconnect.App{
Key: edgeconnect.AppKey{
Organization: config.Organization,
Name: config.AppName,
Version: config.AppVersion,
@ -101,10 +101,10 @@ func runComprehensiveWorkflow(ctx context.Context, c *client.Client, config Work
Deployment: "kubernetes",
ImageType: "ImageTypeDocker",
ImagePath: "https://registry-1.docker.io/library/nginx:latest",
DefaultFlavor: client.Flavor{Name: config.FlavorName},
DefaultFlavor: edgeconnect.Flavor{Name: config.FlavorName},
ServerlessConfig: struct{}{},
AllowServerless: true,
RequiredOutboundConnections: []client.SecurityRule{
RequiredOutboundConnections: []edgeconnect.SecurityRule{
{
Protocol: "tcp",
PortRangeMin: 80,
@ -128,7 +128,7 @@ func runComprehensiveWorkflow(ctx context.Context, c *client.Client, config Work
// 2. Show Application Details
fmt.Println("\n2⃣ Querying application details...")
appKey := client.AppKey{
appKey := edgeconnect.AppKey{
Organization: config.Organization,
Name: config.AppName,
Version: config.AppVersion,
@ -146,7 +146,7 @@ func runComprehensiveWorkflow(ctx context.Context, c *client.Client, config Work
// 3. List Applications in Organization
fmt.Println("\n3⃣ Listing applications in organization...")
filter := client.AppKey{Organization: config.Organization}
filter := edgeconnect.AppKey{Organization: config.Organization}
apps, err := c.ShowApps(ctx, filter, config.Region)
if err != nil {
return fmt.Errorf("failed to list apps: %w", err)
@ -160,19 +160,19 @@ func runComprehensiveWorkflow(ctx context.Context, c *client.Client, config Work
// 4. Create Application Instance
fmt.Println("\n4⃣ Creating application instance...")
instance := &client.NewAppInstanceInput{
instance := &edgeconnect.NewAppInstanceInput{
Region: config.Region,
AppInst: client.AppInstance{
Key: client.AppInstanceKey{
AppInst: edgeconnect.AppInstance{
Key: edgeconnect.AppInstanceKey{
Organization: config.Organization,
Name: config.InstanceName,
CloudletKey: client.CloudletKey{
CloudletKey: edgeconnect.CloudletKey{
Organization: config.CloudletOrg,
Name: config.CloudletName,
},
},
AppKey: appKey,
Flavor: client.Flavor{Name: config.FlavorName},
Flavor: edgeconnect.Flavor{Name: config.FlavorName},
},
}
@ -184,10 +184,10 @@ func runComprehensiveWorkflow(ctx context.Context, c *client.Client, config Work
// 5. Wait for Application Instance to be Ready
fmt.Println("\n5⃣ Waiting for application instance to be ready...")
instanceKey := client.AppInstanceKey{
instanceKey := edgeconnect.AppInstanceKey{
Organization: config.Organization,
Name: config.InstanceName,
CloudletKey: client.CloudletKey{
CloudletKey: edgeconnect.CloudletKey{
Organization: config.CloudletOrg,
Name: config.CloudletName,
},
@ -207,7 +207,7 @@ func runComprehensiveWorkflow(ctx context.Context, c *client.Client, config Work
// 6. List Application Instances
fmt.Println("\n6⃣ Listing application instances...")
instances, err := c.ShowAppInstances(ctx, client.AppInstanceKey{Organization: config.Organization}, config.Region)
instances, err := c.ShowAppInstances(ctx, edgeconnect.AppInstanceKey{Organization: config.Organization}, config.Region)
if err != nil {
return fmt.Errorf("failed to list app instances: %w", err)
}
@ -228,7 +228,7 @@ func runComprehensiveWorkflow(ctx context.Context, c *client.Client, config Work
// 8. Show Cloudlet Details
fmt.Println("\n8⃣ Querying cloudlet information...")
cloudletKey := client.CloudletKey{
cloudletKey := edgeconnect.CloudletKey{
Organization: config.CloudletOrg,
Name: config.CloudletName,
}
@ -287,7 +287,7 @@ func runComprehensiveWorkflow(ctx context.Context, c *client.Client, config Work
// 13. Verify Cleanup
fmt.Println("\n1⃣3⃣ Verifying cleanup...")
_, err = c.ShowApp(ctx, appKey, config.Region)
if err != nil && fmt.Sprintf("%v", err) == client.ErrResourceNotFound.Error() {
if err != nil && fmt.Sprintf("%v", err) == edgeconnect.ErrResourceNotFound.Error() {
fmt.Printf("✅ Cleanup verified - app no longer exists\n")
} else if err != nil {
fmt.Printf("✅ Cleanup appears successful (verification returned: %v)\n", err)
@ -306,7 +306,7 @@ func getEnvOrDefault(key, defaultValue string) string {
}
// waitForInstanceReady polls the instance status until it's no longer "Creating" or timeout
func waitForInstanceReady(ctx context.Context, c *client.Client, instanceKey client.AppInstanceKey, region string, timeout time.Duration) (client.AppInstance, error) {
func waitForInstanceReady(ctx context.Context, c *edgeconnect.Client, instanceKey edgeconnect.AppInstanceKey, region string, timeout time.Duration) (edgeconnect.AppInstance, error) {
timeoutCtx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
@ -318,7 +318,7 @@ func waitForInstanceReady(ctx context.Context, c *client.Client, instanceKey cli
for {
select {
case <-timeoutCtx.Done():
return client.AppInstance{}, fmt.Errorf("timeout waiting for instance to be ready after %v", timeout)
return edgeconnect.AppInstance{}, fmt.Errorf("timeout waiting for instance to be ready after %v", timeout)
case <-ticker.C:
instance, err := c.ShowAppInstance(timeoutCtx, instanceKey, region)

View file

@ -12,7 +12,7 @@ import (
"strings"
"time"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/sdk/client"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/sdk/edgeconnect"
)
func main() {
@ -24,22 +24,22 @@ func main() {
username := getEnvOrDefault("EDGEXR_USERNAME", "")
password := getEnvOrDefault("EDGEXR_PASSWORD", "")
var edgeClient *client.Client
var edgeClient *edgeconnect.Client
if token != "" {
// Use static token authentication
fmt.Println("🔐 Using Bearer token authentication")
edgeClient = client.NewClient(baseURL,
client.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
client.WithAuthProvider(client.NewStaticTokenProvider(token)),
client.WithLogger(log.Default()),
edgeClient = edgeconnect.NewClient(baseURL,
edgeconnect.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
edgeconnect.WithAuthProvider(edgeconnect.NewStaticTokenProvider(token)),
edgeconnect.WithLogger(log.Default()),
)
} else if username != "" && password != "" {
// Use username/password authentication (matches existing client pattern)
fmt.Println("🔐 Using username/password authentication")
edgeClient = client.NewClientWithCredentials(baseURL, username, password,
client.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
client.WithLogger(log.Default()),
edgeClient = edgeconnect.NewClientWithCredentials(baseURL, username, password,
edgeconnect.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
edgeconnect.WithLogger(log.Default()),
)
} else {
log.Fatal("Authentication required: Set either EDGEXR_TOKEN or both EDGEXR_USERNAME and EDGEXR_PASSWORD")
@ -48,10 +48,10 @@ func main() {
ctx := context.Background()
// Example application to deploy
app := &client.NewAppInput{
app := &edgeconnect.NewAppInput{
Region: "EU",
App: client.App{
Key: client.AppKey{
App: edgeconnect.App{
Key: edgeconnect.AppKey{
Organization: "edp2",
Name: "my-edge-app",
Version: "1.0.0",
@ -59,7 +59,7 @@ func main() {
Deployment: "docker",
ImageType: "ImageTypeDocker",
ImagePath: "https://registry-1.docker.io/library/nginx:latest",
DefaultFlavor: client.Flavor{Name: "EU.small"},
DefaultFlavor: edgeconnect.Flavor{Name: "EU.small"},
ServerlessConfig: struct{}{},
AllowServerless: false,
},
@ -73,7 +73,7 @@ func main() {
fmt.Println("✅ SDK example completed successfully!")
}
func demonstrateAppLifecycle(ctx context.Context, edgeClient *client.Client, input *client.NewAppInput) error {
func demonstrateAppLifecycle(ctx context.Context, edgeClient *edgeconnect.Client, input *edgeconnect.NewAppInput) error {
appKey := input.App.Key
region := input.Region
@ -98,7 +98,7 @@ func demonstrateAppLifecycle(ctx context.Context, edgeClient *client.Client, inp
// Step 3: List applications in the organization
fmt.Println("\n3. Listing applications...")
filter := client.AppKey{Organization: appKey.Organization}
filter := edgeconnect.AppKey{Organization: appKey.Organization}
apps, err := edgeClient.ShowApps(ctx, filter, region)
if err != nil {
return fmt.Errorf("failed to list apps: %w", err)
@ -116,7 +116,7 @@ func demonstrateAppLifecycle(ctx context.Context, edgeClient *client.Client, inp
fmt.Println("\n5. Verifying deletion...")
_, err = edgeClient.ShowApp(ctx, appKey, region)
if err != nil {
if strings.Contains(fmt.Sprintf("%v", err), client.ErrResourceNotFound.Error()) {
if strings.Contains(fmt.Sprintf("%v", err), edgeconnect.ErrResourceNotFound.Error()) {
fmt.Printf("✅ App successfully deleted (not found)\n")
} else {
return fmt.Errorf("unexpected error verifying deletion: %w", err)