diff --git a/cmd/ucpd/ucp-dev.yaml b/cmd/ucpd/ucp-dev.yaml index a7561eeb7a..a754c4579f 100644 --- a/cmd/ucpd/ucp-dev.yaml +++ b/cmd/ucpd/ucp-dev.yaml @@ -52,6 +52,8 @@ initialization: Applications.Datastores: "http://localhost:8080" Microsoft.Resources: "http://localhost:5017" kind: "UCPNative" + # This is the directory location which contains manifests to be registered. + manifestDirectory: "" identity: authMethod: default diff --git a/deploy/Chart/templates/ucp/configmaps.yaml b/deploy/Chart/templates/ucp/configmaps.yaml index cc9968228c..f6a93131a5 100644 --- a/deploy/Chart/templates/ucp/configmaps.yaml +++ b/deploy/Chart/templates/ucp/configmaps.yaml @@ -50,6 +50,7 @@ data: - id: "/planes/aws/aws" properties: kind: "AWS" + manifestDirectory: "" identity: authMethod: UCPCredential diff --git a/pkg/cli/cmd/resourceprovider/create/create.go b/pkg/cli/cmd/resourceprovider/create/create.go index b5c55b775f..162bef3c76 100644 --- a/pkg/cli/cmd/resourceprovider/create/create.go +++ b/pkg/cli/cmd/resourceprovider/create/create.go @@ -19,16 +19,15 @@ package create import ( "context" - v1 "github.com/radius-project/radius/pkg/armrpc/api/v1" + aztoken "github.com/radius-project/radius/pkg/azure/tokencredentials" "github.com/radius-project/radius/pkg/cli" "github.com/radius-project/radius/pkg/cli/cmd/commonflags" "github.com/radius-project/radius/pkg/cli/cmd/resourceprovider/common" - "github.com/radius-project/radius/pkg/cli/connections" "github.com/radius-project/radius/pkg/cli/framework" "github.com/radius-project/radius/pkg/cli/manifest" "github.com/radius-project/radius/pkg/cli/output" "github.com/radius-project/radius/pkg/cli/workspaces" - "github.com/radius-project/radius/pkg/to" + "github.com/radius-project/radius/pkg/sdk" "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" "github.com/spf13/cobra" ) @@ -70,22 +69,26 @@ rad resource-provider create --from-file /path/to/input.json // Runner is the Runner implementation for the `rad resource-provider create` command. type Runner struct { - ConnectionFactory connections.Factory - ConfigHolder *framework.ConfigHolder - Output output.Interface - Format string - Workspace *workspaces.Workspace + UCPClientFactory *v20231001preview.ClientFactory + ConfigHolder *framework.ConfigHolder + Output output.Interface + Format string + Workspace *workspaces.Workspace ResourceProviderManifestFilePath string ResourceProvider *manifest.ResourceProvider + Logger func(format string, args ...any) } // NewRunner creates an instance of the runner for the `rad resource-provider create` command. func NewRunner(factory framework.Factory) *Runner { + output := factory.GetOutput() return &Runner{ - ConnectionFactory: factory.GetConnectionFactory(), - ConfigHolder: factory.GetConfigHolder(), - Output: factory.GetOutput(), + ConfigHolder: factory.GetConfigHolder(), + Output: output, + Logger: func(format string, args ...any) { + output.LogInfo(format, args...) + }, } } @@ -114,76 +117,49 @@ func (r *Runner) Validate(cmd *cobra.Command, args []string) error { // Run runs the `rad resource-provider create` command. func (r *Runner) Run(ctx context.Context) error { - client, err := r.ConnectionFactory.CreateApplicationsManagementClient(ctx, *r.Workspace) - if err != nil { - return err + // Initialize the client factory if it hasn't been set externally. + // This allows for flexibility where a test UCPClientFactory can be set externally during testing. + if r.UCPClientFactory == nil { + err := r.initializeClientFactory(ctx, r.Workspace) + if err != nil { + return err + } } - r.Output.LogInfo("Creating resource provider %s", r.ResourceProvider.Name) - _, err = client.CreateOrUpdateResourceProvider(ctx, "local", r.ResourceProvider.Name, &v20231001preview.ResourceProviderResource{ - Location: to.Ptr(v1.LocationGlobal), - Properties: &v20231001preview.ResourceProviderProperties{}, - }) - if err != nil { + // Proceed with registering manifests + if err := manifest.RegisterFile(ctx, r.UCPClientFactory, "local", r.ResourceProviderManifestFilePath, r.Logger); err != nil { return err } - // The location resource contains references to all of the resource types and API versions that the resource provider supports. - // We're instantiating the struct here so we can update it as we loop. - locationResource := v20231001preview.LocationResource{ - Properties: &v20231001preview.LocationProperties{ - ResourceTypes: map[string]*v20231001preview.LocationResourceType{}, - }, + response, err := r.UCPClientFactory.NewResourceProvidersClient().Get(ctx, "local", r.ResourceProvider.Name, nil) + if err != nil { + return err } - for resourceTypeName, resourceType := range r.ResourceProvider.Types { - r.Output.LogInfo("Creating resource type %s/%s", r.ResourceProvider.Name, resourceTypeName) - _, err := client.CreateOrUpdateResourceType(ctx, "local", r.ResourceProvider.Name, resourceTypeName, &v20231001preview.ResourceTypeResource{ - Properties: &v20231001preview.ResourceTypeProperties{ - DefaultAPIVersion: resourceType.DefaultAPIVersion, - }, - }) - if err != nil { - return err - } - - locationResourceType := &v20231001preview.LocationResourceType{ - APIVersions: map[string]map[string]any{}, - } - - for apiVersionName := range resourceType.APIVersions { - r.Output.LogInfo("Creating API Version %s/%s@%s", r.ResourceProvider.Name, resourceTypeName, apiVersionName) - _, err := client.CreateOrUpdateAPIVersion(ctx, "local", r.ResourceProvider.Name, resourceTypeName, apiVersionName, &v20231001preview.APIVersionResource{ - Properties: &v20231001preview.APIVersionProperties{}, - }) - if err != nil { - return err - } - - locationResourceType.APIVersions[apiVersionName] = map[string]any{} - } - - locationResource.Properties.ResourceTypes[resourceTypeName] = locationResourceType - } + // Add a blank line before printing the result. + r.Output.LogInfo("") - r.Output.LogInfo("Creating location %s/%s", r.ResourceProvider.Name, v1.LocationGlobal) - _, err = client.CreateOrUpdateLocation(ctx, "local", r.ResourceProvider.Name, v1.LocationGlobal, &locationResource) + err = r.Output.WriteFormatted(r.Format, response, common.GetResourceProviderTableFormat()) if err != nil { return err } - response, err := client.GetResourceProvider(ctx, "local", r.ResourceProvider.Name) + return nil +} + +func (r *Runner) initializeClientFactory(ctx context.Context, workspace *workspaces.Workspace) error { + connection, err := workspace.Connect(ctx) if err != nil { return err } - // Add a blank line before printing the result. - r.Output.LogInfo("") + clientOptions := sdk.NewClientOptions(connection) - err = r.Output.WriteFormatted(r.Format, response, common.GetResourceProviderTableFormat()) + clientFactory, err := v20231001preview.NewClientFactory(&aztoken.AnonymousCredential{}, clientOptions) if err != nil { return err } + r.UCPClientFactory = clientFactory return nil } diff --git a/pkg/cli/cmd/resourceprovider/create/create_test.go b/pkg/cli/cmd/resourceprovider/create/create_test.go index 83f7f317db..d74123e709 100644 --- a/pkg/cli/cmd/resourceprovider/create/create_test.go +++ b/pkg/cli/cmd/resourceprovider/create/create_test.go @@ -17,22 +17,17 @@ limitations under the License. package create import ( + "bytes" "context" + "fmt" "testing" - v1 "github.com/radius-project/radius/pkg/armrpc/api/v1" - "github.com/radius-project/radius/pkg/cli/clients" - "github.com/radius-project/radius/pkg/cli/cmd/resourceprovider/common" - "github.com/radius-project/radius/pkg/cli/connections" "github.com/radius-project/radius/pkg/cli/framework" "github.com/radius-project/radius/pkg/cli/manifest" "github.com/radius-project/radius/pkg/cli/output" "github.com/radius-project/radius/pkg/cli/workspaces" - "github.com/radius-project/radius/pkg/to" - "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" "github.com/radius-project/radius/test/radcli" "github.com/stretchr/testify/require" - "go.uber.org/mock/gomock" ) func Test_CommandValidation(t *testing.T) { @@ -68,101 +63,43 @@ func Test_Validate(t *testing.T) { ConfigHolder: framework.ConfigHolder{Config: config}, }, } + radcli.SharedValidateValidation(t, NewCommand, testcases) } func Test_Run(t *testing.T) { t.Run("Success: resource provider created", func(t *testing.T) { - ctrl := gomock.NewController(t) resourceProviderData, err := manifest.ReadFile("testdata/valid.yaml") require.NoError(t, err) - expectedResourceProvider := v20231001preview.ResourceProviderResource{ - Location: to.Ptr(v1.LocationGlobal), - Properties: &v20231001preview.ResourceProviderProperties{}, - } - expectedResourceType := v20231001preview.ResourceTypeResource{ - Properties: &v20231001preview.ResourceTypeProperties{}, - } - expectedAPIVersion := v20231001preview.APIVersionResource{ - Properties: &v20231001preview.APIVersionProperties{}, - } - expectedLocation := v20231001preview.LocationResource{ - Properties: &v20231001preview.LocationProperties{ - ResourceTypes: map[string]*v20231001preview.LocationResourceType{ - "testResources": { - APIVersions: map[string]map[string]any{ - "2025-01-01-preview": {}, - }, - }, - }, - }, - } + expectedResourceType := "testResources" + expectedAPIVersion := "2025-01-01-preview" - appManagementClient := clients.NewMockApplicationsManagementClient(ctrl) - appManagementClient.EXPECT(). - CreateOrUpdateResourceProvider(gomock.Any(), "local", "MyCompany.Resources", &expectedResourceProvider). - Return(expectedResourceProvider, nil). - Times(1) - appManagementClient.EXPECT(). - CreateOrUpdateResourceType(gomock.Any(), "local", "MyCompany.Resources", "testResources", &expectedResourceType). - Return(expectedResourceType, nil). - Times(1) - appManagementClient.EXPECT(). - CreateOrUpdateAPIVersion(gomock.Any(), "local", "MyCompany.Resources", "testResources", "2025-01-01-preview", &expectedAPIVersion). - Return(expectedAPIVersion, nil). - Times(1) - appManagementClient.EXPECT(). - CreateOrUpdateLocation(gomock.Any(), "local", "MyCompany.Resources", v1.LocationGlobal, &expectedLocation). - Return(expectedLocation, nil). - Times(1) - appManagementClient.EXPECT(). - GetResourceProvider(gomock.Any(), "local", "MyCompany.Resources"). - Return(expectedResourceProvider, nil). - Times(1) - - outputSink := &output.MockOutput{} + clientFactory, err := manifest.NewTestClientFactory() + require.NoError(t, err) + + var logBuffer bytes.Buffer + logger := func(format string, args ...any) { + fmt.Fprintf(&logBuffer, format+"\n", args...) + } runner := &Runner{ - ConnectionFactory: &connections.MockFactory{ApplicationsManagementClient: appManagementClient}, - Output: outputSink, - Workspace: &workspaces.Workspace{}, - ResourceProvider: resourceProviderData, - Format: "table", + UCPClientFactory: clientFactory, + Output: &output.MockOutput{}, + Workspace: &workspaces.Workspace{}, + ResourceProvider: resourceProviderData, + Format: "table", + Logger: logger, + ResourceProviderManifestFilePath: "testdata/valid.yaml", } err = runner.Run(context.Background()) require.NoError(t, err) - expectedOutput := []any{ - output.LogOutput{ - Format: "Creating resource provider %s", - Params: []any{"MyCompany.Resources"}, - }, - output.LogOutput{ - Format: "Creating resource type %s/%s", - Params: []any{"MyCompany.Resources", "testResources"}, - }, - output.LogOutput{ - Format: "Creating API Version %s/%s@%s", - Params: []any{"MyCompany.Resources", "testResources", "2025-01-01-preview"}, - }, - output.LogOutput{ - Format: "Creating location %s/%s", - Params: []any{"MyCompany.Resources", "global"}, - }, - output.LogOutput{ - Format: "", - Params: nil, - }, - output.FormattedOutput{ - Format: "table", - Obj: expectedResourceProvider, - Options: common.GetResourceProviderTableFormat(), - }, - } - require.Equal(t, expectedOutput, outputSink.Writes) + logOutput := logBuffer.String() + require.Contains(t, logOutput, fmt.Sprintf("Creating resource provider %s", resourceProviderData.Name)) + require.Contains(t, logOutput, fmt.Sprintf("Creating resource type %s/%s", resourceProviderData.Name, expectedResourceType)) + require.Contains(t, logOutput, fmt.Sprintf("Creating API Version %s/%s@%s", resourceProviderData.Name, expectedResourceType, expectedAPIVersion)) }) - } diff --git a/pkg/cli/connections/factory.go b/pkg/cli/connections/factory.go index 93b34f0142..cd7bda56dd 100644 --- a/pkg/cli/connections/factory.go +++ b/pkg/cli/connections/factory.go @@ -18,13 +18,11 @@ package connections import ( "context" - "errors" "fmt" aztoken "github.com/radius-project/radius/pkg/azure/tokencredentials" "github.com/radius-project/radius/pkg/cli/clients" "github.com/radius-project/radius/pkg/cli/clients_new/generated" - "github.com/radius-project/radius/pkg/cli/clierrors" cli_credential "github.com/radius-project/radius/pkg/cli/credential" "github.com/radius-project/radius/pkg/cli/deployment" "github.com/radius-project/radius/pkg/cli/kubernetes" @@ -55,18 +53,11 @@ type impl struct { // CreateDeploymentClient connects to a workspace, tests the connection, creates a deployment client and an operations // client, and returns them along with the resource group name. It returns an error if any of the steps fail. func (i *impl) CreateDeploymentClient(ctx context.Context, workspace workspaces.Workspace) (clients.DeploymentClient, error) { - connection, err := workspace.Connect() + connection, err := workspace.Connect(ctx) if err != nil { return nil, err } - err = sdk.TestConnection(ctx, connection) - if errors.Is(err, &sdk.ErrRadiusNotInstalled{}) { - return nil, clierrors.MessageWithCause(err, "Could not connect to Radius.") - } else if err != nil { - return nil, err - } - armClientOptions := sdk.NewClientOptions(connection) dc, err := sdkclients.NewResourceDeploymentsClient(&sdkclients.Options{ Cred: &aztoken.AnonymousCredential{}, @@ -102,18 +93,11 @@ func (i *impl) CreateDeploymentClient(ctx context.Context, workspace workspaces. // CreateDiagnosticsClient creates a DiagnosticsClient by connecting to a workspace, testing the connection, and creating // clients for applications, containers, environments, and gateways. If an error occurs, it is returned. func (i *impl) CreateDiagnosticsClient(ctx context.Context, workspace workspaces.Workspace) (clients.DiagnosticsClient, error) { - connection, err := workspace.Connect() + connection, err := workspace.Connect(ctx) if err != nil { return nil, err } - err = sdk.TestConnection(ctx, connection) - if errors.Is(err, &sdk.ErrRadiusNotInstalled{}) { - return nil, clierrors.MessageWithCause(err, "Could not connect to Radius.") - } else if err != nil { - return nil, err - } - connectionConfig, err := workspace.ConnectionConfig() if err != nil { return nil, err @@ -168,18 +152,11 @@ func (i *impl) CreateDiagnosticsClient(ctx context.Context, workspace workspaces // CreateApplicationsManagementClient connects to the workspace, tests the connection, and returns a // UCPApplicationsManagementClient if successful, or an error if unsuccessful. func (*impl) CreateApplicationsManagementClient(ctx context.Context, workspace workspaces.Workspace) (clients.ApplicationsManagementClient, error) { - connection, err := workspace.Connect() + connection, err := workspace.Connect(ctx) if err != nil { return nil, err } - err = sdk.TestConnection(ctx, connection) - if errors.Is(err, &sdk.ErrRadiusNotInstalled{}) { - return nil, clierrors.MessageWithCause(err, "Could not connect to Radius.") - } else if err != nil { - return nil, err - } - return &clients.UCPApplicationsManagementClient{ RootScope: workspace.Scope, ClientOptions: sdk.NewClientOptions(connection), @@ -192,18 +169,11 @@ func (*impl) CreateApplicationsManagementClient(ctx context.Context, workspace w // CreateCredentialManagementClient establishes a connection to a workspace, tests the connection, creates Azure and AWS // credential clients, and returns a UCPCredentialManagementClient. An error is returned if any of the steps fail. func (*impl) CreateCredentialManagementClient(ctx context.Context, workspace workspaces.Workspace) (cli_credential.CredentialManagementClient, error) { - connection, err := workspace.Connect() + connection, err := workspace.Connect(ctx) if err != nil { return nil, err } - err = sdk.TestConnection(ctx, connection) - if errors.Is(err, &sdk.ErrRadiusNotInstalled{}) { - return nil, clierrors.MessageWithCause(err, "Could not connect to Radius.") - } else if err != nil { - return nil, err - } - clientOptions := sdk.NewClientOptions(connection) azureCredentialClient, err := v20231001preview.NewAzureCredentialsClient(&aztoken.AnonymousCredential{}, clientOptions) diff --git a/pkg/cli/manifest/registermanifest.go b/pkg/cli/manifest/registermanifest.go new file mode 100644 index 0000000000..289f96d5e5 --- /dev/null +++ b/pkg/cli/manifest/registermanifest.go @@ -0,0 +1,168 @@ +/* +Copyright 2023 The Radius Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package manifest + +import ( + "context" + "fmt" + "os" + "path/filepath" + + v1 "github.com/radius-project/radius/pkg/armrpc/api/v1" + "github.com/radius-project/radius/pkg/to" + "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" +) + +// RegisterFile registers a manifest file +func RegisterFile(ctx context.Context, clientFactory *v20231001preview.ClientFactory, planeName string, filePath string, logger func(format string, args ...any)) error { + // Check for valid file path + if filePath == "" { + return fmt.Errorf("invalid manifest file path") + } + + // Read the manifest file + resourceProvider, err := ReadFile(filePath) + if err != nil { + return err + } + + logIfEnabled(logger, "Creating resource provider %s", resourceProvider.Name) + resourceProviderPoller, err := clientFactory.NewResourceProvidersClient().BeginCreateOrUpdate(ctx, planeName, resourceProvider.Name, v20231001preview.ResourceProviderResource{ + Location: to.Ptr(v1.LocationGlobal), + Properties: &v20231001preview.ResourceProviderProperties{}, + }, nil) + if err != nil { + return err + } + + _, err = resourceProviderPoller.PollUntilDone(ctx, nil) + if err != nil { + return err + } + + // The location resource contains references to all of the resource types and API versions that the resource provider supports. + // We're instantiating the struct here so we can update it as we loop. + locationResource := v20231001preview.LocationResource{ + Properties: &v20231001preview.LocationProperties{ + ResourceTypes: map[string]*v20231001preview.LocationResourceType{}, + }, + } + + for resourceTypeName, resourceType := range resourceProvider.Types { + logIfEnabled(logger, "Creating resource type %s/%s", resourceProvider.Name, resourceTypeName) + resourceTypePoller, err := clientFactory.NewResourceTypesClient().BeginCreateOrUpdate(ctx, planeName, resourceProvider.Name, resourceTypeName, v20231001preview.ResourceTypeResource{ + Properties: &v20231001preview.ResourceTypeProperties{ + DefaultAPIVersion: resourceType.DefaultAPIVersion, + }, + }, nil) + if err != nil { + return err + } + + _, err = resourceTypePoller.PollUntilDone(ctx, nil) + if err != nil { + return err + } + + locationResourceType := &v20231001preview.LocationResourceType{ + APIVersions: map[string]map[string]any{}, + } + + for apiVersionName := range resourceType.APIVersions { + logIfEnabled(logger, "Creating API Version %s/%s@%s", resourceProvider.Name, resourceTypeName, apiVersionName) + apiVersionsPoller, err := clientFactory.NewAPIVersionsClient().BeginCreateOrUpdate(ctx, planeName, resourceProvider.Name, resourceTypeName, apiVersionName, v20231001preview.APIVersionResource{ + Properties: &v20231001preview.APIVersionProperties{}, + }, nil) + if err != nil { + return err + } + + _, err = apiVersionsPoller.PollUntilDone(ctx, nil) + if err != nil { + return err + } + + locationResourceType.APIVersions[apiVersionName] = map[string]any{} + } + + locationResource.Properties.ResourceTypes[resourceTypeName] = locationResourceType + } + + logIfEnabled(logger, "Creating location %s/%s", resourceProvider.Name, v1.LocationGlobal) + locationPoller, err := clientFactory.NewLocationsClient().BeginCreateOrUpdate(ctx, planeName, resourceProvider.Name, v1.LocationGlobal, locationResource, nil) + if err != nil { + return err + } + + _, err = locationPoller.PollUntilDone(ctx, nil) + if err != nil { + return err + } + + _, err = clientFactory.NewResourceProvidersClient().Get(ctx, planeName, resourceProvider.Name, nil) + if err != nil { + return err + } + + return nil +} + +// RegisterDirectory registers all manifest files in a directory +func RegisterDirectory(ctx context.Context, clientFactory *v20231001preview.ClientFactory, planeName string, directoryPath string, logger func(format string, args ...any)) error { + // Check for valid directory path + if directoryPath == "" { + return fmt.Errorf("invalid manifest directory") + } + + info, err := os.Stat(directoryPath) + if err != nil { + return fmt.Errorf("failed to access manifest path %s: %w", directoryPath, err) + } + + if !info.IsDir() { + return fmt.Errorf("manifest path %s is not a directory", directoryPath) + } + + // List all files in the manifestDirectory + files, err := os.ReadDir(directoryPath) + if err != nil { + return err + } + + // Iterate over each file in the directory + for _, fileInfo := range files { + if fileInfo.IsDir() { + continue // Skip directories + } + filePath := filepath.Join(directoryPath, fileInfo.Name()) + + logIfEnabled(logger, "Registering manifest %s", filePath) + err = RegisterFile(ctx, clientFactory, planeName, filePath, logger) + if err != nil { + return fmt.Errorf("failed to register manifest file %s: %w", filePath, err) + } + } + + return nil +} + +// Define an optional logger to prevent nil pointer dereference +func logIfEnabled(logger func(format string, args ...any), format string, args ...any) { + if logger != nil { + logger(format, args...) + } +} diff --git a/pkg/cli/manifest/registermanifest_test.go b/pkg/cli/manifest/registermanifest_test.go new file mode 100644 index 0000000000..cc2c1ec525 --- /dev/null +++ b/pkg/cli/manifest/registermanifest_test.go @@ -0,0 +1,160 @@ +/* +Copyright 2023 The Radius Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package manifest + +import ( + "bytes" + "context" + "fmt" + "testing" + + // armpolicy "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/policy" + + "github.com/radius-project/radius/pkg/to" + "github.com/stretchr/testify/require" +) + +func TestRegisterDirectory(t *testing.T) { + tests := []struct { + name string + planeName string + directoryPath string + expectError bool + expectedErrorMessage string + expectedResourceProvider string + }{ + { + name: "Success", + planeName: "local", + directoryPath: "testdata/registerdirectory", + expectError: false, + expectedErrorMessage: "", + expectedResourceProvider: "MyCompany2.CompanyName2", + }, + { + name: "EmptyDirectoryPath", + planeName: "local", + directoryPath: "", + expectError: true, + expectedErrorMessage: "invalid manifest directory", + expectedResourceProvider: "", + }, + { + name: "InvalidDirectoryPath", + planeName: "local", + directoryPath: "#^$/invalid", + expectError: true, + expectedErrorMessage: "failed to access manifest path #^$/invalid: stat #^$/invalid: no such file or directory", + expectedResourceProvider: "", + }, + { + name: "FilePathInsteadOfDirectory", + planeName: "local", + directoryPath: "testdata/valid.yaml", + expectError: true, + expectedErrorMessage: "manifest path testdata/valid.yaml is not a directory", + expectedResourceProvider: "", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + clientFactory, err := NewTestClientFactory() + require.NoError(t, err) + + err = RegisterDirectory(context.Background(), clientFactory, tt.planeName, tt.directoryPath, nil) + if tt.expectError { + require.Error(t, err) + require.Contains(t, err.Error(), tt.expectedErrorMessage) + } else { + require.NoError(t, err) + + // Verify the expected resource provider exists + if tt.expectedResourceProvider != "" { + rp, err := clientFactory.NewResourceProvidersClient().Get(context.Background(), tt.planeName, tt.expectedResourceProvider, nil) + require.NoError(t, err, "Failed to retrieve the expected resource provider") + require.Equal(t, to.Ptr(tt.expectedResourceProvider), rp.Name) + } + } + }) + } +} + +func TestRegisterFile(t *testing.T) { + tests := []struct { + name string + planeName string + filePath string + expectError bool + expectedErrorMessage string + expectedResourceProvider string + expectedResourceTypeName string + expectedAPIVersion string + }{ + { + name: "Success", + planeName: "local", + filePath: "testdata/registerdirectory/resourceprovider-valid2.yaml", + expectError: false, + expectedErrorMessage: "", + expectedResourceProvider: "MyCompany2.CompanyName2", + expectedResourceTypeName: "testResource3", + expectedAPIVersion: "2025-01-01-preview", + }, + { + name: "EmptyDirectoryPath", + planeName: "local", + filePath: "", + expectError: true, + expectedErrorMessage: "invalid manifest file path", + expectedResourceProvider: "", + expectedResourceTypeName: "", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + + clientFactory, err := NewTestClientFactory() + require.NoError(t, err, "Failed to create client factory") + + var logBuffer bytes.Buffer + logger := func(format string, args ...interface{}) { + fmt.Fprintf(&logBuffer, format+"\n", args...) + } + + err = RegisterFile(context.Background(), clientFactory, tt.planeName, tt.filePath, logger) + if tt.expectError { + require.Error(t, err) + require.Contains(t, err.Error(), tt.expectedErrorMessage) + } else { + require.NoError(t, err) + + // Verify the expected resource provider exists + if tt.expectedResourceProvider != "" { + rp, err := clientFactory.NewResourceProvidersClient().Get(context.Background(), tt.planeName, tt.expectedResourceProvider, nil) + require.NoError(t, err, "Failed to retrieve the expected resource provider") + require.Equal(t, to.Ptr(tt.expectedResourceProvider), rp.Name) + + logOutput := logBuffer.String() + require.Contains(t, logOutput, fmt.Sprintf("Creating resource type %s/%s", tt.expectedResourceProvider, tt.expectedResourceTypeName)) + require.Contains(t, logOutput, fmt.Sprintf("Creating API Version %s/%s@%s", tt.expectedResourceProvider, tt.expectedResourceTypeName, tt.expectedAPIVersion)) + } + } + }) + } +} diff --git a/pkg/cli/manifest/testclientfactory.go b/pkg/cli/manifest/testclientfactory.go new file mode 100644 index 0000000000..85e9117d1f --- /dev/null +++ b/pkg/cli/manifest/testclientfactory.go @@ -0,0 +1,164 @@ +/* +Copyright 2023 The Radius Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package manifest + +import ( + "context" + "net/http" + + armpolicy "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/policy" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/radius-project/radius/pkg/to" + "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" + ucpfake "github.com/radius-project/radius/pkg/ucp/api/v20231001preview/fake" +) + +// NewTestClientFactory creates a new client factory for testing purposes. +func NewTestClientFactory() (*v20231001preview.ClientFactory, error) { + // Create fake servers for each client + resourceProvidersServer := ucpfake.ResourceProvidersServer{ + BeginCreateOrUpdate: func( + ctx context.Context, + planeName string, + resourceProviderName string, + resource v20231001preview.ResourceProviderResource, + options *v20231001preview.ResourceProvidersClientBeginCreateOrUpdateOptions, + ) (resp azfake.PollerResponder[v20231001preview.ResourceProvidersClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) { + // Simulate successful creation + result := v20231001preview.ResourceProvidersClientCreateOrUpdateResponse{ + ResourceProviderResource: resource, + } + resp.AddNonTerminalResponse(http.StatusCreated, nil) + resp.SetTerminalResponse(http.StatusOK, result, nil) + + return + }, + Get: func( + ctx context.Context, + planeName string, + resourceProviderName string, + options *v20231001preview.ResourceProvidersClientGetOptions, // Add this parameter + ) (resp azfake.Responder[v20231001preview.ResourceProvidersClientGetResponse], errResp azfake.ErrorResponder) { + response := v20231001preview.ResourceProvidersClientGetResponse{ + ResourceProviderResource: v20231001preview.ResourceProviderResource{ + Name: to.Ptr(resourceProviderName), + }, + } + resp.SetResponse(http.StatusOK, response, nil) + return + }, + } + + resourceTypesServer := ucpfake.ResourceTypesServer{ + BeginCreateOrUpdate: func( + ctx context.Context, + planeName string, + resourceProviderName string, + resourceTypeName string, + resource v20231001preview.ResourceTypeResource, + options *v20231001preview.ResourceTypesClientBeginCreateOrUpdateOptions, + ) (resp azfake.PollerResponder[v20231001preview.ResourceTypesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) { + result := v20231001preview.ResourceTypesClientCreateOrUpdateResponse{ + ResourceTypeResource: resource, + } + + resp.AddNonTerminalResponse(http.StatusCreated, nil) + resp.SetTerminalResponse(http.StatusOK, result, nil) + + return + }, + Get: func( + ctx context.Context, + planeName string, + resourceProviderName string, + resourceTypeName string, + options *v20231001preview.ResourceTypesClientGetOptions, + ) (resp azfake.Responder[v20231001preview.ResourceTypesClientGetResponse], errResp azfake.ErrorResponder) { + response := v20231001preview.ResourceTypesClientGetResponse{ + ResourceTypeResource: v20231001preview.ResourceTypeResource{ + Name: to.Ptr(resourceTypeName), + }, + } + resp.SetResponse(http.StatusOK, response, nil) + return + }, + } + + apiVersionsServer := ucpfake.APIVersionsServer{ + BeginCreateOrUpdate: func( + ctx context.Context, + planeName string, + resourceProviderName string, + resourceTypeName string, + apiVersionName string, // Added missing parameter + resource v20231001preview.APIVersionResource, + options *v20231001preview.APIVersionsClientBeginCreateOrUpdateOptions, + ) (resp azfake.PollerResponder[v20231001preview.APIVersionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) { + // Simulate successful creation + result := v20231001preview.APIVersionsClientCreateOrUpdateResponse{ + APIVersionResource: resource, + } + resp.AddNonTerminalResponse(http.StatusCreated, nil) + resp.SetTerminalResponse(http.StatusOK, result, nil) + return + }, + } + + locationsServer := ucpfake.LocationsServer{ + BeginCreateOrUpdate: func( + ctx context.Context, + planeName string, + resourceProviderName string, + locationName string, + resource v20231001preview.LocationResource, + options *v20231001preview.LocationsClientBeginCreateOrUpdateOptions, + ) (resp azfake.PollerResponder[v20231001preview.LocationsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) { + // Simulate successful creation + result := v20231001preview.LocationsClientCreateOrUpdateResponse{ + LocationResource: resource, + } + resp.AddNonTerminalResponse(http.StatusCreated, nil) + resp.SetTerminalResponse(http.StatusOK, result, nil) + + return + }, + } + + serverFactory := ucpfake.ServerFactory{ + ResourceProvidersServer: resourceProvidersServer, + ResourceTypesServer: resourceTypesServer, + APIVersionsServer: apiVersionsServer, + LocationsServer: locationsServer, + } + + serverFactoryTransport := ucpfake.NewServerFactoryTransport(&serverFactory) + + clientOptions := &armpolicy.ClientOptions{ + ClientOptions: policy.ClientOptions{ + Transport: serverFactoryTransport, + }, + } + + clientFactory, err := v20231001preview.NewClientFactory(&azfake.TokenCredential{}, clientOptions) + if err != nil { + return nil, err + } + + return clientFactory, err +} diff --git a/pkg/cli/manifest/testdata/registerdirectory/resourceprovider-valid1.yaml b/pkg/cli/manifest/testdata/registerdirectory/resourceprovider-valid1.yaml new file mode 100644 index 0000000000..b76f369047 --- /dev/null +++ b/pkg/cli/manifest/testdata/registerdirectory/resourceprovider-valid1.yaml @@ -0,0 +1,12 @@ +name: MyCompany.CompanyName +types: + testResource1: + apiVersions: + "2025-01-01-preview": + schema: {} + capabilities: [] + testResource2: + apiVersions: + "2025-01-01-preview": + schema: {} + capabilities: [] diff --git a/pkg/cli/manifest/testdata/registerdirectory/resourceprovider-valid2.yaml b/pkg/cli/manifest/testdata/registerdirectory/resourceprovider-valid2.yaml new file mode 100644 index 0000000000..3ef2b3ffcc --- /dev/null +++ b/pkg/cli/manifest/testdata/registerdirectory/resourceprovider-valid2.yaml @@ -0,0 +1,12 @@ +name: MyCompany2.CompanyName2 +types: + testResource3: + apiVersions: + "2025-01-01-preview": + schema: {} + capabilities: ["Recipes"] + testResource4: + apiVersions: + "2025-01-01-preview": + schema: {} + capabilities: ["Recipes"] diff --git a/pkg/cli/workspaces/connection.go b/pkg/cli/workspaces/connection.go index 12addf527c..aff86392da 100644 --- a/pkg/cli/workspaces/connection.go +++ b/pkg/cli/workspaces/connection.go @@ -17,6 +17,8 @@ limitations under the License. package workspaces import ( + "context" + "errors" "fmt" "net/url" "strings" @@ -92,14 +94,26 @@ func (ws Workspace) ConnectionConfig() (ConnectionConfig, error) { } } -// Connect attempts to create a connection to the workspace using the connection configuration and returns the +// Connect attempts to create and test a connection to the workspace using the connection configuration and returns the // connection and an error if one occurs. -func (ws Workspace) Connect() (sdk.Connection, error) { +func (ws Workspace) Connect(ctx context.Context) (sdk.Connection, error) { connectionConfig, err := ws.ConnectionConfig() if err != nil { return nil, err } + connection, err := connectionConfig.Connect() + if err != nil { + return nil, err + } + + err = sdk.TestConnection(ctx, connection) + if errors.Is(err, &sdk.ErrRadiusNotInstalled{}) { + return nil, fmt.Errorf("could not connect to radius: %w", err) + } else if err != nil { + return nil, err + } + return connectionConfig.Connect() } diff --git a/pkg/ucp/api/README.md b/pkg/ucp/api/README.md index aa95d60849..169ee1afa6 100644 --- a/pkg/ucp/api/README.md +++ b/pkg/ucp/api/README.md @@ -51,7 +51,6 @@ module-version: 0.0.1 file-prefix: zz_generated_ license-header: "Licensed under the Apache License, Version 2.0 . See LICENSE in the repository root for license information.\nCode generated by Microsoft (R) AutoRest Code Generator.\nChanges may cause incorrect behavior and will be lost if the code is regenerated." azure-arm: true -generate-fakes: false ``` ### Output diff --git a/pkg/ucp/api/v20231001preview/fake/zz_generated_apiversions_server.go b/pkg/ucp/api/v20231001preview/fake/zz_generated_apiversions_server.go new file mode 100644 index 0000000000..0050096780 --- /dev/null +++ b/pkg/ucp/api/v20231001preview/fake/zz_generated_apiversions_server.go @@ -0,0 +1,310 @@ +// Licensed under the Apache License, Version 2.0 . See LICENSE in the repository root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" + "net/http" + "net/url" + "regexp" +) + +// APIVersionsServer is a fake server for instances of the v20231001preview.APIVersionsClient type. +type APIVersionsServer struct{ + // BeginCreateOrUpdate is the fake for method APIVersionsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, planeName string, resourceProviderName string, resourceTypeName string, apiVersionName string, resource v20231001preview.APIVersionResource, options *v20231001preview.APIVersionsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[v20231001preview.APIVersionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method APIVersionsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, planeName string, resourceProviderName string, resourceTypeName string, apiVersionName string, options *v20231001preview.APIVersionsClientBeginDeleteOptions) (resp azfake.PollerResponder[v20231001preview.APIVersionsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method APIVersionsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, planeName string, resourceProviderName string, resourceTypeName string, apiVersionName string, options *v20231001preview.APIVersionsClientGetOptions) (resp azfake.Responder[v20231001preview.APIVersionsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method APIVersionsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(planeName string, resourceProviderName string, resourceTypeName string, options *v20231001preview.APIVersionsClientListOptions) (resp azfake.PagerResponder[v20231001preview.APIVersionsClientListResponse]) + +} + +// NewAPIVersionsServerTransport creates a new instance of APIVersionsServerTransport with the provided implementation. +// The returned APIVersionsServerTransport instance is connected to an instance of v20231001preview.APIVersionsClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewAPIVersionsServerTransport(srv *APIVersionsServer) *APIVersionsServerTransport { + return &APIVersionsServerTransport{ + srv: srv, + beginCreateOrUpdate: newTracker[azfake.PollerResponder[v20231001preview.APIVersionsClientCreateOrUpdateResponse]](), + beginDelete: newTracker[azfake.PollerResponder[v20231001preview.APIVersionsClientDeleteResponse]](), + newListPager: newTracker[azfake.PagerResponder[v20231001preview.APIVersionsClientListResponse]](), + } +} + +// APIVersionsServerTransport connects instances of v20231001preview.APIVersionsClient to instances of APIVersionsServer. +// Don't use this type directly, use NewAPIVersionsServerTransport instead. +type APIVersionsServerTransport struct { + srv *APIVersionsServer + beginCreateOrUpdate *tracker[azfake.PollerResponder[v20231001preview.APIVersionsClientCreateOrUpdateResponse]] + beginDelete *tracker[azfake.PollerResponder[v20231001preview.APIVersionsClientDeleteResponse]] + newListPager *tracker[azfake.PagerResponder[v20231001preview.APIVersionsClientListResponse]] +} + +// Do implements the policy.Transporter interface for APIVersionsServerTransport. +func (a *APIVersionsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return a.dispatchToMethodFake(req, method) +} + +func (a *APIVersionsServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if apiVersionsServerTransportInterceptor != nil { + res.resp, res.err, intercepted = apiVersionsServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "APIVersionsClient.BeginCreateOrUpdate": + res.resp, res.err = a.dispatchBeginCreateOrUpdate(req) + case "APIVersionsClient.BeginDelete": + res.resp, res.err = a.dispatchBeginDelete(req) + case "APIVersionsClient.Get": + res.resp, res.err = a.dispatchGet(req) + case "APIVersionsClient.NewListPager": + res.resp, res.err = a.dispatchNewListPager(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (a *APIVersionsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if a.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + beginCreateOrUpdate := a.beginCreateOrUpdate.get(req) + if beginCreateOrUpdate == nil { + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Resources/resourceproviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcetypes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/apiversions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[v20231001preview.APIVersionResource](req) + if err != nil { + return nil, err + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceProviderNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderName")]) + if err != nil { + return nil, err + } + resourceTypeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceTypeName")]) + if err != nil { + return nil, err + } + apiVersionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("apiVersionName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginCreateOrUpdate(req.Context(), planeNameParam, resourceProviderNameParam, resourceTypeNameParam, apiVersionNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginCreateOrUpdate = &respr + a.beginCreateOrUpdate.add(req, beginCreateOrUpdate) + } + + resp, err := server.PollerResponderNext(beginCreateOrUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + a.beginCreateOrUpdate.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(beginCreateOrUpdate) { + a.beginCreateOrUpdate.remove(req) + } + + return resp, nil +} + +func (a *APIVersionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if a.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + beginDelete := a.beginDelete.get(req) + if beginDelete == nil { + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Resources/resourceproviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcetypes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/apiversions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceProviderNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderName")]) + if err != nil { + return nil, err + } + resourceTypeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceTypeName")]) + if err != nil { + return nil, err + } + apiVersionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("apiVersionName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginDelete(req.Context(), planeNameParam, resourceProviderNameParam, resourceTypeNameParam, apiVersionNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginDelete = &respr + a.beginDelete.add(req, beginDelete) + } + + resp, err := server.PollerResponderNext(beginDelete, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + a.beginDelete.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(beginDelete) { + a.beginDelete.remove(req) + } + + return resp, nil +} + +func (a *APIVersionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if a.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Resources/resourceproviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcetypes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/apiversions/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 4 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceProviderNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderName")]) + if err != nil { + return nil, err + } + resourceTypeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceTypeName")]) + if err != nil { + return nil, err + } + apiVersionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("apiVersionName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Get(req.Context(), planeNameParam, resourceProviderNameParam, resourceTypeNameParam, apiVersionNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).APIVersionResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *APIVersionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := a.newListPager.get(req) + if newListPager == nil { + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Resources/resourceproviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcetypes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/apiversions` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceProviderNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderName")]) + if err != nil { + return nil, err + } + resourceTypeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceTypeName")]) + if err != nil { + return nil, err + } +resp := a.srv.NewListPager(planeNameParam, resourceProviderNameParam, resourceTypeNameParam, nil) + newListPager = &resp + a.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *v20231001preview.APIVersionsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + a.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + a.newListPager.remove(req) + } + return resp, nil +} + +// set this to conditionally intercept incoming requests to APIVersionsServerTransport +var apiVersionsServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/pkg/ucp/api/v20231001preview/fake/zz_generated_awscredentials_server.go b/pkg/ucp/api/v20231001preview/fake/zz_generated_awscredentials_server.go new file mode 100644 index 0000000000..bad6241902 --- /dev/null +++ b/pkg/ucp/api/v20231001preview/fake/zz_generated_awscredentials_server.go @@ -0,0 +1,295 @@ +// Licensed under the Apache License, Version 2.0 . See LICENSE in the repository root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" + "net/http" + "net/url" + "regexp" +) + +// AwsCredentialsServer is a fake server for instances of the v20231001preview.AwsCredentialsClient type. +type AwsCredentialsServer struct{ + // CreateOrUpdate is the fake for method AwsCredentialsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, planeName string, credentialName string, resource v20231001preview.AwsCredentialResource, options *v20231001preview.AwsCredentialsClientCreateOrUpdateOptions) (resp azfake.Responder[v20231001preview.AwsCredentialsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method AwsCredentialsClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, planeName string, credentialName string, options *v20231001preview.AwsCredentialsClientDeleteOptions) (resp azfake.Responder[v20231001preview.AwsCredentialsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method AwsCredentialsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, planeName string, credentialName string, options *v20231001preview.AwsCredentialsClientGetOptions) (resp azfake.Responder[v20231001preview.AwsCredentialsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method AwsCredentialsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(planeName string, options *v20231001preview.AwsCredentialsClientListOptions) (resp azfake.PagerResponder[v20231001preview.AwsCredentialsClientListResponse]) + + // Update is the fake for method AwsCredentialsClient.Update + // HTTP status codes to indicate success: http.StatusOK + Update func(ctx context.Context, planeName string, credentialName string, properties v20231001preview.AwsCredentialResourceTagsUpdate, options *v20231001preview.AwsCredentialsClientUpdateOptions) (resp azfake.Responder[v20231001preview.AwsCredentialsClientUpdateResponse], errResp azfake.ErrorResponder) + +} + +// NewAwsCredentialsServerTransport creates a new instance of AwsCredentialsServerTransport with the provided implementation. +// The returned AwsCredentialsServerTransport instance is connected to an instance of v20231001preview.AwsCredentialsClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewAwsCredentialsServerTransport(srv *AwsCredentialsServer) *AwsCredentialsServerTransport { + return &AwsCredentialsServerTransport{ + srv: srv, + newListPager: newTracker[azfake.PagerResponder[v20231001preview.AwsCredentialsClientListResponse]](), + } +} + +// AwsCredentialsServerTransport connects instances of v20231001preview.AwsCredentialsClient to instances of AwsCredentialsServer. +// Don't use this type directly, use NewAwsCredentialsServerTransport instead. +type AwsCredentialsServerTransport struct { + srv *AwsCredentialsServer + newListPager *tracker[azfake.PagerResponder[v20231001preview.AwsCredentialsClientListResponse]] +} + +// Do implements the policy.Transporter interface for AwsCredentialsServerTransport. +func (a *AwsCredentialsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return a.dispatchToMethodFake(req, method) +} + +func (a *AwsCredentialsServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if awsCredentialsServerTransportInterceptor != nil { + res.resp, res.err, intercepted = awsCredentialsServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "AwsCredentialsClient.CreateOrUpdate": + res.resp, res.err = a.dispatchCreateOrUpdate(req) + case "AwsCredentialsClient.Delete": + res.resp, res.err = a.dispatchDelete(req) + case "AwsCredentialsClient.Get": + res.resp, res.err = a.dispatchGet(req) + case "AwsCredentialsClient.NewListPager": + res.resp, res.err = a.dispatchNewListPager(req) + case "AwsCredentialsClient.Update": + res.resp, res.err = a.dispatchUpdate(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (a *AwsCredentialsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if a.srv.CreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdate not implemented")} + } + const regexStr = `/planes/aws/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.AWS/credentials/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[v20231001preview.AwsCredentialResource](req) + if err != nil { + return nil, err + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + credentialNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("credentialName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.CreateOrUpdate(req.Context(), planeNameParam, credentialNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).AwsCredentialResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AwsCredentialsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if a.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("fake for method Delete not implemented")} + } + const regexStr = `/planes/aws/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.AWS/credentials/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + credentialNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("credentialName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Delete(req.Context(), planeNameParam, credentialNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AwsCredentialsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if a.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/planes/aws/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.AWS/credentials/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + credentialNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("credentialName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Get(req.Context(), planeNameParam, credentialNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).AwsCredentialResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AwsCredentialsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := a.newListPager.get(req) + if newListPager == nil { + const regexStr = `/planes/aws/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.AWS/credentials` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } +resp := a.srv.NewListPager(planeNameParam, nil) + newListPager = &resp + a.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *v20231001preview.AwsCredentialsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + a.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + a.newListPager.remove(req) + } + return resp, nil +} + +func (a *AwsCredentialsServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { + if a.srv.Update == nil { + return nil, &nonRetriableError{errors.New("fake for method Update not implemented")} + } + const regexStr = `/planes/aws/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.AWS/credentials/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[v20231001preview.AwsCredentialResourceTagsUpdate](req) + if err != nil { + return nil, err + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + credentialNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("credentialName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Update(req.Context(), planeNameParam, credentialNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).AwsCredentialResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +// set this to conditionally intercept incoming requests to AwsCredentialsServerTransport +var awsCredentialsServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/pkg/ucp/api/v20231001preview/fake/zz_generated_awsplanes_server.go b/pkg/ucp/api/v20231001preview/fake/zz_generated_awsplanes_server.go new file mode 100644 index 0000000000..ccb43ad22e --- /dev/null +++ b/pkg/ucp/api/v20231001preview/fake/zz_generated_awsplanes_server.go @@ -0,0 +1,308 @@ +// Licensed under the Apache License, Version 2.0 . See LICENSE in the repository root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" + "net/http" + "net/url" + "regexp" +) + +// AwsPlanesServer is a fake server for instances of the v20231001preview.AwsPlanesClient type. +type AwsPlanesServer struct{ + // BeginCreateOrUpdate is the fake for method AwsPlanesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, planeName string, resource v20231001preview.AwsPlaneResource, options *v20231001preview.AwsPlanesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[v20231001preview.AwsPlanesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method AwsPlanesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, planeName string, options *v20231001preview.AwsPlanesClientBeginDeleteOptions) (resp azfake.PollerResponder[v20231001preview.AwsPlanesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method AwsPlanesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, planeName string, options *v20231001preview.AwsPlanesClientGetOptions) (resp azfake.Responder[v20231001preview.AwsPlanesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method AwsPlanesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *v20231001preview.AwsPlanesClientListOptions) (resp azfake.PagerResponder[v20231001preview.AwsPlanesClientListResponse]) + + // BeginUpdate is the fake for method AwsPlanesClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdate func(ctx context.Context, planeName string, properties v20231001preview.AwsPlaneResourceTagsUpdate, options *v20231001preview.AwsPlanesClientBeginUpdateOptions) (resp azfake.PollerResponder[v20231001preview.AwsPlanesClientUpdateResponse], errResp azfake.ErrorResponder) + +} + +// NewAwsPlanesServerTransport creates a new instance of AwsPlanesServerTransport with the provided implementation. +// The returned AwsPlanesServerTransport instance is connected to an instance of v20231001preview.AwsPlanesClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewAwsPlanesServerTransport(srv *AwsPlanesServer) *AwsPlanesServerTransport { + return &AwsPlanesServerTransport{ + srv: srv, + beginCreateOrUpdate: newTracker[azfake.PollerResponder[v20231001preview.AwsPlanesClientCreateOrUpdateResponse]](), + beginDelete: newTracker[azfake.PollerResponder[v20231001preview.AwsPlanesClientDeleteResponse]](), + newListPager: newTracker[azfake.PagerResponder[v20231001preview.AwsPlanesClientListResponse]](), + beginUpdate: newTracker[azfake.PollerResponder[v20231001preview.AwsPlanesClientUpdateResponse]](), + } +} + +// AwsPlanesServerTransport connects instances of v20231001preview.AwsPlanesClient to instances of AwsPlanesServer. +// Don't use this type directly, use NewAwsPlanesServerTransport instead. +type AwsPlanesServerTransport struct { + srv *AwsPlanesServer + beginCreateOrUpdate *tracker[azfake.PollerResponder[v20231001preview.AwsPlanesClientCreateOrUpdateResponse]] + beginDelete *tracker[azfake.PollerResponder[v20231001preview.AwsPlanesClientDeleteResponse]] + newListPager *tracker[azfake.PagerResponder[v20231001preview.AwsPlanesClientListResponse]] + beginUpdate *tracker[azfake.PollerResponder[v20231001preview.AwsPlanesClientUpdateResponse]] +} + +// Do implements the policy.Transporter interface for AwsPlanesServerTransport. +func (a *AwsPlanesServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return a.dispatchToMethodFake(req, method) +} + +func (a *AwsPlanesServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if awsPlanesServerTransportInterceptor != nil { + res.resp, res.err, intercepted = awsPlanesServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "AwsPlanesClient.BeginCreateOrUpdate": + res.resp, res.err = a.dispatchBeginCreateOrUpdate(req) + case "AwsPlanesClient.BeginDelete": + res.resp, res.err = a.dispatchBeginDelete(req) + case "AwsPlanesClient.Get": + res.resp, res.err = a.dispatchGet(req) + case "AwsPlanesClient.NewListPager": + res.resp, res.err = a.dispatchNewListPager(req) + case "AwsPlanesClient.BeginUpdate": + res.resp, res.err = a.dispatchBeginUpdate(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (a *AwsPlanesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if a.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + beginCreateOrUpdate := a.beginCreateOrUpdate.get(req) + if beginCreateOrUpdate == nil { + const regexStr = `/planes/aws/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[v20231001preview.AwsPlaneResource](req) + if err != nil { + return nil, err + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginCreateOrUpdate(req.Context(), planeNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginCreateOrUpdate = &respr + a.beginCreateOrUpdate.add(req, beginCreateOrUpdate) + } + + resp, err := server.PollerResponderNext(beginCreateOrUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + a.beginCreateOrUpdate.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(beginCreateOrUpdate) { + a.beginCreateOrUpdate.remove(req) + } + + return resp, nil +} + +func (a *AwsPlanesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if a.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + beginDelete := a.beginDelete.get(req) + if beginDelete == nil { + const regexStr = `/planes/aws/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginDelete(req.Context(), planeNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginDelete = &respr + a.beginDelete.add(req, beginDelete) + } + + resp, err := server.PollerResponderNext(beginDelete, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + a.beginDelete.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(beginDelete) { + a.beginDelete.remove(req) + } + + return resp, nil +} + +func (a *AwsPlanesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if a.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/planes/aws/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Get(req.Context(), planeNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).AwsPlaneResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AwsPlanesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := a.newListPager.get(req) + if newListPager == nil { +resp := a.srv.NewListPager(nil) + newListPager = &resp + a.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *v20231001preview.AwsPlanesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + a.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + a.newListPager.remove(req) + } + return resp, nil +} + +func (a *AwsPlanesServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if a.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} + } + beginUpdate := a.beginUpdate.get(req) + if beginUpdate == nil { + const regexStr = `/planes/aws/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[v20231001preview.AwsPlaneResourceTagsUpdate](req) + if err != nil { + return nil, err + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginUpdate(req.Context(), planeNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginUpdate = &respr + a.beginUpdate.add(req, beginUpdate) + } + + resp, err := server.PollerResponderNext(beginUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { + a.beginUpdate.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(beginUpdate) { + a.beginUpdate.remove(req) + } + + return resp, nil +} + +// set this to conditionally intercept incoming requests to AwsPlanesServerTransport +var awsPlanesServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/pkg/ucp/api/v20231001preview/fake/zz_generated_azurecredentials_server.go b/pkg/ucp/api/v20231001preview/fake/zz_generated_azurecredentials_server.go new file mode 100644 index 0000000000..e4151d61d5 --- /dev/null +++ b/pkg/ucp/api/v20231001preview/fake/zz_generated_azurecredentials_server.go @@ -0,0 +1,295 @@ +// Licensed under the Apache License, Version 2.0 . See LICENSE in the repository root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" + "net/http" + "net/url" + "regexp" +) + +// AzureCredentialsServer is a fake server for instances of the v20231001preview.AzureCredentialsClient type. +type AzureCredentialsServer struct{ + // CreateOrUpdate is the fake for method AzureCredentialsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, planeName string, credentialName string, resource v20231001preview.AzureCredentialResource, options *v20231001preview.AzureCredentialsClientCreateOrUpdateOptions) (resp azfake.Responder[v20231001preview.AzureCredentialsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method AzureCredentialsClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, planeName string, credentialName string, options *v20231001preview.AzureCredentialsClientDeleteOptions) (resp azfake.Responder[v20231001preview.AzureCredentialsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method AzureCredentialsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, planeName string, credentialName string, options *v20231001preview.AzureCredentialsClientGetOptions) (resp azfake.Responder[v20231001preview.AzureCredentialsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method AzureCredentialsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(planeName string, options *v20231001preview.AzureCredentialsClientListOptions) (resp azfake.PagerResponder[v20231001preview.AzureCredentialsClientListResponse]) + + // Update is the fake for method AzureCredentialsClient.Update + // HTTP status codes to indicate success: http.StatusOK + Update func(ctx context.Context, planeName string, credentialName string, properties v20231001preview.AzureCredentialResourceTagsUpdate, options *v20231001preview.AzureCredentialsClientUpdateOptions) (resp azfake.Responder[v20231001preview.AzureCredentialsClientUpdateResponse], errResp azfake.ErrorResponder) + +} + +// NewAzureCredentialsServerTransport creates a new instance of AzureCredentialsServerTransport with the provided implementation. +// The returned AzureCredentialsServerTransport instance is connected to an instance of v20231001preview.AzureCredentialsClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewAzureCredentialsServerTransport(srv *AzureCredentialsServer) *AzureCredentialsServerTransport { + return &AzureCredentialsServerTransport{ + srv: srv, + newListPager: newTracker[azfake.PagerResponder[v20231001preview.AzureCredentialsClientListResponse]](), + } +} + +// AzureCredentialsServerTransport connects instances of v20231001preview.AzureCredentialsClient to instances of AzureCredentialsServer. +// Don't use this type directly, use NewAzureCredentialsServerTransport instead. +type AzureCredentialsServerTransport struct { + srv *AzureCredentialsServer + newListPager *tracker[azfake.PagerResponder[v20231001preview.AzureCredentialsClientListResponse]] +} + +// Do implements the policy.Transporter interface for AzureCredentialsServerTransport. +func (a *AzureCredentialsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return a.dispatchToMethodFake(req, method) +} + +func (a *AzureCredentialsServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if azureCredentialsServerTransportInterceptor != nil { + res.resp, res.err, intercepted = azureCredentialsServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "AzureCredentialsClient.CreateOrUpdate": + res.resp, res.err = a.dispatchCreateOrUpdate(req) + case "AzureCredentialsClient.Delete": + res.resp, res.err = a.dispatchDelete(req) + case "AzureCredentialsClient.Get": + res.resp, res.err = a.dispatchGet(req) + case "AzureCredentialsClient.NewListPager": + res.resp, res.err = a.dispatchNewListPager(req) + case "AzureCredentialsClient.Update": + res.resp, res.err = a.dispatchUpdate(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (a *AzureCredentialsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if a.srv.CreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdate not implemented")} + } + const regexStr = `/planes/azure/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Azure/credentials/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[v20231001preview.AzureCredentialResource](req) + if err != nil { + return nil, err + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + credentialNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("credentialName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.CreateOrUpdate(req.Context(), planeNameParam, credentialNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).AzureCredentialResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AzureCredentialsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if a.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("fake for method Delete not implemented")} + } + const regexStr = `/planes/azure/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Azure/credentials/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + credentialNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("credentialName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Delete(req.Context(), planeNameParam, credentialNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AzureCredentialsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if a.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/planes/azure/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Azure/credentials/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + credentialNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("credentialName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Get(req.Context(), planeNameParam, credentialNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).AzureCredentialResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AzureCredentialsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := a.newListPager.get(req) + if newListPager == nil { + const regexStr = `/planes/azure/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Azure/credentials` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } +resp := a.srv.NewListPager(planeNameParam, nil) + newListPager = &resp + a.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *v20231001preview.AzureCredentialsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + a.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + a.newListPager.remove(req) + } + return resp, nil +} + +func (a *AzureCredentialsServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { + if a.srv.Update == nil { + return nil, &nonRetriableError{errors.New("fake for method Update not implemented")} + } + const regexStr = `/planes/azure/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Azure/credentials/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[v20231001preview.AzureCredentialResourceTagsUpdate](req) + if err != nil { + return nil, err + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + credentialNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("credentialName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Update(req.Context(), planeNameParam, credentialNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).AzureCredentialResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +// set this to conditionally intercept incoming requests to AzureCredentialsServerTransport +var azureCredentialsServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/pkg/ucp/api/v20231001preview/fake/zz_generated_azureplanes_server.go b/pkg/ucp/api/v20231001preview/fake/zz_generated_azureplanes_server.go new file mode 100644 index 0000000000..13f7a03c9a --- /dev/null +++ b/pkg/ucp/api/v20231001preview/fake/zz_generated_azureplanes_server.go @@ -0,0 +1,308 @@ +// Licensed under the Apache License, Version 2.0 . See LICENSE in the repository root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" + "net/http" + "net/url" + "regexp" +) + +// AzurePlanesServer is a fake server for instances of the v20231001preview.AzurePlanesClient type. +type AzurePlanesServer struct{ + // BeginCreateOrUpdate is the fake for method AzurePlanesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, planeName string, resource v20231001preview.AzurePlaneResource, options *v20231001preview.AzurePlanesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[v20231001preview.AzurePlanesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method AzurePlanesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, planeName string, options *v20231001preview.AzurePlanesClientBeginDeleteOptions) (resp azfake.PollerResponder[v20231001preview.AzurePlanesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method AzurePlanesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, planeName string, options *v20231001preview.AzurePlanesClientGetOptions) (resp azfake.Responder[v20231001preview.AzurePlanesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method AzurePlanesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *v20231001preview.AzurePlanesClientListOptions) (resp azfake.PagerResponder[v20231001preview.AzurePlanesClientListResponse]) + + // BeginUpdate is the fake for method AzurePlanesClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdate func(ctx context.Context, planeName string, properties v20231001preview.AzurePlaneResourceTagsUpdate, options *v20231001preview.AzurePlanesClientBeginUpdateOptions) (resp azfake.PollerResponder[v20231001preview.AzurePlanesClientUpdateResponse], errResp azfake.ErrorResponder) + +} + +// NewAzurePlanesServerTransport creates a new instance of AzurePlanesServerTransport with the provided implementation. +// The returned AzurePlanesServerTransport instance is connected to an instance of v20231001preview.AzurePlanesClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewAzurePlanesServerTransport(srv *AzurePlanesServer) *AzurePlanesServerTransport { + return &AzurePlanesServerTransport{ + srv: srv, + beginCreateOrUpdate: newTracker[azfake.PollerResponder[v20231001preview.AzurePlanesClientCreateOrUpdateResponse]](), + beginDelete: newTracker[azfake.PollerResponder[v20231001preview.AzurePlanesClientDeleteResponse]](), + newListPager: newTracker[azfake.PagerResponder[v20231001preview.AzurePlanesClientListResponse]](), + beginUpdate: newTracker[azfake.PollerResponder[v20231001preview.AzurePlanesClientUpdateResponse]](), + } +} + +// AzurePlanesServerTransport connects instances of v20231001preview.AzurePlanesClient to instances of AzurePlanesServer. +// Don't use this type directly, use NewAzurePlanesServerTransport instead. +type AzurePlanesServerTransport struct { + srv *AzurePlanesServer + beginCreateOrUpdate *tracker[azfake.PollerResponder[v20231001preview.AzurePlanesClientCreateOrUpdateResponse]] + beginDelete *tracker[azfake.PollerResponder[v20231001preview.AzurePlanesClientDeleteResponse]] + newListPager *tracker[azfake.PagerResponder[v20231001preview.AzurePlanesClientListResponse]] + beginUpdate *tracker[azfake.PollerResponder[v20231001preview.AzurePlanesClientUpdateResponse]] +} + +// Do implements the policy.Transporter interface for AzurePlanesServerTransport. +func (a *AzurePlanesServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return a.dispatchToMethodFake(req, method) +} + +func (a *AzurePlanesServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if azurePlanesServerTransportInterceptor != nil { + res.resp, res.err, intercepted = azurePlanesServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "AzurePlanesClient.BeginCreateOrUpdate": + res.resp, res.err = a.dispatchBeginCreateOrUpdate(req) + case "AzurePlanesClient.BeginDelete": + res.resp, res.err = a.dispatchBeginDelete(req) + case "AzurePlanesClient.Get": + res.resp, res.err = a.dispatchGet(req) + case "AzurePlanesClient.NewListPager": + res.resp, res.err = a.dispatchNewListPager(req) + case "AzurePlanesClient.BeginUpdate": + res.resp, res.err = a.dispatchBeginUpdate(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (a *AzurePlanesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if a.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + beginCreateOrUpdate := a.beginCreateOrUpdate.get(req) + if beginCreateOrUpdate == nil { + const regexStr = `/planes/azure/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[v20231001preview.AzurePlaneResource](req) + if err != nil { + return nil, err + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginCreateOrUpdate(req.Context(), planeNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginCreateOrUpdate = &respr + a.beginCreateOrUpdate.add(req, beginCreateOrUpdate) + } + + resp, err := server.PollerResponderNext(beginCreateOrUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + a.beginCreateOrUpdate.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(beginCreateOrUpdate) { + a.beginCreateOrUpdate.remove(req) + } + + return resp, nil +} + +func (a *AzurePlanesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if a.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + beginDelete := a.beginDelete.get(req) + if beginDelete == nil { + const regexStr = `/planes/azure/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginDelete(req.Context(), planeNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginDelete = &respr + a.beginDelete.add(req, beginDelete) + } + + resp, err := server.PollerResponderNext(beginDelete, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + a.beginDelete.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(beginDelete) { + a.beginDelete.remove(req) + } + + return resp, nil +} + +func (a *AzurePlanesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if a.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/planes/azure/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.Get(req.Context(), planeNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).AzurePlaneResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (a *AzurePlanesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if a.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := a.newListPager.get(req) + if newListPager == nil { +resp := a.srv.NewListPager(nil) + newListPager = &resp + a.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *v20231001preview.AzurePlanesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + a.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + a.newListPager.remove(req) + } + return resp, nil +} + +func (a *AzurePlanesServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if a.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} + } + beginUpdate := a.beginUpdate.get(req) + if beginUpdate == nil { + const regexStr = `/planes/azure/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[v20231001preview.AzurePlaneResourceTagsUpdate](req) + if err != nil { + return nil, err + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + respr, errRespr := a.srv.BeginUpdate(req.Context(), planeNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginUpdate = &respr + a.beginUpdate.add(req, beginUpdate) + } + + resp, err := server.PollerResponderNext(beginUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { + a.beginUpdate.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(beginUpdate) { + a.beginUpdate.remove(req) + } + + return resp, nil +} + +// set this to conditionally intercept incoming requests to AzurePlanesServerTransport +var azurePlanesServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/pkg/ucp/api/v20231001preview/fake/zz_generated_internal.go b/pkg/ucp/api/v20231001preview/fake/zz_generated_internal.go new file mode 100644 index 0000000000..0c62457a83 --- /dev/null +++ b/pkg/ucp/api/v20231001preview/fake/zz_generated_internal.go @@ -0,0 +1,66 @@ +// Licensed under the Apache License, Version 2.0 . See LICENSE in the repository root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "net/http" + "sync" +) + + +type result struct { + resp *http.Response + err error +} + +type nonRetriableError struct { + error +} + +func (nonRetriableError) NonRetriable() { + // marker method +} + +func contains[T comparable](s []T, v T) bool { + for _, vv := range s { + if vv == v { + return true + } + } + return false +} + +func newTracker[T any]() *tracker[T] { + return &tracker[T]{ + items: map[string]*T{}, + } +} + +type tracker[T any] struct { + items map[string]*T + mu sync.Mutex +} + +func (p *tracker[T]) get(req *http.Request) *T { + p.mu.Lock() + defer p.mu.Unlock() + if item, ok := p.items[server.SanitizePagerPollerPath(req.URL.Path)]; ok { + return item + } + return nil +} + +func (p *tracker[T]) add(req *http.Request, item *T) { + p.mu.Lock() + defer p.mu.Unlock() + p.items[server.SanitizePagerPollerPath(req.URL.Path)] = item +} + +func (p *tracker[T]) remove(req *http.Request) { + p.mu.Lock() + defer p.mu.Unlock() + delete(p.items, server.SanitizePagerPollerPath(req.URL.Path)) +} diff --git a/pkg/ucp/api/v20231001preview/fake/zz_generated_locations_server.go b/pkg/ucp/api/v20231001preview/fake/zz_generated_locations_server.go new file mode 100644 index 0000000000..cf97d09ddd --- /dev/null +++ b/pkg/ucp/api/v20231001preview/fake/zz_generated_locations_server.go @@ -0,0 +1,294 @@ +// Licensed under the Apache License, Version 2.0 . See LICENSE in the repository root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" + "net/http" + "net/url" + "regexp" +) + +// LocationsServer is a fake server for instances of the v20231001preview.LocationsClient type. +type LocationsServer struct{ + // BeginCreateOrUpdate is the fake for method LocationsClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, planeName string, resourceProviderName string, locationName string, resource v20231001preview.LocationResource, options *v20231001preview.LocationsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[v20231001preview.LocationsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method LocationsClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, planeName string, resourceProviderName string, locationName string, options *v20231001preview.LocationsClientBeginDeleteOptions) (resp azfake.PollerResponder[v20231001preview.LocationsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method LocationsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, planeName string, resourceProviderName string, locationName string, options *v20231001preview.LocationsClientGetOptions) (resp azfake.Responder[v20231001preview.LocationsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method LocationsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(planeName string, resourceProviderName string, options *v20231001preview.LocationsClientListOptions) (resp azfake.PagerResponder[v20231001preview.LocationsClientListResponse]) + +} + +// NewLocationsServerTransport creates a new instance of LocationsServerTransport with the provided implementation. +// The returned LocationsServerTransport instance is connected to an instance of v20231001preview.LocationsClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewLocationsServerTransport(srv *LocationsServer) *LocationsServerTransport { + return &LocationsServerTransport{ + srv: srv, + beginCreateOrUpdate: newTracker[azfake.PollerResponder[v20231001preview.LocationsClientCreateOrUpdateResponse]](), + beginDelete: newTracker[azfake.PollerResponder[v20231001preview.LocationsClientDeleteResponse]](), + newListPager: newTracker[azfake.PagerResponder[v20231001preview.LocationsClientListResponse]](), + } +} + +// LocationsServerTransport connects instances of v20231001preview.LocationsClient to instances of LocationsServer. +// Don't use this type directly, use NewLocationsServerTransport instead. +type LocationsServerTransport struct { + srv *LocationsServer + beginCreateOrUpdate *tracker[azfake.PollerResponder[v20231001preview.LocationsClientCreateOrUpdateResponse]] + beginDelete *tracker[azfake.PollerResponder[v20231001preview.LocationsClientDeleteResponse]] + newListPager *tracker[azfake.PagerResponder[v20231001preview.LocationsClientListResponse]] +} + +// Do implements the policy.Transporter interface for LocationsServerTransport. +func (l *LocationsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return l.dispatchToMethodFake(req, method) +} + +func (l *LocationsServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if locationsServerTransportInterceptor != nil { + res.resp, res.err, intercepted = locationsServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "LocationsClient.BeginCreateOrUpdate": + res.resp, res.err = l.dispatchBeginCreateOrUpdate(req) + case "LocationsClient.BeginDelete": + res.resp, res.err = l.dispatchBeginDelete(req) + case "LocationsClient.Get": + res.resp, res.err = l.dispatchGet(req) + case "LocationsClient.NewListPager": + res.resp, res.err = l.dispatchNewListPager(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (l *LocationsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if l.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + beginCreateOrUpdate := l.beginCreateOrUpdate.get(req) + if beginCreateOrUpdate == nil { + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Resources/resourceproviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[v20231001preview.LocationResource](req) + if err != nil { + return nil, err + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceProviderNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderName")]) + if err != nil { + return nil, err + } + locationNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("locationName")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.BeginCreateOrUpdate(req.Context(), planeNameParam, resourceProviderNameParam, locationNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginCreateOrUpdate = &respr + l.beginCreateOrUpdate.add(req, beginCreateOrUpdate) + } + + resp, err := server.PollerResponderNext(beginCreateOrUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + l.beginCreateOrUpdate.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(beginCreateOrUpdate) { + l.beginCreateOrUpdate.remove(req) + } + + return resp, nil +} + +func (l *LocationsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if l.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + beginDelete := l.beginDelete.get(req) + if beginDelete == nil { + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Resources/resourceproviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceProviderNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderName")]) + if err != nil { + return nil, err + } + locationNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("locationName")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.BeginDelete(req.Context(), planeNameParam, resourceProviderNameParam, locationNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginDelete = &respr + l.beginDelete.add(req, beginDelete) + } + + resp, err := server.PollerResponderNext(beginDelete, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + l.beginDelete.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(beginDelete) { + l.beginDelete.remove(req) + } + + return resp, nil +} + +func (l *LocationsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if l.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Resources/resourceproviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/locations/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceProviderNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderName")]) + if err != nil { + return nil, err + } + locationNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("locationName")]) + if err != nil { + return nil, err + } + respr, errRespr := l.srv.Get(req.Context(), planeNameParam, resourceProviderNameParam, locationNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).LocationResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (l *LocationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if l.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := l.newListPager.get(req) + if newListPager == nil { + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Resources/resourceproviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/locations` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceProviderNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderName")]) + if err != nil { + return nil, err + } +resp := l.srv.NewListPager(planeNameParam, resourceProviderNameParam, nil) + newListPager = &resp + l.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *v20231001preview.LocationsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + l.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + l.newListPager.remove(req) + } + return resp, nil +} + +// set this to conditionally intercept incoming requests to LocationsServerTransport +var locationsServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/pkg/ucp/api/v20231001preview/fake/zz_generated_planes_server.go b/pkg/ucp/api/v20231001preview/fake/zz_generated_planes_server.go new file mode 100644 index 0000000000..b361998914 --- /dev/null +++ b/pkg/ucp/api/v20231001preview/fake/zz_generated_planes_server.go @@ -0,0 +1,118 @@ +// Licensed under the Apache License, Version 2.0 . See LICENSE in the repository root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" + "net/http" +) + +// PlanesServer is a fake server for instances of the v20231001preview.PlanesClient type. +type PlanesServer struct{ + // NewListPlanesPager is the fake for method PlanesClient.NewListPlanesPager + // HTTP status codes to indicate success: http.StatusOK + NewListPlanesPager func(options *v20231001preview.PlanesClientListPlanesOptions) (resp azfake.PagerResponder[v20231001preview.PlanesClientListPlanesResponse]) + +} + +// NewPlanesServerTransport creates a new instance of PlanesServerTransport with the provided implementation. +// The returned PlanesServerTransport instance is connected to an instance of v20231001preview.PlanesClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewPlanesServerTransport(srv *PlanesServer) *PlanesServerTransport { + return &PlanesServerTransport{ + srv: srv, + newListPlanesPager: newTracker[azfake.PagerResponder[v20231001preview.PlanesClientListPlanesResponse]](), + } +} + +// PlanesServerTransport connects instances of v20231001preview.PlanesClient to instances of PlanesServer. +// Don't use this type directly, use NewPlanesServerTransport instead. +type PlanesServerTransport struct { + srv *PlanesServer + newListPlanesPager *tracker[azfake.PagerResponder[v20231001preview.PlanesClientListPlanesResponse]] +} + +// Do implements the policy.Transporter interface for PlanesServerTransport. +func (p *PlanesServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return p.dispatchToMethodFake(req, method) +} + +func (p *PlanesServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if planesServerTransportInterceptor != nil { + res.resp, res.err, intercepted = planesServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "PlanesClient.NewListPlanesPager": + res.resp, res.err = p.dispatchNewListPlanesPager(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (p *PlanesServerTransport) dispatchNewListPlanesPager(req *http.Request) (*http.Response, error) { + if p.srv.NewListPlanesPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPlanesPager not implemented")} + } + newListPlanesPager := p.newListPlanesPager.get(req) + if newListPlanesPager == nil { +resp := p.srv.NewListPlanesPager(nil) + newListPlanesPager = &resp + p.newListPlanesPager.add(req, newListPlanesPager) + server.PagerResponderInjectNextLinks(newListPlanesPager, req, func(page *v20231001preview.PlanesClientListPlanesResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListPlanesPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + p.newListPlanesPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPlanesPager) { + p.newListPlanesPager.remove(req) + } + return resp, nil +} + +// set this to conditionally intercept incoming requests to PlanesServerTransport +var planesServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/pkg/ucp/api/v20231001preview/fake/zz_generated_radiusplanes_server.go b/pkg/ucp/api/v20231001preview/fake/zz_generated_radiusplanes_server.go new file mode 100644 index 0000000000..3271c005e4 --- /dev/null +++ b/pkg/ucp/api/v20231001preview/fake/zz_generated_radiusplanes_server.go @@ -0,0 +1,308 @@ +// Licensed under the Apache License, Version 2.0 . See LICENSE in the repository root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" + "net/http" + "net/url" + "regexp" +) + +// RadiusPlanesServer is a fake server for instances of the v20231001preview.RadiusPlanesClient type. +type RadiusPlanesServer struct{ + // BeginCreateOrUpdate is the fake for method RadiusPlanesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, planeName string, resource v20231001preview.RadiusPlaneResource, options *v20231001preview.RadiusPlanesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[v20231001preview.RadiusPlanesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method RadiusPlanesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, planeName string, options *v20231001preview.RadiusPlanesClientBeginDeleteOptions) (resp azfake.PollerResponder[v20231001preview.RadiusPlanesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method RadiusPlanesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, planeName string, options *v20231001preview.RadiusPlanesClientGetOptions) (resp azfake.Responder[v20231001preview.RadiusPlanesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method RadiusPlanesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(options *v20231001preview.RadiusPlanesClientListOptions) (resp azfake.PagerResponder[v20231001preview.RadiusPlanesClientListResponse]) + + // BeginUpdate is the fake for method RadiusPlanesClient.BeginUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted + BeginUpdate func(ctx context.Context, planeName string, properties v20231001preview.RadiusPlaneResourceTagsUpdate, options *v20231001preview.RadiusPlanesClientBeginUpdateOptions) (resp azfake.PollerResponder[v20231001preview.RadiusPlanesClientUpdateResponse], errResp azfake.ErrorResponder) + +} + +// NewRadiusPlanesServerTransport creates a new instance of RadiusPlanesServerTransport with the provided implementation. +// The returned RadiusPlanesServerTransport instance is connected to an instance of v20231001preview.RadiusPlanesClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewRadiusPlanesServerTransport(srv *RadiusPlanesServer) *RadiusPlanesServerTransport { + return &RadiusPlanesServerTransport{ + srv: srv, + beginCreateOrUpdate: newTracker[azfake.PollerResponder[v20231001preview.RadiusPlanesClientCreateOrUpdateResponse]](), + beginDelete: newTracker[azfake.PollerResponder[v20231001preview.RadiusPlanesClientDeleteResponse]](), + newListPager: newTracker[azfake.PagerResponder[v20231001preview.RadiusPlanesClientListResponse]](), + beginUpdate: newTracker[azfake.PollerResponder[v20231001preview.RadiusPlanesClientUpdateResponse]](), + } +} + +// RadiusPlanesServerTransport connects instances of v20231001preview.RadiusPlanesClient to instances of RadiusPlanesServer. +// Don't use this type directly, use NewRadiusPlanesServerTransport instead. +type RadiusPlanesServerTransport struct { + srv *RadiusPlanesServer + beginCreateOrUpdate *tracker[azfake.PollerResponder[v20231001preview.RadiusPlanesClientCreateOrUpdateResponse]] + beginDelete *tracker[azfake.PollerResponder[v20231001preview.RadiusPlanesClientDeleteResponse]] + newListPager *tracker[azfake.PagerResponder[v20231001preview.RadiusPlanesClientListResponse]] + beginUpdate *tracker[azfake.PollerResponder[v20231001preview.RadiusPlanesClientUpdateResponse]] +} + +// Do implements the policy.Transporter interface for RadiusPlanesServerTransport. +func (r *RadiusPlanesServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return r.dispatchToMethodFake(req, method) +} + +func (r *RadiusPlanesServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if radiusPlanesServerTransportInterceptor != nil { + res.resp, res.err, intercepted = radiusPlanesServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "RadiusPlanesClient.BeginCreateOrUpdate": + res.resp, res.err = r.dispatchBeginCreateOrUpdate(req) + case "RadiusPlanesClient.BeginDelete": + res.resp, res.err = r.dispatchBeginDelete(req) + case "RadiusPlanesClient.Get": + res.resp, res.err = r.dispatchGet(req) + case "RadiusPlanesClient.NewListPager": + res.resp, res.err = r.dispatchNewListPager(req) + case "RadiusPlanesClient.BeginUpdate": + res.resp, res.err = r.dispatchBeginUpdate(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (r *RadiusPlanesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if r.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + beginCreateOrUpdate := r.beginCreateOrUpdate.get(req) + if beginCreateOrUpdate == nil { + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[v20231001preview.RadiusPlaneResource](req) + if err != nil { + return nil, err + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginCreateOrUpdate(req.Context(), planeNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginCreateOrUpdate = &respr + r.beginCreateOrUpdate.add(req, beginCreateOrUpdate) + } + + resp, err := server.PollerResponderNext(beginCreateOrUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + r.beginCreateOrUpdate.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(beginCreateOrUpdate) { + r.beginCreateOrUpdate.remove(req) + } + + return resp, nil +} + +func (r *RadiusPlanesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if r.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + beginDelete := r.beginDelete.get(req) + if beginDelete == nil { + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginDelete(req.Context(), planeNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginDelete = &respr + r.beginDelete.add(req, beginDelete) + } + + resp, err := server.PollerResponderNext(beginDelete, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + r.beginDelete.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(beginDelete) { + r.beginDelete.remove(req) + } + + return resp, nil +} + +func (r *RadiusPlanesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if r.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.Get(req.Context(), planeNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).RadiusPlaneResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *RadiusPlanesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if r.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := r.newListPager.get(req) + if newListPager == nil { +resp := r.srv.NewListPager(nil) + newListPager = &resp + r.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *v20231001preview.RadiusPlanesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + r.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + r.newListPager.remove(req) + } + return resp, nil +} + +func (r *RadiusPlanesServerTransport) dispatchBeginUpdate(req *http.Request) (*http.Response, error) { + if r.srv.BeginUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginUpdate not implemented")} + } + beginUpdate := r.beginUpdate.get(req) + if beginUpdate == nil { + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[v20231001preview.RadiusPlaneResourceTagsUpdate](req) + if err != nil { + return nil, err + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginUpdate(req.Context(), planeNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginUpdate = &respr + r.beginUpdate.add(req, beginUpdate) + } + + resp, err := server.PollerResponderNext(beginUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { + r.beginUpdate.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} + } + if !server.PollerResponderMore(beginUpdate) { + r.beginUpdate.remove(req) + } + + return resp, nil +} + +// set this to conditionally intercept incoming requests to RadiusPlanesServerTransport +var radiusPlanesServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/pkg/ucp/api/v20231001preview/fake/zz_generated_resourcegroups_server.go b/pkg/ucp/api/v20231001preview/fake/zz_generated_resourcegroups_server.go new file mode 100644 index 0000000000..c66d567bcd --- /dev/null +++ b/pkg/ucp/api/v20231001preview/fake/zz_generated_resourcegroups_server.go @@ -0,0 +1,295 @@ +// Licensed under the Apache License, Version 2.0 . See LICENSE in the repository root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" + "net/http" + "net/url" + "regexp" +) + +// ResourceGroupsServer is a fake server for instances of the v20231001preview.ResourceGroupsClient type. +type ResourceGroupsServer struct{ + // CreateOrUpdate is the fake for method ResourceGroupsClient.CreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + CreateOrUpdate func(ctx context.Context, planeName string, resourceGroupName string, resource v20231001preview.ResourceGroupResource, options *v20231001preview.ResourceGroupsClientCreateOrUpdateOptions) (resp azfake.Responder[v20231001preview.ResourceGroupsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // Delete is the fake for method ResourceGroupsClient.Delete + // HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent + Delete func(ctx context.Context, planeName string, resourceGroupName string, options *v20231001preview.ResourceGroupsClientDeleteOptions) (resp azfake.Responder[v20231001preview.ResourceGroupsClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ResourceGroupsClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, planeName string, resourceGroupName string, options *v20231001preview.ResourceGroupsClientGetOptions) (resp azfake.Responder[v20231001preview.ResourceGroupsClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ResourceGroupsClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(planeName string, options *v20231001preview.ResourceGroupsClientListOptions) (resp azfake.PagerResponder[v20231001preview.ResourceGroupsClientListResponse]) + + // Update is the fake for method ResourceGroupsClient.Update + // HTTP status codes to indicate success: http.StatusOK + Update func(ctx context.Context, planeName string, resourceGroupName string, properties v20231001preview.ResourceGroupResourceTagsUpdate, options *v20231001preview.ResourceGroupsClientUpdateOptions) (resp azfake.Responder[v20231001preview.ResourceGroupsClientUpdateResponse], errResp azfake.ErrorResponder) + +} + +// NewResourceGroupsServerTransport creates a new instance of ResourceGroupsServerTransport with the provided implementation. +// The returned ResourceGroupsServerTransport instance is connected to an instance of v20231001preview.ResourceGroupsClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewResourceGroupsServerTransport(srv *ResourceGroupsServer) *ResourceGroupsServerTransport { + return &ResourceGroupsServerTransport{ + srv: srv, + newListPager: newTracker[azfake.PagerResponder[v20231001preview.ResourceGroupsClientListResponse]](), + } +} + +// ResourceGroupsServerTransport connects instances of v20231001preview.ResourceGroupsClient to instances of ResourceGroupsServer. +// Don't use this type directly, use NewResourceGroupsServerTransport instead. +type ResourceGroupsServerTransport struct { + srv *ResourceGroupsServer + newListPager *tracker[azfake.PagerResponder[v20231001preview.ResourceGroupsClientListResponse]] +} + +// Do implements the policy.Transporter interface for ResourceGroupsServerTransport. +func (r *ResourceGroupsServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return r.dispatchToMethodFake(req, method) +} + +func (r *ResourceGroupsServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if resourceGroupsServerTransportInterceptor != nil { + res.resp, res.err, intercepted = resourceGroupsServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "ResourceGroupsClient.CreateOrUpdate": + res.resp, res.err = r.dispatchCreateOrUpdate(req) + case "ResourceGroupsClient.Delete": + res.resp, res.err = r.dispatchDelete(req) + case "ResourceGroupsClient.Get": + res.resp, res.err = r.dispatchGet(req) + case "ResourceGroupsClient.NewListPager": + res.resp, res.err = r.dispatchNewListPager(req) + case "ResourceGroupsClient.Update": + res.resp, res.err = r.dispatchUpdate(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (r *ResourceGroupsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { + if r.srv.CreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdate not implemented")} + } + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[v20231001preview.ResourceGroupResource](req) + if err != nil { + return nil, err + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.CreateOrUpdate(req.Context(), planeNameParam, resourceGroupNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ResourceGroupResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *ResourceGroupsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) { + if r.srv.Delete == nil { + return nil, &nonRetriableError{errors.New("fake for method Delete not implemented")} + } + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.Delete(req.Context(), planeNameParam, resourceGroupNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)} + } + resp, err := server.NewResponse(respContent, req, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *ResourceGroupsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if r.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.Get(req.Context(), planeNameParam, resourceGroupNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ResourceGroupResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *ResourceGroupsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if r.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := r.newListPager.get(req) + if newListPager == nil { + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } +resp := r.srv.NewListPager(planeNameParam, nil) + newListPager = &resp + r.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *v20231001preview.ResourceGroupsClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + r.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + r.newListPager.remove(req) + } + return resp, nil +} + +func (r *ResourceGroupsServerTransport) dispatchUpdate(req *http.Request) (*http.Response, error) { + if r.srv.Update == nil { + return nil, &nonRetriableError{errors.New("fake for method Update not implemented")} + } + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[v20231001preview.ResourceGroupResourceTagsUpdate](req) + if err != nil { + return nil, err + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.Update(req.Context(), planeNameParam, resourceGroupNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ResourceGroupResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +// set this to conditionally intercept incoming requests to ResourceGroupsServerTransport +var resourceGroupsServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/pkg/ucp/api/v20231001preview/fake/zz_generated_resourceproviders_server.go b/pkg/ucp/api/v20231001preview/fake/zz_generated_resourceproviders_server.go new file mode 100644 index 0000000000..138f9aaceb --- /dev/null +++ b/pkg/ucp/api/v20231001preview/fake/zz_generated_resourceproviders_server.go @@ -0,0 +1,362 @@ +// Licensed under the Apache License, Version 2.0 . See LICENSE in the repository root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" + "net/http" + "net/url" + "regexp" +) + +// ResourceProvidersServer is a fake server for instances of the v20231001preview.ResourceProvidersClient type. +type ResourceProvidersServer struct{ + // BeginCreateOrUpdate is the fake for method ResourceProvidersClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, planeName string, resourceProviderName string, resource v20231001preview.ResourceProviderResource, options *v20231001preview.ResourceProvidersClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[v20231001preview.ResourceProvidersClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ResourceProvidersClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, planeName string, resourceProviderName string, options *v20231001preview.ResourceProvidersClientBeginDeleteOptions) (resp azfake.PollerResponder[v20231001preview.ResourceProvidersClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ResourceProvidersClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, planeName string, resourceProviderName string, options *v20231001preview.ResourceProvidersClientGetOptions) (resp azfake.Responder[v20231001preview.ResourceProvidersClientGetResponse], errResp azfake.ErrorResponder) + + // GetProviderSummary is the fake for method ResourceProvidersClient.GetProviderSummary + // HTTP status codes to indicate success: http.StatusOK + GetProviderSummary func(ctx context.Context, planeName string, resourceProviderName string, options *v20231001preview.ResourceProvidersClientGetProviderSummaryOptions) (resp azfake.Responder[v20231001preview.ResourceProvidersClientGetProviderSummaryResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ResourceProvidersClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(planeName string, options *v20231001preview.ResourceProvidersClientListOptions) (resp azfake.PagerResponder[v20231001preview.ResourceProvidersClientListResponse]) + + // NewListProviderSummariesPager is the fake for method ResourceProvidersClient.NewListProviderSummariesPager + // HTTP status codes to indicate success: http.StatusOK + NewListProviderSummariesPager func(planeName string, options *v20231001preview.ResourceProvidersClientListProviderSummariesOptions) (resp azfake.PagerResponder[v20231001preview.ResourceProvidersClientListProviderSummariesResponse]) + +} + +// NewResourceProvidersServerTransport creates a new instance of ResourceProvidersServerTransport with the provided implementation. +// The returned ResourceProvidersServerTransport instance is connected to an instance of v20231001preview.ResourceProvidersClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewResourceProvidersServerTransport(srv *ResourceProvidersServer) *ResourceProvidersServerTransport { + return &ResourceProvidersServerTransport{ + srv: srv, + beginCreateOrUpdate: newTracker[azfake.PollerResponder[v20231001preview.ResourceProvidersClientCreateOrUpdateResponse]](), + beginDelete: newTracker[azfake.PollerResponder[v20231001preview.ResourceProvidersClientDeleteResponse]](), + newListPager: newTracker[azfake.PagerResponder[v20231001preview.ResourceProvidersClientListResponse]](), + newListProviderSummariesPager: newTracker[azfake.PagerResponder[v20231001preview.ResourceProvidersClientListProviderSummariesResponse]](), + } +} + +// ResourceProvidersServerTransport connects instances of v20231001preview.ResourceProvidersClient to instances of ResourceProvidersServer. +// Don't use this type directly, use NewResourceProvidersServerTransport instead. +type ResourceProvidersServerTransport struct { + srv *ResourceProvidersServer + beginCreateOrUpdate *tracker[azfake.PollerResponder[v20231001preview.ResourceProvidersClientCreateOrUpdateResponse]] + beginDelete *tracker[azfake.PollerResponder[v20231001preview.ResourceProvidersClientDeleteResponse]] + newListPager *tracker[azfake.PagerResponder[v20231001preview.ResourceProvidersClientListResponse]] + newListProviderSummariesPager *tracker[azfake.PagerResponder[v20231001preview.ResourceProvidersClientListProviderSummariesResponse]] +} + +// Do implements the policy.Transporter interface for ResourceProvidersServerTransport. +func (r *ResourceProvidersServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return r.dispatchToMethodFake(req, method) +} + +func (r *ResourceProvidersServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if resourceProvidersServerTransportInterceptor != nil { + res.resp, res.err, intercepted = resourceProvidersServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "ResourceProvidersClient.BeginCreateOrUpdate": + res.resp, res.err = r.dispatchBeginCreateOrUpdate(req) + case "ResourceProvidersClient.BeginDelete": + res.resp, res.err = r.dispatchBeginDelete(req) + case "ResourceProvidersClient.Get": + res.resp, res.err = r.dispatchGet(req) + case "ResourceProvidersClient.GetProviderSummary": + res.resp, res.err = r.dispatchGetProviderSummary(req) + case "ResourceProvidersClient.NewListPager": + res.resp, res.err = r.dispatchNewListPager(req) + case "ResourceProvidersClient.NewListProviderSummariesPager": + res.resp, res.err = r.dispatchNewListProviderSummariesPager(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (r *ResourceProvidersServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if r.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + beginCreateOrUpdate := r.beginCreateOrUpdate.get(req) + if beginCreateOrUpdate == nil { + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Resources/resourceproviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[v20231001preview.ResourceProviderResource](req) + if err != nil { + return nil, err + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceProviderNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginCreateOrUpdate(req.Context(), planeNameParam, resourceProviderNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginCreateOrUpdate = &respr + r.beginCreateOrUpdate.add(req, beginCreateOrUpdate) + } + + resp, err := server.PollerResponderNext(beginCreateOrUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + r.beginCreateOrUpdate.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(beginCreateOrUpdate) { + r.beginCreateOrUpdate.remove(req) + } + + return resp, nil +} + +func (r *ResourceProvidersServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if r.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + beginDelete := r.beginDelete.get(req) + if beginDelete == nil { + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Resources/resourceproviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceProviderNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginDelete(req.Context(), planeNameParam, resourceProviderNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginDelete = &respr + r.beginDelete.add(req, beginDelete) + } + + resp, err := server.PollerResponderNext(beginDelete, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + r.beginDelete.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(beginDelete) { + r.beginDelete.remove(req) + } + + return resp, nil +} + +func (r *ResourceProvidersServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if r.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Resources/resourceproviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceProviderNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.Get(req.Context(), planeNameParam, resourceProviderNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ResourceProviderResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *ResourceProvidersServerTransport) dispatchGetProviderSummary(req *http.Request) (*http.Response, error) { + if r.srv.GetProviderSummary == nil { + return nil, &nonRetriableError{errors.New("fake for method GetProviderSummary not implemented")} + } + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceProviderNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.GetProviderSummary(req.Context(), planeNameParam, resourceProviderNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ResourceProviderSummary, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *ResourceProvidersServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if r.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := r.newListPager.get(req) + if newListPager == nil { + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Resources/resourceproviders` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } +resp := r.srv.NewListPager(planeNameParam, nil) + newListPager = &resp + r.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *v20231001preview.ResourceProvidersClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + r.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + r.newListPager.remove(req) + } + return resp, nil +} + +func (r *ResourceProvidersServerTransport) dispatchNewListProviderSummariesPager(req *http.Request) (*http.Response, error) { + if r.srv.NewListProviderSummariesPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListProviderSummariesPager not implemented")} + } + newListProviderSummariesPager := r.newListProviderSummariesPager.get(req) + if newListProviderSummariesPager == nil { + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 1 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } +resp := r.srv.NewListProviderSummariesPager(planeNameParam, nil) + newListProviderSummariesPager = &resp + r.newListProviderSummariesPager.add(req, newListProviderSummariesPager) + server.PagerResponderInjectNextLinks(newListProviderSummariesPager, req, func(page *v20231001preview.ResourceProvidersClientListProviderSummariesResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListProviderSummariesPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + r.newListProviderSummariesPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListProviderSummariesPager) { + r.newListProviderSummariesPager.remove(req) + } + return resp, nil +} + +// set this to conditionally intercept incoming requests to ResourceProvidersServerTransport +var resourceProvidersServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/pkg/ucp/api/v20231001preview/fake/zz_generated_resources_server.go b/pkg/ucp/api/v20231001preview/fake/zz_generated_resources_server.go new file mode 100644 index 0000000000..39f575e452 --- /dev/null +++ b/pkg/ucp/api/v20231001preview/fake/zz_generated_resources_server.go @@ -0,0 +1,134 @@ +// Licensed under the Apache License, Version 2.0 . See LICENSE in the repository root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" + "net/http" + "net/url" + "regexp" +) + +// ResourcesServer is a fake server for instances of the v20231001preview.ResourcesClient type. +type ResourcesServer struct{ + // NewListPager is the fake for method ResourcesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(planeName string, resourceGroupName string, options *v20231001preview.ResourcesClientListOptions) (resp azfake.PagerResponder[v20231001preview.ResourcesClientListResponse]) + +} + +// NewResourcesServerTransport creates a new instance of ResourcesServerTransport with the provided implementation. +// The returned ResourcesServerTransport instance is connected to an instance of v20231001preview.ResourcesClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewResourcesServerTransport(srv *ResourcesServer) *ResourcesServerTransport { + return &ResourcesServerTransport{ + srv: srv, + newListPager: newTracker[azfake.PagerResponder[v20231001preview.ResourcesClientListResponse]](), + } +} + +// ResourcesServerTransport connects instances of v20231001preview.ResourcesClient to instances of ResourcesServer. +// Don't use this type directly, use NewResourcesServerTransport instead. +type ResourcesServerTransport struct { + srv *ResourcesServer + newListPager *tracker[azfake.PagerResponder[v20231001preview.ResourcesClientListResponse]] +} + +// Do implements the policy.Transporter interface for ResourcesServerTransport. +func (r *ResourcesServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return r.dispatchToMethodFake(req, method) +} + +func (r *ResourcesServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if resourcesServerTransportInterceptor != nil { + res.resp, res.err, intercepted = resourcesServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "ResourcesClient.NewListPager": + res.resp, res.err = r.dispatchNewListPager(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (r *ResourcesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if r.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := r.newListPager.get(req) + if newListPager == nil { + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcegroups/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resources` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) + if err != nil { + return nil, err + } +resp := r.srv.NewListPager(planeNameParam, resourceGroupNameParam, nil) + newListPager = &resp + r.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *v20231001preview.ResourcesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + r.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + r.newListPager.remove(req) + } + return resp, nil +} + +// set this to conditionally intercept incoming requests to ResourcesServerTransport +var resourcesServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/pkg/ucp/api/v20231001preview/fake/zz_generated_resourcetypes_server.go b/pkg/ucp/api/v20231001preview/fake/zz_generated_resourcetypes_server.go new file mode 100644 index 0000000000..d745f522d0 --- /dev/null +++ b/pkg/ucp/api/v20231001preview/fake/zz_generated_resourcetypes_server.go @@ -0,0 +1,294 @@ +// Licensed under the Apache License, Version 2.0 . See LICENSE in the repository root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "context" + "errors" + "fmt" + azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" + "net/http" + "net/url" + "regexp" +) + +// ResourceTypesServer is a fake server for instances of the v20231001preview.ResourceTypesClient type. +type ResourceTypesServer struct{ + // BeginCreateOrUpdate is the fake for method ResourceTypesClient.BeginCreateOrUpdate + // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated + BeginCreateOrUpdate func(ctx context.Context, planeName string, resourceProviderName string, resourceTypeName string, resource v20231001preview.ResourceTypeResource, options *v20231001preview.ResourceTypesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[v20231001preview.ResourceTypesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) + + // BeginDelete is the fake for method ResourceTypesClient.BeginDelete + // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent + BeginDelete func(ctx context.Context, planeName string, resourceProviderName string, resourceTypeName string, options *v20231001preview.ResourceTypesClientBeginDeleteOptions) (resp azfake.PollerResponder[v20231001preview.ResourceTypesClientDeleteResponse], errResp azfake.ErrorResponder) + + // Get is the fake for method ResourceTypesClient.Get + // HTTP status codes to indicate success: http.StatusOK + Get func(ctx context.Context, planeName string, resourceProviderName string, resourceTypeName string, options *v20231001preview.ResourceTypesClientGetOptions) (resp azfake.Responder[v20231001preview.ResourceTypesClientGetResponse], errResp azfake.ErrorResponder) + + // NewListPager is the fake for method ResourceTypesClient.NewListPager + // HTTP status codes to indicate success: http.StatusOK + NewListPager func(planeName string, resourceProviderName string, options *v20231001preview.ResourceTypesClientListOptions) (resp azfake.PagerResponder[v20231001preview.ResourceTypesClientListResponse]) + +} + +// NewResourceTypesServerTransport creates a new instance of ResourceTypesServerTransport with the provided implementation. +// The returned ResourceTypesServerTransport instance is connected to an instance of v20231001preview.ResourceTypesClient via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewResourceTypesServerTransport(srv *ResourceTypesServer) *ResourceTypesServerTransport { + return &ResourceTypesServerTransport{ + srv: srv, + beginCreateOrUpdate: newTracker[azfake.PollerResponder[v20231001preview.ResourceTypesClientCreateOrUpdateResponse]](), + beginDelete: newTracker[azfake.PollerResponder[v20231001preview.ResourceTypesClientDeleteResponse]](), + newListPager: newTracker[azfake.PagerResponder[v20231001preview.ResourceTypesClientListResponse]](), + } +} + +// ResourceTypesServerTransport connects instances of v20231001preview.ResourceTypesClient to instances of ResourceTypesServer. +// Don't use this type directly, use NewResourceTypesServerTransport instead. +type ResourceTypesServerTransport struct { + srv *ResourceTypesServer + beginCreateOrUpdate *tracker[azfake.PollerResponder[v20231001preview.ResourceTypesClientCreateOrUpdateResponse]] + beginDelete *tracker[azfake.PollerResponder[v20231001preview.ResourceTypesClientDeleteResponse]] + newListPager *tracker[azfake.PagerResponder[v20231001preview.ResourceTypesClientListResponse]] +} + +// Do implements the policy.Transporter interface for ResourceTypesServerTransport. +func (r *ResourceTypesServerTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + return r.dispatchToMethodFake(req, method) +} + +func (r *ResourceTypesServerTransport) dispatchToMethodFake(req *http.Request, method string) (*http.Response, error) { + resultChan := make(chan result) + defer close(resultChan) + + go func() { + var intercepted bool + var res result + if resourceTypesServerTransportInterceptor != nil { + res.resp, res.err, intercepted = resourceTypesServerTransportInterceptor.Do(req) + } + if !intercepted { + switch method { + case "ResourceTypesClient.BeginCreateOrUpdate": + res.resp, res.err = r.dispatchBeginCreateOrUpdate(req) + case "ResourceTypesClient.BeginDelete": + res.resp, res.err = r.dispatchBeginDelete(req) + case "ResourceTypesClient.Get": + res.resp, res.err = r.dispatchGet(req) + case "ResourceTypesClient.NewListPager": + res.resp, res.err = r.dispatchNewListPager(req) + default: + res.err = fmt.Errorf("unhandled API %s", method) + } + + } + select { + case resultChan <- res: + case <-req.Context().Done(): + } + }() + + select { + case <-req.Context().Done(): + return nil, req.Context().Err() + case res := <-resultChan: + return res.resp, res.err + } +} + +func (r *ResourceTypesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { + if r.srv.BeginCreateOrUpdate == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} + } + beginCreateOrUpdate := r.beginCreateOrUpdate.get(req) + if beginCreateOrUpdate == nil { + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Resources/resourceproviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcetypes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + body, err := server.UnmarshalRequestAsJSON[v20231001preview.ResourceTypeResource](req) + if err != nil { + return nil, err + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceProviderNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderName")]) + if err != nil { + return nil, err + } + resourceTypeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceTypeName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginCreateOrUpdate(req.Context(), planeNameParam, resourceProviderNameParam, resourceTypeNameParam, body, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginCreateOrUpdate = &respr + r.beginCreateOrUpdate.add(req, beginCreateOrUpdate) + } + + resp, err := server.PollerResponderNext(beginCreateOrUpdate, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { + r.beginCreateOrUpdate.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} + } + if !server.PollerResponderMore(beginCreateOrUpdate) { + r.beginCreateOrUpdate.remove(req) + } + + return resp, nil +} + +func (r *ResourceTypesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { + if r.srv.BeginDelete == nil { + return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} + } + beginDelete := r.beginDelete.get(req) + if beginDelete == nil { + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Resources/resourceproviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcetypes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceProviderNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderName")]) + if err != nil { + return nil, err + } + resourceTypeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceTypeName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.BeginDelete(req.Context(), planeNameParam, resourceProviderNameParam, resourceTypeNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + beginDelete = &respr + r.beginDelete.add(req, beginDelete) + } + + resp, err := server.PollerResponderNext(beginDelete, req) + if err != nil { + return nil, err + } + + if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { + r.beginDelete.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} + } + if !server.PollerResponderMore(beginDelete) { + r.beginDelete.remove(req) + } + + return resp, nil +} + +func (r *ResourceTypesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { + if r.srv.Get == nil { + return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} + } + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Resources/resourceproviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcetypes/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 3 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceProviderNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderName")]) + if err != nil { + return nil, err + } + resourceTypeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceTypeName")]) + if err != nil { + return nil, err + } + respr, errRespr := r.srv.Get(req.Context(), planeNameParam, resourceProviderNameParam, resourceTypeNameParam, nil) + if respErr := server.GetError(errRespr, req); respErr != nil { + return nil, respErr + } + respContent := server.GetResponseContent(respr) + if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} + } + resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ResourceTypeResource, req) + if err != nil { + return nil, err + } + return resp, nil +} + +func (r *ResourceTypesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { + if r.srv.NewListPager == nil { + return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} + } + newListPager := r.newListPager.get(req) + if newListPager == nil { + const regexStr = `/planes/radius/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/System\.Resources/resourceproviders/(?P[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourcetypes` + regex := regexp.MustCompile(regexStr) + matches := regex.FindStringSubmatch(req.URL.EscapedPath()) + if matches == nil || len(matches) < 2 { + return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) + } + planeNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("planeName")]) + if err != nil { + return nil, err + } + resourceProviderNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceProviderName")]) + if err != nil { + return nil, err + } +resp := r.srv.NewListPager(planeNameParam, resourceProviderNameParam, nil) + newListPager = &resp + r.newListPager.add(req, newListPager) + server.PagerResponderInjectNextLinks(newListPager, req, func(page *v20231001preview.ResourceTypesClientListResponse, createLink func() string) { + page.NextLink = to.Ptr(createLink()) + }) + } + resp, err := server.PagerResponderNext(newListPager, req) + if err != nil { + return nil, err + } + if !contains([]int{http.StatusOK}, resp.StatusCode) { + r.newListPager.remove(req) + return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} + } + if !server.PagerResponderMore(newListPager) { + r.newListPager.remove(req) + } + return resp, nil +} + +// set this to conditionally intercept incoming requests to ResourceTypesServerTransport +var resourceTypesServerTransportInterceptor interface { + // Do returns true if the server transport should use the returned response/error + Do(*http.Request) (*http.Response, error, bool) +} diff --git a/pkg/ucp/api/v20231001preview/fake/zz_generated_server_factory.go b/pkg/ucp/api/v20231001preview/fake/zz_generated_server_factory.go new file mode 100644 index 0000000000..90ceab79c8 --- /dev/null +++ b/pkg/ucp/api/v20231001preview/fake/zz_generated_server_factory.go @@ -0,0 +1,150 @@ +// Licensed under the Apache License, Version 2.0 . See LICENSE in the repository root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + +import ( + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "strings" + "sync" +) + +// ServerFactory is a fake server for instances of the v20231001preview.ClientFactory type. +type ServerFactory struct { + // APIVersionsServer contains the fakes for client APIVersionsClient + APIVersionsServer APIVersionsServer + + // AwsCredentialsServer contains the fakes for client AwsCredentialsClient + AwsCredentialsServer AwsCredentialsServer + + // AwsPlanesServer contains the fakes for client AwsPlanesClient + AwsPlanesServer AwsPlanesServer + + // AzureCredentialsServer contains the fakes for client AzureCredentialsClient + AzureCredentialsServer AzureCredentialsServer + + // AzurePlanesServer contains the fakes for client AzurePlanesClient + AzurePlanesServer AzurePlanesServer + + // LocationsServer contains the fakes for client LocationsClient + LocationsServer LocationsServer + + // PlanesServer contains the fakes for client PlanesClient + PlanesServer PlanesServer + + // RadiusPlanesServer contains the fakes for client RadiusPlanesClient + RadiusPlanesServer RadiusPlanesServer + + // ResourceGroupsServer contains the fakes for client ResourceGroupsClient + ResourceGroupsServer ResourceGroupsServer + + // ResourceProvidersServer contains the fakes for client ResourceProvidersClient + ResourceProvidersServer ResourceProvidersServer + + // ResourceTypesServer contains the fakes for client ResourceTypesClient + ResourceTypesServer ResourceTypesServer + + // ResourcesServer contains the fakes for client ResourcesClient + ResourcesServer ResourcesServer + +} + +// NewServerFactoryTransport creates a new instance of ServerFactoryTransport with the provided implementation. +// The returned ServerFactoryTransport instance is connected to an instance of v20231001preview.ClientFactory via the +// azcore.ClientOptions.Transporter field in the client's constructor parameters. +func NewServerFactoryTransport(srv *ServerFactory) *ServerFactoryTransport { + return &ServerFactoryTransport{ + srv: srv, + } +} + +// ServerFactoryTransport connects instances of v20231001preview.ClientFactory to instances of ServerFactory. +// Don't use this type directly, use NewServerFactoryTransport instead. +type ServerFactoryTransport struct { + srv *ServerFactory + trMu sync.Mutex + trAPIVersionsServer *APIVersionsServerTransport + trAwsCredentialsServer *AwsCredentialsServerTransport + trAwsPlanesServer *AwsPlanesServerTransport + trAzureCredentialsServer *AzureCredentialsServerTransport + trAzurePlanesServer *AzurePlanesServerTransport + trLocationsServer *LocationsServerTransport + trPlanesServer *PlanesServerTransport + trRadiusPlanesServer *RadiusPlanesServerTransport + trResourceGroupsServer *ResourceGroupsServerTransport + trResourceProvidersServer *ResourceProvidersServerTransport + trResourceTypesServer *ResourceTypesServerTransport + trResourcesServer *ResourcesServerTransport +} + +// Do implements the policy.Transporter interface for ServerFactoryTransport. +func (s *ServerFactoryTransport) Do(req *http.Request) (*http.Response, error) { + rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) + method, ok := rawMethod.(string) + if !ok { + return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} + } + + client := method[:strings.Index(method, ".")] + var resp *http.Response + var err error + + switch client { + case "APIVersionsClient": + initServer(s, &s.trAPIVersionsServer, func() *APIVersionsServerTransport { return NewAPIVersionsServerTransport(&s.srv.APIVersionsServer) }) + resp, err = s.trAPIVersionsServer.Do(req) + case "AwsCredentialsClient": + initServer(s, &s.trAwsCredentialsServer, func() *AwsCredentialsServerTransport { return NewAwsCredentialsServerTransport(&s.srv.AwsCredentialsServer) }) + resp, err = s.trAwsCredentialsServer.Do(req) + case "AwsPlanesClient": + initServer(s, &s.trAwsPlanesServer, func() *AwsPlanesServerTransport { return NewAwsPlanesServerTransport(&s.srv.AwsPlanesServer) }) + resp, err = s.trAwsPlanesServer.Do(req) + case "AzureCredentialsClient": + initServer(s, &s.trAzureCredentialsServer, func() *AzureCredentialsServerTransport { return NewAzureCredentialsServerTransport(&s.srv.AzureCredentialsServer) }) + resp, err = s.trAzureCredentialsServer.Do(req) + case "AzurePlanesClient": + initServer(s, &s.trAzurePlanesServer, func() *AzurePlanesServerTransport { return NewAzurePlanesServerTransport(&s.srv.AzurePlanesServer) }) + resp, err = s.trAzurePlanesServer.Do(req) + case "LocationsClient": + initServer(s, &s.trLocationsServer, func() *LocationsServerTransport { return NewLocationsServerTransport(&s.srv.LocationsServer) }) + resp, err = s.trLocationsServer.Do(req) + case "PlanesClient": + initServer(s, &s.trPlanesServer, func() *PlanesServerTransport { return NewPlanesServerTransport(&s.srv.PlanesServer) }) + resp, err = s.trPlanesServer.Do(req) + case "RadiusPlanesClient": + initServer(s, &s.trRadiusPlanesServer, func() *RadiusPlanesServerTransport { return NewRadiusPlanesServerTransport(&s.srv.RadiusPlanesServer) }) + resp, err = s.trRadiusPlanesServer.Do(req) + case "ResourceGroupsClient": + initServer(s, &s.trResourceGroupsServer, func() *ResourceGroupsServerTransport { return NewResourceGroupsServerTransport(&s.srv.ResourceGroupsServer) }) + resp, err = s.trResourceGroupsServer.Do(req) + case "ResourceProvidersClient": + initServer(s, &s.trResourceProvidersServer, func() *ResourceProvidersServerTransport { return NewResourceProvidersServerTransport(&s.srv.ResourceProvidersServer) }) + resp, err = s.trResourceProvidersServer.Do(req) + case "ResourceTypesClient": + initServer(s, &s.trResourceTypesServer, func() *ResourceTypesServerTransport { return NewResourceTypesServerTransport(&s.srv.ResourceTypesServer) }) + resp, err = s.trResourceTypesServer.Do(req) + case "ResourcesClient": + initServer(s, &s.trResourcesServer, func() *ResourcesServerTransport { return NewResourcesServerTransport(&s.srv.ResourcesServer) }) + resp, err = s.trResourcesServer.Do(req) + default: + err = fmt.Errorf("unhandled client %s", client) + } + + if err != nil { + return nil, err + } + + return resp, nil +} + +func initServer[T any](s *ServerFactoryTransport, dst **T, src func() *T) { + s.trMu.Lock() + if *dst == nil { + *dst = src() + } + s.trMu.Unlock() +} diff --git a/pkg/ucp/api/v20231001preview/fake/zz_generated_time_rfc3339.go b/pkg/ucp/api/v20231001preview/fake/zz_generated_time_rfc3339.go new file mode 100644 index 0000000000..83c75cddc6 --- /dev/null +++ b/pkg/ucp/api/v20231001preview/fake/zz_generated_time_rfc3339.go @@ -0,0 +1,114 @@ +// Licensed under the Apache License, Version 2.0 . See LICENSE in the repository root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package fake + + + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" + "regexp" + "strings" + "time" +) + + + +// Azure reports time in UTC but it doesn't include the 'Z' time zone suffix in some cases. +var tzOffsetRegex = regexp.MustCompile(`(?:Z|z|\+|-)(?:\d+:\d+)*"*$`) + +const ( + utcDateTime = "2006-01-02T15:04:05.999999999" + utcDateTimeJSON = `"` + utcDateTime + `"` + utcDateTimeNoT = "2006-01-02 15:04:05.999999999" + utcDateTimeJSONNoT = `"` + utcDateTimeNoT + `"` + dateTimeNoT = `2006-01-02 15:04:05.999999999Z07:00` + dateTimeJSON = `"` + time.RFC3339Nano + `"` + dateTimeJSONNoT = `"` + dateTimeNoT + `"` +) + +type dateTimeRFC3339 time.Time + +func (t dateTimeRFC3339) MarshalJSON() ([]byte, error) { + tt := time.Time(t) + return tt.MarshalJSON() +} + +func (t dateTimeRFC3339) MarshalText() ([]byte, error) { + tt := time.Time(t) + return tt.MarshalText() +} + +func (t *dateTimeRFC3339) UnmarshalJSON(data []byte) error { + tzOffset := tzOffsetRegex.Match(data) + hasT := strings.Contains(string(data), "T") || strings.Contains(string(data), "t") + var layout string + if tzOffset && hasT { + layout = dateTimeJSON + } else if tzOffset { + layout = dateTimeJSONNoT + } else if hasT { + layout = utcDateTimeJSON + } else { + layout = utcDateTimeJSONNoT + } + return t.Parse(layout, string(data)) +} + +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + if len(data) == 0 { + return nil + } + tzOffset := tzOffsetRegex.Match(data) + hasT := strings.Contains(string(data), "T") || strings.Contains(string(data), "t") + var layout string + if tzOffset && hasT { + layout = time.RFC3339Nano + } else if tzOffset { + layout = dateTimeNoT + } else if hasT { + layout = utcDateTime + } else { + layout = utcDateTimeNoT + } + return t.Parse(layout, string(data)) +} + +func (t *dateTimeRFC3339) Parse(layout, value string) error { + p, err := time.Parse(layout, strings.ToUpper(value)) + *t = dateTimeRFC3339(p) + return err +} + +func (t dateTimeRFC3339) String() string { + return time.Time(t).Format(time.RFC3339Nano) +} + + +func populateDateTimeRFC3339(m map[string]any, k string, t *time.Time) { + if t == nil { + return + } else if azcore.IsNullValue(t) { + m[k] = nil + return + } else if reflect.ValueOf(t).IsNil() { + return + } + m[k] = (*dateTimeRFC3339)(t) +} + +func unpopulateDateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { + if data == nil || string(data) == "null" { + return nil + } + var aux dateTimeRFC3339 + if err := json.Unmarshal(data, &aux); err != nil { + return fmt.Errorf("struct field %s: %v", fn, err) + } + *t = (*time.Time)(&aux) + return nil +} diff --git a/pkg/ucp/api/v20231001preview/zz_generated_apiversions_client.go b/pkg/ucp/api/v20231001preview/zz_generated_apiversions_client.go index d050dd8ec8..7910252031 100644 --- a/pkg/ucp/api/v20231001preview/zz_generated_apiversions_client.go +++ b/pkg/ucp/api/v20231001preview/zz_generated_apiversions_client.go @@ -71,7 +71,9 @@ func (client *APIVersionsClient) BeginCreateOrUpdate(ctx context.Context, planeN // Generated from API version 2023-10-01-preview func (client *APIVersionsClient) createOrUpdate(ctx context.Context, planeName string, resourceProviderName string, resourceTypeName string, apiVersionName string, resource APIVersionResource, options *APIVersionsClientBeginCreateOrUpdateOptions) (*http.Response, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "APIVersionsClient.BeginCreateOrUpdate", client.internal.Tracer(), nil) + const operationName = "APIVersionsClient.BeginCreateOrUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.createOrUpdateCreateRequest(ctx, planeName, resourceProviderName, resourceTypeName, apiVersionName, resource, options) if err != nil { @@ -154,7 +156,9 @@ func (client *APIVersionsClient) BeginDelete(ctx context.Context, planeName stri // Generated from API version 2023-10-01-preview func (client *APIVersionsClient) deleteOperation(ctx context.Context, planeName string, resourceProviderName string, resourceTypeName string, apiVersionName string, options *APIVersionsClientBeginDeleteOptions) (*http.Response, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "APIVersionsClient.BeginDelete", client.internal.Tracer(), nil) + const operationName = "APIVersionsClient.BeginDelete" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.deleteCreateRequest(ctx, planeName, resourceProviderName, resourceTypeName, apiVersionName, options) if err != nil { @@ -212,7 +216,9 @@ func (client *APIVersionsClient) deleteCreateRequest(ctx context.Context, planeN // - options - APIVersionsClientGetOptions contains the optional parameters for the APIVersionsClient.Get method. func (client *APIVersionsClient) Get(ctx context.Context, planeName string, resourceProviderName string, resourceTypeName string, apiVersionName string, options *APIVersionsClientGetOptions) (APIVersionsClientGetResponse, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "APIVersionsClient.Get", client.internal.Tracer(), nil) + const operationName = "APIVersionsClient.Get" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.getCreateRequest(ctx, planeName, resourceProviderName, resourceTypeName, apiVersionName, options) if err != nil { @@ -282,6 +288,7 @@ func (client *APIVersionsClient) NewListPager(planeName string, resourceProvider return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *APIVersionsClientListResponse) (APIVersionsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "APIVersionsClient.NewListPager") nextLink := "" if page != nil { nextLink = *page.NextLink diff --git a/pkg/ucp/api/v20231001preview/zz_generated_awscredentials_client.go b/pkg/ucp/api/v20231001preview/zz_generated_awscredentials_client.go index c460688e0a..20c91b7411 100644 --- a/pkg/ucp/api/v20231001preview/zz_generated_awscredentials_client.go +++ b/pkg/ucp/api/v20231001preview/zz_generated_awscredentials_client.go @@ -47,7 +47,9 @@ func NewAwsCredentialsClient(credential azcore.TokenCredential, options *arm.Cli // method. func (client *AwsCredentialsClient) CreateOrUpdate(ctx context.Context, planeName string, credentialName string, resource AwsCredentialResource, options *AwsCredentialsClientCreateOrUpdateOptions) (AwsCredentialsClientCreateOrUpdateResponse, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "AwsCredentialsClient.CreateOrUpdate", client.internal.Tracer(), nil) + const operationName = "AwsCredentialsClient.CreateOrUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.createOrUpdateCreateRequest(ctx, planeName, credentialName, resource, options) if err != nil { @@ -105,7 +107,9 @@ func (client *AwsCredentialsClient) createOrUpdateHandleResponse(resp *http.Resp // - options - AwsCredentialsClientDeleteOptions contains the optional parameters for the AwsCredentialsClient.Delete method. func (client *AwsCredentialsClient) Delete(ctx context.Context, planeName string, credentialName string, options *AwsCredentialsClientDeleteOptions) (AwsCredentialsClientDeleteResponse, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "AwsCredentialsClient.Delete", client.internal.Tracer(), nil) + const operationName = "AwsCredentialsClient.Delete" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.deleteCreateRequest(ctx, planeName, credentialName, options) if err != nil { @@ -150,7 +154,9 @@ func (client *AwsCredentialsClient) deleteCreateRequest(ctx context.Context, pla // - options - AwsCredentialsClientGetOptions contains the optional parameters for the AwsCredentialsClient.Get method. func (client *AwsCredentialsClient) Get(ctx context.Context, planeName string, credentialName string, options *AwsCredentialsClientGetOptions) (AwsCredentialsClientGetResponse, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "AwsCredentialsClient.Get", client.internal.Tracer(), nil) + const operationName = "AwsCredentialsClient.Get" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.getCreateRequest(ctx, planeName, credentialName, options) if err != nil { @@ -207,6 +213,7 @@ func (client *AwsCredentialsClient) NewListPager(planeName string, options *AwsC return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AwsCredentialsClientListResponse) (AwsCredentialsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AwsCredentialsClient.NewListPager") nextLink := "" if page != nil { nextLink = *page.NextLink @@ -257,7 +264,9 @@ func (client *AwsCredentialsClient) listHandleResponse(resp *http.Response) (Aws // - options - AwsCredentialsClientUpdateOptions contains the optional parameters for the AwsCredentialsClient.Update method. func (client *AwsCredentialsClient) Update(ctx context.Context, planeName string, credentialName string, properties AwsCredentialResourceTagsUpdate, options *AwsCredentialsClientUpdateOptions) (AwsCredentialsClientUpdateResponse, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "AwsCredentialsClient.Update", client.internal.Tracer(), nil) + const operationName = "AwsCredentialsClient.Update" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.updateCreateRequest(ctx, planeName, credentialName, properties, options) if err != nil { diff --git a/pkg/ucp/api/v20231001preview/zz_generated_awsplanes_client.go b/pkg/ucp/api/v20231001preview/zz_generated_awsplanes_client.go index df7b97bfb1..18444b3475 100644 --- a/pkg/ucp/api/v20231001preview/zz_generated_awsplanes_client.go +++ b/pkg/ucp/api/v20231001preview/zz_generated_awsplanes_client.go @@ -68,7 +68,9 @@ func (client *AwsPlanesClient) BeginCreateOrUpdate(ctx context.Context, planeNam // Generated from API version 2023-10-01-preview func (client *AwsPlanesClient) createOrUpdate(ctx context.Context, planeName string, resource AwsPlaneResource, options *AwsPlanesClientBeginCreateOrUpdateOptions) (*http.Response, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "AwsPlanesClient.BeginCreateOrUpdate", client.internal.Tracer(), nil) + const operationName = "AwsPlanesClient.BeginCreateOrUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.createOrUpdateCreateRequest(ctx, planeName, resource, options) if err != nil { @@ -136,7 +138,9 @@ func (client *AwsPlanesClient) BeginDelete(ctx context.Context, planeName string // Generated from API version 2023-10-01-preview func (client *AwsPlanesClient) deleteOperation(ctx context.Context, planeName string, options *AwsPlanesClientBeginDeleteOptions) (*http.Response, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "AwsPlanesClient.BeginDelete", client.internal.Tracer(), nil) + const operationName = "AwsPlanesClient.BeginDelete" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.deleteCreateRequest(ctx, planeName, options) if err != nil { @@ -179,7 +183,9 @@ func (client *AwsPlanesClient) deleteCreateRequest(ctx context.Context, planeNam // - options - AwsPlanesClientGetOptions contains the optional parameters for the AwsPlanesClient.Get method. func (client *AwsPlanesClient) Get(ctx context.Context, planeName string, options *AwsPlanesClientGetOptions) (AwsPlanesClientGetResponse, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "AwsPlanesClient.Get", client.internal.Tracer(), nil) + const operationName = "AwsPlanesClient.Get" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.getCreateRequest(ctx, planeName, options) if err != nil { @@ -234,6 +240,7 @@ func (client *AwsPlanesClient) NewListPager(options *AwsPlanesClientListOptions) return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AwsPlanesClientListResponse) (AwsPlanesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AwsPlanesClient.NewListPager") nextLink := "" if page != nil { nextLink = *page.NextLink @@ -304,7 +311,9 @@ func (client *AwsPlanesClient) BeginUpdate(ctx context.Context, planeName string // Generated from API version 2023-10-01-preview func (client *AwsPlanesClient) update(ctx context.Context, planeName string, properties AwsPlaneResourceTagsUpdate, options *AwsPlanesClientBeginUpdateOptions) (*http.Response, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "AwsPlanesClient.BeginUpdate", client.internal.Tracer(), nil) + const operationName = "AwsPlanesClient.BeginUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.updateCreateRequest(ctx, planeName, properties, options) if err != nil { diff --git a/pkg/ucp/api/v20231001preview/zz_generated_azurecredentials_client.go b/pkg/ucp/api/v20231001preview/zz_generated_azurecredentials_client.go index 7ff88801cc..10e95efd04 100644 --- a/pkg/ucp/api/v20231001preview/zz_generated_azurecredentials_client.go +++ b/pkg/ucp/api/v20231001preview/zz_generated_azurecredentials_client.go @@ -47,7 +47,9 @@ func NewAzureCredentialsClient(credential azcore.TokenCredential, options *arm.C // method. func (client *AzureCredentialsClient) CreateOrUpdate(ctx context.Context, planeName string, credentialName string, resource AzureCredentialResource, options *AzureCredentialsClientCreateOrUpdateOptions) (AzureCredentialsClientCreateOrUpdateResponse, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "AzureCredentialsClient.CreateOrUpdate", client.internal.Tracer(), nil) + const operationName = "AzureCredentialsClient.CreateOrUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.createOrUpdateCreateRequest(ctx, planeName, credentialName, resource, options) if err != nil { @@ -105,7 +107,9 @@ func (client *AzureCredentialsClient) createOrUpdateHandleResponse(resp *http.Re // - options - AzureCredentialsClientDeleteOptions contains the optional parameters for the AzureCredentialsClient.Delete method. func (client *AzureCredentialsClient) Delete(ctx context.Context, planeName string, credentialName string, options *AzureCredentialsClientDeleteOptions) (AzureCredentialsClientDeleteResponse, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "AzureCredentialsClient.Delete", client.internal.Tracer(), nil) + const operationName = "AzureCredentialsClient.Delete" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.deleteCreateRequest(ctx, planeName, credentialName, options) if err != nil { @@ -150,7 +154,9 @@ func (client *AzureCredentialsClient) deleteCreateRequest(ctx context.Context, p // - options - AzureCredentialsClientGetOptions contains the optional parameters for the AzureCredentialsClient.Get method. func (client *AzureCredentialsClient) Get(ctx context.Context, planeName string, credentialName string, options *AzureCredentialsClientGetOptions) (AzureCredentialsClientGetResponse, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "AzureCredentialsClient.Get", client.internal.Tracer(), nil) + const operationName = "AzureCredentialsClient.Get" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.getCreateRequest(ctx, planeName, credentialName, options) if err != nil { @@ -208,6 +214,7 @@ func (client *AzureCredentialsClient) NewListPager(planeName string, options *Az return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AzureCredentialsClientListResponse) (AzureCredentialsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AzureCredentialsClient.NewListPager") nextLink := "" if page != nil { nextLink = *page.NextLink @@ -258,7 +265,9 @@ func (client *AzureCredentialsClient) listHandleResponse(resp *http.Response) (A // - options - AzureCredentialsClientUpdateOptions contains the optional parameters for the AzureCredentialsClient.Update method. func (client *AzureCredentialsClient) Update(ctx context.Context, planeName string, credentialName string, properties AzureCredentialResourceTagsUpdate, options *AzureCredentialsClientUpdateOptions) (AzureCredentialsClientUpdateResponse, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "AzureCredentialsClient.Update", client.internal.Tracer(), nil) + const operationName = "AzureCredentialsClient.Update" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.updateCreateRequest(ctx, planeName, credentialName, properties, options) if err != nil { diff --git a/pkg/ucp/api/v20231001preview/zz_generated_azureplanes_client.go b/pkg/ucp/api/v20231001preview/zz_generated_azureplanes_client.go index f638c3c23a..aa247ba136 100644 --- a/pkg/ucp/api/v20231001preview/zz_generated_azureplanes_client.go +++ b/pkg/ucp/api/v20231001preview/zz_generated_azureplanes_client.go @@ -68,7 +68,9 @@ func (client *AzurePlanesClient) BeginCreateOrUpdate(ctx context.Context, planeN // Generated from API version 2023-10-01-preview func (client *AzurePlanesClient) createOrUpdate(ctx context.Context, planeName string, resource AzurePlaneResource, options *AzurePlanesClientBeginCreateOrUpdateOptions) (*http.Response, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "AzurePlanesClient.BeginCreateOrUpdate", client.internal.Tracer(), nil) + const operationName = "AzurePlanesClient.BeginCreateOrUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.createOrUpdateCreateRequest(ctx, planeName, resource, options) if err != nil { @@ -136,7 +138,9 @@ func (client *AzurePlanesClient) BeginDelete(ctx context.Context, planeName stri // Generated from API version 2023-10-01-preview func (client *AzurePlanesClient) deleteOperation(ctx context.Context, planeName string, options *AzurePlanesClientBeginDeleteOptions) (*http.Response, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "AzurePlanesClient.BeginDelete", client.internal.Tracer(), nil) + const operationName = "AzurePlanesClient.BeginDelete" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.deleteCreateRequest(ctx, planeName, options) if err != nil { @@ -179,7 +183,9 @@ func (client *AzurePlanesClient) deleteCreateRequest(ctx context.Context, planeN // - options - AzurePlanesClientGetOptions contains the optional parameters for the AzurePlanesClient.Get method. func (client *AzurePlanesClient) Get(ctx context.Context, planeName string, options *AzurePlanesClientGetOptions) (AzurePlanesClientGetResponse, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "AzurePlanesClient.Get", client.internal.Tracer(), nil) + const operationName = "AzurePlanesClient.Get" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.getCreateRequest(ctx, planeName, options) if err != nil { @@ -234,6 +240,7 @@ func (client *AzurePlanesClient) NewListPager(options *AzurePlanesClientListOpti return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *AzurePlanesClientListResponse) (AzurePlanesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "AzurePlanesClient.NewListPager") nextLink := "" if page != nil { nextLink = *page.NextLink @@ -304,7 +311,9 @@ func (client *AzurePlanesClient) BeginUpdate(ctx context.Context, planeName stri // Generated from API version 2023-10-01-preview func (client *AzurePlanesClient) update(ctx context.Context, planeName string, properties AzurePlaneResourceTagsUpdate, options *AzurePlanesClientBeginUpdateOptions) (*http.Response, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "AzurePlanesClient.BeginUpdate", client.internal.Tracer(), nil) + const operationName = "AzurePlanesClient.BeginUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.updateCreateRequest(ctx, planeName, properties, options) if err != nil { diff --git a/pkg/ucp/api/v20231001preview/zz_generated_locations_client.go b/pkg/ucp/api/v20231001preview/zz_generated_locations_client.go index ae865967fa..69cd3764d6 100644 --- a/pkg/ucp/api/v20231001preview/zz_generated_locations_client.go +++ b/pkg/ucp/api/v20231001preview/zz_generated_locations_client.go @@ -72,7 +72,9 @@ func (client *LocationsClient) BeginCreateOrUpdate(ctx context.Context, planeNam // Generated from API version 2023-10-01-preview func (client *LocationsClient) createOrUpdate(ctx context.Context, planeName string, resourceProviderName string, locationName string, resource LocationResource, options *LocationsClientBeginCreateOrUpdateOptions) (*http.Response, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "LocationsClient.BeginCreateOrUpdate", client.internal.Tracer(), nil) + const operationName = "LocationsClient.BeginCreateOrUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.createOrUpdateCreateRequest(ctx, planeName, resourceProviderName, locationName, resource, options) if err != nil { @@ -150,7 +152,9 @@ func (client *LocationsClient) BeginDelete(ctx context.Context, planeName string // Generated from API version 2023-10-01-preview func (client *LocationsClient) deleteOperation(ctx context.Context, planeName string, resourceProviderName string, locationName string, options *LocationsClientBeginDeleteOptions) (*http.Response, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "LocationsClient.BeginDelete", client.internal.Tracer(), nil) + const operationName = "LocationsClient.BeginDelete" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.deleteCreateRequest(ctx, planeName, resourceProviderName, locationName, options) if err != nil { @@ -203,7 +207,9 @@ func (client *LocationsClient) deleteCreateRequest(ctx context.Context, planeNam // - options - LocationsClientGetOptions contains the optional parameters for the LocationsClient.Get method. func (client *LocationsClient) Get(ctx context.Context, planeName string, resourceProviderName string, locationName string, options *LocationsClientGetOptions) (LocationsClientGetResponse, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "LocationsClient.Get", client.internal.Tracer(), nil) + const operationName = "LocationsClient.Get" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.getCreateRequest(ctx, planeName, resourceProviderName, locationName, options) if err != nil { @@ -268,6 +274,7 @@ func (client *LocationsClient) NewListPager(planeName string, resourceProviderNa return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *LocationsClientListResponse) (LocationsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "LocationsClient.NewListPager") nextLink := "" if page != nil { nextLink = *page.NextLink diff --git a/pkg/ucp/api/v20231001preview/zz_generated_planes_client.go b/pkg/ucp/api/v20231001preview/zz_generated_planes_client.go index b98b126a9e..3b17a63a8f 100644 --- a/pkg/ucp/api/v20231001preview/zz_generated_planes_client.go +++ b/pkg/ucp/api/v20231001preview/zz_generated_planes_client.go @@ -43,6 +43,7 @@ func (client *PlanesClient) NewListPlanesPager(options *PlanesClientListPlanesOp return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *PlanesClientListPlanesResponse) (PlanesClientListPlanesResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PlanesClient.NewListPlanesPager") nextLink := "" if page != nil { nextLink = *page.NextLink diff --git a/pkg/ucp/api/v20231001preview/zz_generated_radiusplanes_client.go b/pkg/ucp/api/v20231001preview/zz_generated_radiusplanes_client.go index 4c7910001b..cc2b4d362f 100644 --- a/pkg/ucp/api/v20231001preview/zz_generated_radiusplanes_client.go +++ b/pkg/ucp/api/v20231001preview/zz_generated_radiusplanes_client.go @@ -68,7 +68,9 @@ func (client *RadiusPlanesClient) BeginCreateOrUpdate(ctx context.Context, plane // Generated from API version 2023-10-01-preview func (client *RadiusPlanesClient) createOrUpdate(ctx context.Context, planeName string, resource RadiusPlaneResource, options *RadiusPlanesClientBeginCreateOrUpdateOptions) (*http.Response, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "RadiusPlanesClient.BeginCreateOrUpdate", client.internal.Tracer(), nil) + const operationName = "RadiusPlanesClient.BeginCreateOrUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.createOrUpdateCreateRequest(ctx, planeName, resource, options) if err != nil { @@ -137,7 +139,9 @@ func (client *RadiusPlanesClient) BeginDelete(ctx context.Context, planeName str // Generated from API version 2023-10-01-preview func (client *RadiusPlanesClient) deleteOperation(ctx context.Context, planeName string, options *RadiusPlanesClientBeginDeleteOptions) (*http.Response, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "RadiusPlanesClient.BeginDelete", client.internal.Tracer(), nil) + const operationName = "RadiusPlanesClient.BeginDelete" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.deleteCreateRequest(ctx, planeName, options) if err != nil { @@ -180,7 +184,9 @@ func (client *RadiusPlanesClient) deleteCreateRequest(ctx context.Context, plane // - options - RadiusPlanesClientGetOptions contains the optional parameters for the RadiusPlanesClient.Get method. func (client *RadiusPlanesClient) Get(ctx context.Context, planeName string, options *RadiusPlanesClientGetOptions) (RadiusPlanesClientGetResponse, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "RadiusPlanesClient.Get", client.internal.Tracer(), nil) + const operationName = "RadiusPlanesClient.Get" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.getCreateRequest(ctx, planeName, options) if err != nil { @@ -235,6 +241,7 @@ func (client *RadiusPlanesClient) NewListPager(options *RadiusPlanesClientListOp return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *RadiusPlanesClientListResponse) (RadiusPlanesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "RadiusPlanesClient.NewListPager") nextLink := "" if page != nil { nextLink = *page.NextLink @@ -306,7 +313,9 @@ func (client *RadiusPlanesClient) BeginUpdate(ctx context.Context, planeName str // Generated from API version 2023-10-01-preview func (client *RadiusPlanesClient) update(ctx context.Context, planeName string, properties RadiusPlaneResourceTagsUpdate, options *RadiusPlanesClientBeginUpdateOptions) (*http.Response, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "RadiusPlanesClient.BeginUpdate", client.internal.Tracer(), nil) + const operationName = "RadiusPlanesClient.BeginUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.updateCreateRequest(ctx, planeName, properties, options) if err != nil { diff --git a/pkg/ucp/api/v20231001preview/zz_generated_resourcegroups_client.go b/pkg/ucp/api/v20231001preview/zz_generated_resourcegroups_client.go index d15214b035..04d4d452e6 100644 --- a/pkg/ucp/api/v20231001preview/zz_generated_resourcegroups_client.go +++ b/pkg/ucp/api/v20231001preview/zz_generated_resourcegroups_client.go @@ -47,7 +47,9 @@ func NewResourceGroupsClient(credential azcore.TokenCredential, options *arm.Cli // method. func (client *ResourceGroupsClient) CreateOrUpdate(ctx context.Context, planeName string, resourceGroupName string, resource ResourceGroupResource, options *ResourceGroupsClientCreateOrUpdateOptions) (ResourceGroupsClientCreateOrUpdateResponse, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "ResourceGroupsClient.CreateOrUpdate", client.internal.Tracer(), nil) + const operationName = "ResourceGroupsClient.CreateOrUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.createOrUpdateCreateRequest(ctx, planeName, resourceGroupName, resource, options) if err != nil { @@ -108,7 +110,9 @@ func (client *ResourceGroupsClient) createOrUpdateHandleResponse(resp *http.Resp // - options - ResourceGroupsClientDeleteOptions contains the optional parameters for the ResourceGroupsClient.Delete method. func (client *ResourceGroupsClient) Delete(ctx context.Context, planeName string, resourceGroupName string, options *ResourceGroupsClientDeleteOptions) (ResourceGroupsClientDeleteResponse, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "ResourceGroupsClient.Delete", client.internal.Tracer(), nil) + const operationName = "ResourceGroupsClient.Delete" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.deleteCreateRequest(ctx, planeName, resourceGroupName, options) if err != nil { @@ -156,7 +160,9 @@ func (client *ResourceGroupsClient) deleteCreateRequest(ctx context.Context, pla // - options - ResourceGroupsClientGetOptions contains the optional parameters for the ResourceGroupsClient.Get method. func (client *ResourceGroupsClient) Get(ctx context.Context, planeName string, resourceGroupName string, options *ResourceGroupsClientGetOptions) (ResourceGroupsClientGetResponse, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "ResourceGroupsClient.Get", client.internal.Tracer(), nil) + const operationName = "ResourceGroupsClient.Get" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.getCreateRequest(ctx, planeName, resourceGroupName, options) if err != nil { @@ -216,6 +222,7 @@ func (client *ResourceGroupsClient) NewListPager(planeName string, options *Reso return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ResourceGroupsClientListResponse) (ResourceGroupsClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ResourceGroupsClient.NewListPager") nextLink := "" if page != nil { nextLink = *page.NextLink @@ -269,7 +276,9 @@ func (client *ResourceGroupsClient) listHandleResponse(resp *http.Response) (Res // - options - ResourceGroupsClientUpdateOptions contains the optional parameters for the ResourceGroupsClient.Update method. func (client *ResourceGroupsClient) Update(ctx context.Context, planeName string, resourceGroupName string, properties ResourceGroupResourceTagsUpdate, options *ResourceGroupsClientUpdateOptions) (ResourceGroupsClientUpdateResponse, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "ResourceGroupsClient.Update", client.internal.Tracer(), nil) + const operationName = "ResourceGroupsClient.Update" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.updateCreateRequest(ctx, planeName, resourceGroupName, properties, options) if err != nil { diff --git a/pkg/ucp/api/v20231001preview/zz_generated_resourceproviders_client.go b/pkg/ucp/api/v20231001preview/zz_generated_resourceproviders_client.go index 1f69e27e93..964c587bb8 100644 --- a/pkg/ucp/api/v20231001preview/zz_generated_resourceproviders_client.go +++ b/pkg/ucp/api/v20231001preview/zz_generated_resourceproviders_client.go @@ -69,7 +69,9 @@ func (client *ResourceProvidersClient) BeginCreateOrUpdate(ctx context.Context, // Generated from API version 2023-10-01-preview func (client *ResourceProvidersClient) createOrUpdate(ctx context.Context, planeName string, resourceProviderName string, resource ResourceProviderResource, options *ResourceProvidersClientBeginCreateOrUpdateOptions) (*http.Response, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "ResourceProvidersClient.BeginCreateOrUpdate", client.internal.Tracer(), nil) + const operationName = "ResourceProvidersClient.BeginCreateOrUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.createOrUpdateCreateRequest(ctx, planeName, resourceProviderName, resource, options) if err != nil { @@ -143,7 +145,9 @@ func (client *ResourceProvidersClient) BeginDelete(ctx context.Context, planeNam // Generated from API version 2023-10-01-preview func (client *ResourceProvidersClient) deleteOperation(ctx context.Context, planeName string, resourceProviderName string, options *ResourceProvidersClientBeginDeleteOptions) (*http.Response, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "ResourceProvidersClient.BeginDelete", client.internal.Tracer(), nil) + const operationName = "ResourceProvidersClient.BeginDelete" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.deleteCreateRequest(ctx, planeName, resourceProviderName, options) if err != nil { @@ -191,7 +195,9 @@ func (client *ResourceProvidersClient) deleteCreateRequest(ctx context.Context, // - options - ResourceProvidersClientGetOptions contains the optional parameters for the ResourceProvidersClient.Get method. func (client *ResourceProvidersClient) Get(ctx context.Context, planeName string, resourceProviderName string, options *ResourceProvidersClientGetOptions) (ResourceProvidersClientGetResponse, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "ResourceProvidersClient.Get", client.internal.Tracer(), nil) + const operationName = "ResourceProvidersClient.Get" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.getCreateRequest(ctx, planeName, resourceProviderName, options) if err != nil { @@ -251,7 +257,9 @@ func (client *ResourceProvidersClient) getHandleResponse(resp *http.Response) (R // method. func (client *ResourceProvidersClient) GetProviderSummary(ctx context.Context, planeName string, resourceProviderName string, options *ResourceProvidersClientGetProviderSummaryOptions) (ResourceProvidersClientGetProviderSummaryResponse, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "ResourceProvidersClient.GetProviderSummary", client.internal.Tracer(), nil) + const operationName = "ResourceProvidersClient.GetProviderSummary" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.getProviderSummaryCreateRequest(ctx, planeName, resourceProviderName, options) if err != nil { @@ -312,6 +320,7 @@ func (client *ResourceProvidersClient) NewListPager(planeName string, options *R return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ResourceProvidersClientListResponse) (ResourceProvidersClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ResourceProvidersClient.NewListPager") nextLink := "" if page != nil { nextLink = *page.NextLink @@ -368,6 +377,7 @@ func (client *ResourceProvidersClient) NewListProviderSummariesPager(planeName s return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ResourceProvidersClientListProviderSummariesResponse) (ResourceProvidersClientListProviderSummariesResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ResourceProvidersClient.NewListProviderSummariesPager") nextLink := "" if page != nil { nextLink = *page.NextLink diff --git a/pkg/ucp/api/v20231001preview/zz_generated_resources_client.go b/pkg/ucp/api/v20231001preview/zz_generated_resources_client.go index 5f7ad29ca7..6c331970ad 100644 --- a/pkg/ucp/api/v20231001preview/zz_generated_resources_client.go +++ b/pkg/ucp/api/v20231001preview/zz_generated_resources_client.go @@ -48,6 +48,7 @@ func (client *ResourcesClient) NewListPager(planeName string, resourceGroupName return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ResourcesClientListResponse) (ResourcesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ResourcesClient.NewListPager") nextLink := "" if page != nil { nextLink = *page.NextLink diff --git a/pkg/ucp/api/v20231001preview/zz_generated_resourcetypes_client.go b/pkg/ucp/api/v20231001preview/zz_generated_resourcetypes_client.go index c781373331..d3dba9d47d 100644 --- a/pkg/ucp/api/v20231001preview/zz_generated_resourcetypes_client.go +++ b/pkg/ucp/api/v20231001preview/zz_generated_resourcetypes_client.go @@ -70,7 +70,9 @@ func (client *ResourceTypesClient) BeginCreateOrUpdate(ctx context.Context, plan // Generated from API version 2023-10-01-preview func (client *ResourceTypesClient) createOrUpdate(ctx context.Context, planeName string, resourceProviderName string, resourceTypeName string, resource ResourceTypeResource, options *ResourceTypesClientBeginCreateOrUpdateOptions) (*http.Response, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "ResourceTypesClient.BeginCreateOrUpdate", client.internal.Tracer(), nil) + const operationName = "ResourceTypesClient.BeginCreateOrUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.createOrUpdateCreateRequest(ctx, planeName, resourceProviderName, resourceTypeName, resource, options) if err != nil { @@ -149,7 +151,9 @@ func (client *ResourceTypesClient) BeginDelete(ctx context.Context, planeName st // Generated from API version 2023-10-01-preview func (client *ResourceTypesClient) deleteOperation(ctx context.Context, planeName string, resourceProviderName string, resourceTypeName string, options *ResourceTypesClientBeginDeleteOptions) (*http.Response, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "ResourceTypesClient.BeginDelete", client.internal.Tracer(), nil) + const operationName = "ResourceTypesClient.BeginDelete" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.deleteCreateRequest(ctx, planeName, resourceProviderName, resourceTypeName, options) if err != nil { @@ -202,7 +206,9 @@ func (client *ResourceTypesClient) deleteCreateRequest(ctx context.Context, plan // - options - ResourceTypesClientGetOptions contains the optional parameters for the ResourceTypesClient.Get method. func (client *ResourceTypesClient) Get(ctx context.Context, planeName string, resourceProviderName string, resourceTypeName string, options *ResourceTypesClientGetOptions) (ResourceTypesClientGetResponse, error) { var err error - ctx, endSpan := runtime.StartSpan(ctx, "ResourceTypesClient.Get", client.internal.Tracer(), nil) + const operationName = "ResourceTypesClient.Get" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) defer func() { endSpan(err) }() req, err := client.getCreateRequest(ctx, planeName, resourceProviderName, resourceTypeName, options) if err != nil { @@ -267,6 +273,7 @@ func (client *ResourceTypesClient) NewListPager(planeName string, resourceProvid return page.NextLink != nil && len(*page.NextLink) > 0 }, Fetcher: func(ctx context.Context, page *ResourceTypesClientListResponse) (ResourceTypesClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ResourceTypesClient.NewListPager") nextLink := "" if page != nil { nextLink = *page.NextLink diff --git a/pkg/ucp/config.go b/pkg/ucp/config.go index 7ef4a8ff56..e6f64921d5 100644 --- a/pkg/ucp/config.go +++ b/pkg/ucp/config.go @@ -108,6 +108,9 @@ type RoutingConfig struct { type InitializationConfig struct { // Planes is a list of planes to create at startup. Planes []Plane `yaml:"planes,omitempty"` + + // ManifestDirectory is the directory which contains manifests. + ManifestDirectory string `yaml:"manifestDirectory"` } // Plane is a configuration entry for a plane resource. This is used to create a plane resource at startup. @@ -125,6 +128,7 @@ type Plane struct { Properties PlaneProperties `json:"properties" yaml:"properties"` } +// PlaneProperties represents the properties of a plane resource. type PlaneProperties struct { // ResourceProviders is a map of resource provider namespaces to their respective addresses. // diff --git a/pkg/ucp/initializer/service.go b/pkg/ucp/initializer/service.go new file mode 100644 index 0000000000..5c53685ae3 --- /dev/null +++ b/pkg/ucp/initializer/service.go @@ -0,0 +1,136 @@ +/* +Copyright 2023 The Radius Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package initializer + +import ( + "context" + "fmt" + "net" + "net/url" + "os" + "time" + + aztoken "github.com/radius-project/radius/pkg/azure/tokencredentials" + "github.com/radius-project/radius/pkg/cli/manifest" + "github.com/radius-project/radius/pkg/sdk" + "github.com/radius-project/radius/pkg/ucp" + "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" + "github.com/radius-project/radius/pkg/ucp/hosting" + + //ucpoptions "github.com/radius-project/radius/pkg/ucp/hostoptions" + "github.com/radius-project/radius/pkg/ucp/ucplog" +) + +// Service implements the hosting.Service interface for registering manifests. +type Service struct { + options *ucp.Options +} + +var _ hosting.Service = (*Service)(nil) + +// NewService creates a server to register manifests. +func NewService(options *ucp.Options) *Service { + return &Service{ + options: options, + } +} + +// Name gets this service name. +func (s *Service) Name() string { + return "initializer" +} + +func waitForServer(ctx context.Context, host, port string, retryInterval time.Duration, connectionTimeout time.Duration, timeout time.Duration) error { + address := net.JoinHostPort(host, port) + deadline := time.Now().Add(timeout) + + for { + select { + case <-ctx.Done(): + return fmt.Errorf("connection attempts canceled or timed out: %w", ctx.Err()) + default: + conn, err := net.DialTimeout("tcp", address, connectionTimeout) + if err == nil { + conn.Close() + return nil + } + + if time.Now().After(deadline) { + return fmt.Errorf("failed to connect to %s after %v: %w", address, timeout, err) + } + + time.Sleep(retryInterval) + } + } +} + +func (w *Service) Run(ctx context.Context) error { + logger := ucplog.FromContextOrDiscard(ctx) + + manifestDir := w.options.Config.Initialization.ManifestDirectory + if manifestDir == "" { + logger.Info("No manifest directory specified, initialization is complete") + return nil + } + + if _, err := os.Stat(manifestDir); os.IsNotExist(err) { + return fmt.Errorf("manifest directory does not exist: %w", err) + } else if err != nil { + return fmt.Errorf("error checking manifest directory: %w", err) + } + + if w.options.UCP == nil || w.options.UCP.Endpoint() == "" { + return fmt.Errorf("connection to UCP is not set") + } + + // Parse the endpoint URL and extract host and port + parsedURL, err := url.Parse(w.options.UCP.Endpoint()) + if err != nil { + return fmt.Errorf("failed to parse endpoint URL: %w", err) + } + + hostName, port, err := net.SplitHostPort(parsedURL.Host) + if err != nil { + return fmt.Errorf("failed to split host and port: %w", err) + } + + // Attempt to connect to the server + err = waitForServer(ctx, hostName, port, 500*time.Millisecond, 500*time.Millisecond, 5*time.Second) + if err != nil { + return fmt.Errorf("failed to connect to server : %w", err) + } + + // Server is up, proceed to register manifests + clientOptions := sdk.NewClientOptions(w.options.UCP) + + clientFactory, err := v20231001preview.NewClientFactory(&aztoken.AnonymousCredential{}, clientOptions) + if err != nil { + return fmt.Errorf("error creating client factory: %w", err) + } + + loggerFunc := func(format string, args ...any) { + logger.Info(fmt.Sprintf(format, args...)) + } + + if err := manifest.RegisterDirectory(ctx, clientFactory, "local", manifestDir, loggerFunc); err != nil { + return fmt.Errorf("error registering manifests : %w", err) + } + + logger.Info("Successfully registered manifests", "directory", manifestDir) + + return nil +} diff --git a/pkg/ucp/integrationtests/resourceproviders/resourceproviders_test.go b/pkg/ucp/integrationtests/resourceproviders/resourceproviders_test.go index 7ad93f4096..a44b6fcd1d 100644 --- a/pkg/ucp/integrationtests/resourceproviders/resourceproviders_test.go +++ b/pkg/ucp/integrationtests/resourceproviders/resourceproviders_test.go @@ -19,7 +19,9 @@ package resourceproviders import ( "net/http" "testing" + "time" + "github.com/radius-project/radius/pkg/ucp" "github.com/radius-project/radius/pkg/ucp/testhost" "github.com/stretchr/testify/require" ) @@ -27,6 +29,14 @@ import ( const ( resourceProviderEmptyListResponseFixture = "testdata/resourceprovider_v20231001preview_emptylist_responsebody.json" resourceProviderListResponseFixture = "testdata/resourceprovider_v20231001preview_list_responsebody.json" + + manifestResourceProviderListResponseFixture = "testdata/resourceprovider_manifest_list_responsebody.json" + manifestResourceProviderResponseFixture = "testdata/resourceprovider_manifest_responsebody.json" + + manifestResourceTypeListResponseFixture = "testdata/resourcetype_manifest_list_responsebody.json" + + registerManifestWaitDuration = 30 * time.Second + registerManifestWaitInterval = 3 * time.Second ) func Test_ResourceProvider_Lifecycle(t *testing.T) { @@ -87,3 +97,31 @@ func Test_ResourceProvider_CascadingDelete(t *testing.T) { response.EqualsErrorCode(404, "NotFound") require.Equal(t, locationID, response.Error.Error.Target) } + +func Test_ResourceProvider_RegisterManifests(t *testing.T) { + server := testhost.Start(t, testhost.TestHostOptionFunc(func(options *ucp.Options) { + options.Config.Initialization.ManifestDirectory = "testdata/manifests" + })) + defer server.Close() + + createRadiusPlane(server) + + require.Eventuallyf(t, func() bool { + // Responses should contain the resource provider and resource type in the manifest + response := server.MakeRequest(http.MethodGet, manifestResourceProviderCollectionURL, nil) + response.EqualsFixture(200, manifestResourceProviderListResponseFixture) + + response = server.MakeRequest(http.MethodGet, manifestResourceProviderURL, nil) + response.EqualsFixture(200, manifestResourceProviderResponseFixture) + + response = server.MakeRequest(http.MethodGet, manifestResourceTypeCollectionURL, nil) + response.EqualsFixture(200, manifestResourceTypeListResponseFixture) + + response = server.MakeRequest(http.MethodGet, manifestResourceTypeURL, nil) + response.EqualsFixture(200, manifestResourceTypeResponseFixture) + + deleteManifestResourceProvider(server) + + return true + }, registerManifestWaitDuration, registerManifestWaitInterval, "manifest registration did not complete in time") +} diff --git a/pkg/ucp/integrationtests/resourceproviders/testdata/manifests/resourceprovider-valid1.yaml b/pkg/ucp/integrationtests/resourceproviders/testdata/manifests/resourceprovider-valid1.yaml new file mode 100644 index 0000000000..2d7d03ca75 --- /dev/null +++ b/pkg/ucp/integrationtests/resourceproviders/testdata/manifests/resourceprovider-valid1.yaml @@ -0,0 +1,7 @@ +name: TestProvider.TestCompany +types: + testResourcesAbc: + apiVersions: + "2023-10-01-preview": + schema: {} + capabilities: [] diff --git a/pkg/ucp/integrationtests/resourceproviders/testdata/resourceprovider_manifest_list_responsebody.json b/pkg/ucp/integrationtests/resourceproviders/testdata/resourceprovider_manifest_list_responsebody.json new file mode 100644 index 0000000000..e195fb5706 --- /dev/null +++ b/pkg/ucp/integrationtests/resourceproviders/testdata/resourceprovider_manifest_list_responsebody.json @@ -0,0 +1,14 @@ +{ + "value": [ + { + "id": "/planes/radius/local/providers/System.Resources/resourceproviders/TestProvider.TestCompany", + "location": "global", + "name": "TestProvider.TestCompany", + "properties": { + "provisioningState": "Succeeded" + }, + "tags": {}, + "type": "System.Resources/resourceproviders" + } + ] +} diff --git a/pkg/ucp/integrationtests/resourceproviders/testdata/resourceprovider_manifest_requestbody.json b/pkg/ucp/integrationtests/resourceproviders/testdata/resourceprovider_manifest_requestbody.json new file mode 100644 index 0000000000..a3aab8e0f6 --- /dev/null +++ b/pkg/ucp/integrationtests/resourceproviders/testdata/resourceprovider_manifest_requestbody.json @@ -0,0 +1,5 @@ +{ + "location": "global", + "tags": {}, + "properties": {} +} diff --git a/pkg/ucp/integrationtests/resourceproviders/testdata/resourceprovider_manifest_responsebody.json b/pkg/ucp/integrationtests/resourceproviders/testdata/resourceprovider_manifest_responsebody.json new file mode 100644 index 0000000000..c8e010d3a9 --- /dev/null +++ b/pkg/ucp/integrationtests/resourceproviders/testdata/resourceprovider_manifest_responsebody.json @@ -0,0 +1,10 @@ +{ + "id": "/planes/radius/local/providers/System.Resources/resourceproviders/TestProvider.TestCompany", + "location": "global", + "name": "TestProvider.TestCompany", + "properties": { + "provisioningState": "Succeeded" + }, + "tags": {}, + "type": "System.Resources/resourceproviders" +} diff --git a/pkg/ucp/integrationtests/resourceproviders/testdata/resourcetype_manifest_list_responsebody.json b/pkg/ucp/integrationtests/resourceproviders/testdata/resourcetype_manifest_list_responsebody.json new file mode 100644 index 0000000000..765c7f29cd --- /dev/null +++ b/pkg/ucp/integrationtests/resourceproviders/testdata/resourcetype_manifest_list_responsebody.json @@ -0,0 +1,12 @@ +{ + "value": [ + { + "id": "/planes/radius/local/providers/System.Resources/resourceproviders/TestProvider.TestCompany/resourcetypes/testResourcesAbc", + "name": "testResourcesAbc", + "properties": { + "provisioningState": "Succeeded" + }, + "type": "System.Resources/resourceproviders/resourcetypes" + } + ] +} diff --git a/pkg/ucp/integrationtests/resourceproviders/testdata/resourcetype_manifest_requestbody.json b/pkg/ucp/integrationtests/resourceproviders/testdata/resourcetype_manifest_requestbody.json new file mode 100644 index 0000000000..b4924988b0 --- /dev/null +++ b/pkg/ucp/integrationtests/resourceproviders/testdata/resourcetype_manifest_requestbody.json @@ -0,0 +1,5 @@ +{ + "properties": { + "defaultApiVersion": "2023-10-01" + } +} diff --git a/pkg/ucp/integrationtests/resourceproviders/testdata/resourcetype_manifest_responsebody.json b/pkg/ucp/integrationtests/resourceproviders/testdata/resourcetype_manifest_responsebody.json new file mode 100644 index 0000000000..e4bd9c9e25 --- /dev/null +++ b/pkg/ucp/integrationtests/resourceproviders/testdata/resourcetype_manifest_responsebody.json @@ -0,0 +1,8 @@ +{ + "id": "/planes/radius/local/providers/System.Resources/resourceproviders/TestProvider.TestCompany/resourcetypes/testResourcesAbc", + "name": "testResourcesAbc", + "properties": { + "provisioningState": "Succeeded" + }, + "type": "System.Resources/resourceproviders/resourcetypes" +} diff --git a/pkg/ucp/integrationtests/resourceproviders/util_test.go b/pkg/ucp/integrationtests/resourceproviders/util_test.go index 3378a8281a..79af09a374 100644 --- a/pkg/ucp/integrationtests/resourceproviders/util_test.go +++ b/pkg/ucp/integrationtests/resourceproviders/util_test.go @@ -54,6 +54,18 @@ const ( resourceProviderSummaryCollectionURL = "/planes/radius/local/providers" + radiusAPIVersion resourceProviderSummaryURL = "/planes/radius/local/providers/" + resourceProviderNamespace + radiusAPIVersion + + manifestNamespace = "TestProvider.TestCompany" + manifestResourceProviderID = "/planes/radius/local/providers/System.Resources/resourceproviders/" + manifestNamespace + manifestResourceProviderCollectionURL = "/planes/radius/local/providers/System.Resources/resourceproviders" + radiusAPIVersion + manifestResourceProviderURL = manifestResourceProviderID + radiusAPIVersion + + manifestResourceTypeName1 = "testResourcesAbc" + manifestResourceTypeID = manifestResourceProviderID + "/resourcetypes/" + manifestResourceTypeName1 + manifestResourceTypeCollectionURL = manifestResourceProviderID + "/resourcetypes" + radiusAPIVersion + manifestResourceTypeURL = manifestResourceTypeID + radiusAPIVersion + manifestResourceTypeRequestFixture = "testdata/resourcetype_manifest_requestbody.json" + manifestResourceTypeResponseFixture = "testdata/resourcetype_manifest_responsebody.json" ) func createRadiusPlane(server *testhost.TestHost) { @@ -80,6 +92,14 @@ func deleteResourceProvider(server *testhost.TestHost) { response.EqualsStatusCode(404) } +func deleteManifestResourceProvider(server *testhost.TestHost) { + response := server.MakeRequest("DELETE", manifestResourceProviderURL, nil) + response.WaitForOperationComplete(nil) + + response = server.MakeRequest("GET", manifestResourceProviderURL, nil) + response.EqualsStatusCode(404) +} + func createResourceType(server *testhost.TestHost) { response := server.MakeFixtureRequest("PUT", resourceTypeURL, resourceTypeRequestFixture) response.WaitForOperationComplete(nil) diff --git a/pkg/ucp/server/server.go b/pkg/ucp/server/server.go index b7d3edc03f..b99d9009db 100644 --- a/pkg/ucp/server/server.go +++ b/pkg/ucp/server/server.go @@ -24,6 +24,7 @@ import ( "github.com/radius-project/radius/pkg/ucp/backend" "github.com/radius-project/radius/pkg/ucp/frontend/api" "github.com/radius-project/radius/pkg/ucp/hosting" + "github.com/radius-project/radius/pkg/ucp/initializer" ) // NewServer initializes a host for UCP based on the provided options. @@ -49,6 +50,8 @@ func NewServer(options *ucp.Options) (*hosting.Host, error) { hostingServices = append(hostingServices, &trace.Service{Options: options.Config.Tracing}) + hostingServices = append(hostingServices, initializer.NewService(options)) + return &hosting.Host{ Services: hostingServices, }, nil diff --git a/test/rp/rptest.go b/test/rp/rptest.go index 21dc72d435..5a05099002 100644 --- a/test/rp/rptest.go +++ b/test/rp/rptest.go @@ -174,7 +174,7 @@ func NewRPTestOptions(t *testing.T) RPTestOptions { client, err := connections.DefaultFactory.CreateApplicationsManagementClient(ctx, *workspace) require.NoError(t, err, "failed to create ApplicationsManagementClient") - connection, err := workspace.Connect() + connection, err := workspace.Connect(ctx) require.NoError(t, err, "failed to connect to workspace") customAction, err := clientv2.NewCustomActionClient("", &clientv2.Options{