From dbf7ccb0d68fe4054bcfb9219e969b0fd98e2fe4 Mon Sep 17 00:00:00 2001 From: Stephan Lo Date: Fri, 17 Oct 2025 12:01:47 +0200 Subject: [PATCH] chore(http-timeout): removed timeout functionality when calling the API as it was not needed and malfunctional --- cmd/app.go | 6 ---- cmd/root.go | 12 +++---- sdk/edgeconnect/appinstance.go | 5 +-- sdk/edgeconnect/client.go | 36 +++++++------------ .../comprehensive/EdgeConnectConfig.yaml | 4 +-- 5 files changed, 20 insertions(+), 43 deletions(-) diff --git a/cmd/app.go b/cmd/app.go index 98914c6..a9f187f 100644 --- a/cmd/app.go +++ b/cmd/app.go @@ -53,7 +53,6 @@ func newSDKClient() *edgeconnect.Client { baseURL := viper.GetString("base_url") username := viper.GetString("username") password := viper.GetString("password") - createAppInstanceTimeout := viper.GetInt("create_app_instance_timeout") err := validateBaseURL(baseURL) if err != nil { @@ -61,20 +60,15 @@ func newSDKClient() *edgeconnect.Client { os.Exit(1) } - // Convert timeout from minutes to duration - timeout := time.Duration(createAppInstanceTimeout) * time.Minute - if username != "" && password != "" { return edgeconnect.NewClientWithCredentials(baseURL, username, password, edgeconnect.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}), - edgeconnect.WithCreateAppInstanceTimeout(timeout), ) } // Fallback to no auth for now - in production should require auth return edgeconnect.NewClient(baseURL, edgeconnect.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}), - edgeconnect.WithCreateAppInstanceTimeout(timeout), ) } diff --git a/cmd/root.go b/cmd/root.go index 7817622..480d8f5 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -9,11 +9,10 @@ import ( ) var ( - cfgFile string - baseURL string - username string - password string - createAppInstanceTimeout int // timeout in minutes + cfgFile string + baseURL string + username string + password string ) // rootCmd represents the base command when called without any subcommands @@ -40,12 +39,10 @@ func init() { rootCmd.PersistentFlags().StringVar(&baseURL, "base-url", "", "base URL for the Edge Connect API") rootCmd.PersistentFlags().StringVar(&username, "username", "", "username for authentication") rootCmd.PersistentFlags().StringVar(&password, "password", "", "password for authentication") - rootCmd.PersistentFlags().IntVar(&createAppInstanceTimeout, "create-app-instance-timeout", 10, "timeout in minutes for CreateAppInstance operations") viper.BindPFlag("base_url", rootCmd.PersistentFlags().Lookup("base-url")) viper.BindPFlag("username", rootCmd.PersistentFlags().Lookup("username")) viper.BindPFlag("password", rootCmd.PersistentFlags().Lookup("password")) - viper.BindPFlag("create_app_instance_timeout", rootCmd.PersistentFlags().Lookup("create-app-instance-timeout")) } func initConfig() { @@ -54,7 +51,6 @@ func initConfig() { viper.BindEnv("base_url", "EDGE_CONNECT_BASE_URL") viper.BindEnv("username", "EDGE_CONNECT_USERNAME") viper.BindEnv("password", "EDGE_CONNECT_PASSWORD") - viper.BindEnv("create_app_instance_timeout", "EDGE_CONNECT_CREATE_APP_INSTANCE_TIMEOUT") if cfgFile != "" { viper.SetConfigFile(cfgFile) diff --git a/sdk/edgeconnect/appinstance.go b/sdk/edgeconnect/appinstance.go index a02d9f4..a26f45c 100644 --- a/sdk/edgeconnect/appinstance.go +++ b/sdk/edgeconnect/appinstance.go @@ -15,14 +15,11 @@ import ( // CreateAppInstance creates a new application instance in the specified region // Maps to POST /auth/ctrl/CreateAppInst func (c *Client) CreateAppInstance(ctx context.Context, input *NewAppInstanceInput) error { - // Apply CreateAppInstance-specific timeout - timeoutCtx, cancel := context.WithTimeout(ctx, c.CreateAppInstanceTimeout) - defer cancel() transport := c.getTransport() url := c.BaseURL + "/api/v1/auth/ctrl/CreateAppInst" - resp, err := transport.Call(timeoutCtx, "POST", url, input) + resp, err := transport.Call(ctx, "POST", url, input) if err != nil { return fmt.Errorf("CreateAppInstance failed: %w", err) } diff --git a/sdk/edgeconnect/client.go b/sdk/edgeconnect/client.go index bcac042..2a79cff 100644 --- a/sdk/edgeconnect/client.go +++ b/sdk/edgeconnect/client.go @@ -11,12 +11,11 @@ import ( // Client represents the EdgeXR Master Controller SDK client type Client struct { - BaseURL string - HTTPClient *http.Client - AuthProvider AuthProvider - RetryOpts RetryOptions - Logger Logger - CreateAppInstanceTimeout time.Duration + BaseURL string + HTTPClient *http.Client + AuthProvider AuthProvider + RetryOpts RetryOptions + Logger Logger } // RetryOptions configures retry behavior for API calls @@ -82,21 +81,13 @@ func WithLogger(logger Logger) Option { } } -// WithCreateAppInstanceTimeout sets the timeout for CreateAppInstance operations -func WithCreateAppInstanceTimeout(timeout time.Duration) Option { - return func(c *Client) { - c.CreateAppInstanceTimeout = timeout - } -} - // NewClient creates a new EdgeXR SDK client func NewClient(baseURL string, options ...Option) *Client { client := &Client{ - BaseURL: strings.TrimRight(baseURL, "/"), - HTTPClient: &http.Client{Timeout: 30 * time.Second}, - AuthProvider: NewNoAuthProvider(), - RetryOpts: DefaultRetryOptions(), - CreateAppInstanceTimeout: 10 * time.Minute, + BaseURL: strings.TrimRight(baseURL, "/"), + HTTPClient: &http.Client{Timeout: 30 * time.Second}, + AuthProvider: NewNoAuthProvider(), + RetryOpts: DefaultRetryOptions(), } for _, opt := range options { @@ -110,11 +101,10 @@ func NewClient(baseURL string, options ...Option) *Client { // This matches the existing client pattern from client/client.go func NewClientWithCredentials(baseURL, username, password string, options ...Option) *Client { client := &Client{ - BaseURL: strings.TrimRight(baseURL, "/"), - HTTPClient: &http.Client{Timeout: 30 * time.Second}, - AuthProvider: NewUsernamePasswordProvider(baseURL, username, password, nil), - RetryOpts: DefaultRetryOptions(), - CreateAppInstanceTimeout: 10 * time.Minute, + BaseURL: strings.TrimRight(baseURL, "/"), + HTTPClient: &http.Client{Timeout: 30 * time.Second}, + AuthProvider: NewUsernamePasswordProvider(baseURL, username, password, nil), + RetryOpts: DefaultRetryOptions(), } for _, opt := range options { diff --git a/sdk/examples/comprehensive/EdgeConnectConfig.yaml b/sdk/examples/comprehensive/EdgeConnectConfig.yaml index fc24729..b45abc4 100644 --- a/sdk/examples/comprehensive/EdgeConnectConfig.yaml +++ b/sdk/examples/comprehensive/EdgeConnectConfig.yaml @@ -2,7 +2,7 @@ # How does it differ from the EdgeXR API? kind: edgeconnect-deployment metadata: - name: "edge-app-test" # name could be used for appName + name: "edge-app-demo" # name could be used for appName appVersion: "1.0.0" organization: "edp2" spec: @@ -15,7 +15,7 @@ spec: infraTemplate: - region: "EU" cloudletOrg: "TelekomOP" - cloudletName: "Hamburg" + cloudletName: "Munich" flavorName: "EU.small" network: outboundConnections: