sdk/resourcemanager/apimanagement/armapimanagement/workspaceapidiagnostic_client.go (430 lines of code) (raw):
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project 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 armapimanagement
import (
"context"
"errors"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"net/http"
"net/url"
"strconv"
"strings"
)
// WorkspaceAPIDiagnosticClient contains the methods for the WorkspaceAPIDiagnostic group.
// Don't use this type directly, use NewWorkspaceAPIDiagnosticClient() instead.
type WorkspaceAPIDiagnosticClient struct {
internal *arm.Client
subscriptionID string
}
// NewWorkspaceAPIDiagnosticClient creates a new instance of WorkspaceAPIDiagnosticClient with the specified values.
// - subscriptionID - The ID of the target subscription. The value must be an UUID.
// - credential - used to authorize requests. Usually a credential from azidentity.
// - options - pass nil to accept the default values.
func NewWorkspaceAPIDiagnosticClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*WorkspaceAPIDiagnosticClient, error) {
cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
if err != nil {
return nil, err
}
client := &WorkspaceAPIDiagnosticClient{
subscriptionID: subscriptionID,
internal: cl,
}
return client, nil
}
// CreateOrUpdate - Creates a new Diagnostic for an API or updates an existing one.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-05-01
// - resourceGroupName - The name of the resource group. The name is case insensitive.
// - serviceName - The name of the API Management service.
// - workspaceID - Workspace identifier. Must be unique in the current API Management service instance.
// - apiID - API identifier. Must be unique in the current API Management service instance.
// - diagnosticID - Diagnostic identifier. Must be unique in the current API Management service instance.
// - parameters - Create parameters.
// - options - WorkspaceAPIDiagnosticClientCreateOrUpdateOptions contains the optional parameters for the WorkspaceAPIDiagnosticClient.CreateOrUpdate
// method.
func (client *WorkspaceAPIDiagnosticClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, workspaceID string, apiID string, diagnosticID string, parameters DiagnosticContract, options *WorkspaceAPIDiagnosticClientCreateOrUpdateOptions) (WorkspaceAPIDiagnosticClientCreateOrUpdateResponse, error) {
var err error
const operationName = "WorkspaceAPIDiagnosticClient.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, resourceGroupName, serviceName, workspaceID, apiID, diagnosticID, parameters, options)
if err != nil {
return WorkspaceAPIDiagnosticClientCreateOrUpdateResponse{}, err
}
httpResp, err := client.internal.Pipeline().Do(req)
if err != nil {
return WorkspaceAPIDiagnosticClientCreateOrUpdateResponse{}, err
}
if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) {
err = runtime.NewResponseError(httpResp)
return WorkspaceAPIDiagnosticClientCreateOrUpdateResponse{}, err
}
resp, err := client.createOrUpdateHandleResponse(httpResp)
return resp, err
}
// createOrUpdateCreateRequest creates the CreateOrUpdate request.
func (client *WorkspaceAPIDiagnosticClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, workspaceID string, apiID string, diagnosticID string, parameters DiagnosticContract, options *WorkspaceAPIDiagnosticClientCreateOrUpdateOptions) (*policy.Request, error) {
urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/workspaces/{workspaceId}/apis/{apiId}/diagnostics/{diagnosticId}"
if resourceGroupName == "" {
return nil, errors.New("parameter resourceGroupName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
if serviceName == "" {
return nil, errors.New("parameter serviceName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
if workspaceID == "" {
return nil, errors.New("parameter workspaceID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{workspaceId}", url.PathEscape(workspaceID))
if apiID == "" {
return nil, errors.New("parameter apiID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{apiId}", url.PathEscape(apiID))
if diagnosticID == "" {
return nil, errors.New("parameter diagnosticID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{diagnosticId}", url.PathEscape(diagnosticID))
if client.subscriptionID == "" {
return nil, errors.New("parameter client.subscriptionID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2024-05-01")
req.Raw().URL.RawQuery = reqQP.Encode()
req.Raw().Header["Accept"] = []string{"application/json"}
if options != nil && options.IfMatch != nil {
req.Raw().Header["If-Match"] = []string{*options.IfMatch}
}
if err := runtime.MarshalAsJSON(req, parameters); err != nil {
return nil, err
}
return req, nil
}
// createOrUpdateHandleResponse handles the CreateOrUpdate response.
func (client *WorkspaceAPIDiagnosticClient) createOrUpdateHandleResponse(resp *http.Response) (WorkspaceAPIDiagnosticClientCreateOrUpdateResponse, error) {
result := WorkspaceAPIDiagnosticClientCreateOrUpdateResponse{}
if val := resp.Header.Get("ETag"); val != "" {
result.ETag = &val
}
if err := runtime.UnmarshalAsJSON(resp, &result.DiagnosticContract); err != nil {
return WorkspaceAPIDiagnosticClientCreateOrUpdateResponse{}, err
}
return result, nil
}
// Delete - Deletes the specified Diagnostic from an API.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-05-01
// - resourceGroupName - The name of the resource group. The name is case insensitive.
// - serviceName - The name of the API Management service.
// - workspaceID - Workspace identifier. Must be unique in the current API Management service instance.
// - apiID - API identifier. Must be unique in the current API Management service instance.
// - diagnosticID - Diagnostic identifier. Must be unique in the current API Management service instance.
// - ifMatch - ETag of the Entity. ETag should match the current entity state from the header response of the GET request or
// it should be * for unconditional update.
// - options - WorkspaceAPIDiagnosticClientDeleteOptions contains the optional parameters for the WorkspaceAPIDiagnosticClient.Delete
// method.
func (client *WorkspaceAPIDiagnosticClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, workspaceID string, apiID string, diagnosticID string, ifMatch string, options *WorkspaceAPIDiagnosticClientDeleteOptions) (WorkspaceAPIDiagnosticClientDeleteResponse, error) {
var err error
const operationName = "WorkspaceAPIDiagnosticClient.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, resourceGroupName, serviceName, workspaceID, apiID, diagnosticID, ifMatch, options)
if err != nil {
return WorkspaceAPIDiagnosticClientDeleteResponse{}, err
}
httpResp, err := client.internal.Pipeline().Do(req)
if err != nil {
return WorkspaceAPIDiagnosticClientDeleteResponse{}, err
}
if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) {
err = runtime.NewResponseError(httpResp)
return WorkspaceAPIDiagnosticClientDeleteResponse{}, err
}
return WorkspaceAPIDiagnosticClientDeleteResponse{}, nil
}
// deleteCreateRequest creates the Delete request.
func (client *WorkspaceAPIDiagnosticClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, workspaceID string, apiID string, diagnosticID string, ifMatch string, _ *WorkspaceAPIDiagnosticClientDeleteOptions) (*policy.Request, error) {
urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/workspaces/{workspaceId}/apis/{apiId}/diagnostics/{diagnosticId}"
if resourceGroupName == "" {
return nil, errors.New("parameter resourceGroupName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
if serviceName == "" {
return nil, errors.New("parameter serviceName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
if workspaceID == "" {
return nil, errors.New("parameter workspaceID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{workspaceId}", url.PathEscape(workspaceID))
if apiID == "" {
return nil, errors.New("parameter apiID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{apiId}", url.PathEscape(apiID))
if diagnosticID == "" {
return nil, errors.New("parameter diagnosticID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{diagnosticId}", url.PathEscape(diagnosticID))
if client.subscriptionID == "" {
return nil, errors.New("parameter client.subscriptionID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2024-05-01")
req.Raw().URL.RawQuery = reqQP.Encode()
req.Raw().Header["Accept"] = []string{"application/json"}
req.Raw().Header["If-Match"] = []string{ifMatch}
return req, nil
}
// Get - Gets the details of the Diagnostic for an API specified by its identifier.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-05-01
// - resourceGroupName - The name of the resource group. The name is case insensitive.
// - serviceName - The name of the API Management service.
// - workspaceID - Workspace identifier. Must be unique in the current API Management service instance.
// - apiID - API identifier. Must be unique in the current API Management service instance.
// - diagnosticID - Diagnostic identifier. Must be unique in the current API Management service instance.
// - options - WorkspaceAPIDiagnosticClientGetOptions contains the optional parameters for the WorkspaceAPIDiagnosticClient.Get
// method.
func (client *WorkspaceAPIDiagnosticClient) Get(ctx context.Context, resourceGroupName string, serviceName string, workspaceID string, apiID string, diagnosticID string, options *WorkspaceAPIDiagnosticClientGetOptions) (WorkspaceAPIDiagnosticClientGetResponse, error) {
var err error
const operationName = "WorkspaceAPIDiagnosticClient.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, resourceGroupName, serviceName, workspaceID, apiID, diagnosticID, options)
if err != nil {
return WorkspaceAPIDiagnosticClientGetResponse{}, err
}
httpResp, err := client.internal.Pipeline().Do(req)
if err != nil {
return WorkspaceAPIDiagnosticClientGetResponse{}, err
}
if !runtime.HasStatusCode(httpResp, http.StatusOK) {
err = runtime.NewResponseError(httpResp)
return WorkspaceAPIDiagnosticClientGetResponse{}, err
}
resp, err := client.getHandleResponse(httpResp)
return resp, err
}
// getCreateRequest creates the Get request.
func (client *WorkspaceAPIDiagnosticClient) getCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, workspaceID string, apiID string, diagnosticID string, _ *WorkspaceAPIDiagnosticClientGetOptions) (*policy.Request, error) {
urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/workspaces/{workspaceId}/apis/{apiId}/diagnostics/{diagnosticId}"
if resourceGroupName == "" {
return nil, errors.New("parameter resourceGroupName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
if serviceName == "" {
return nil, errors.New("parameter serviceName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
if workspaceID == "" {
return nil, errors.New("parameter workspaceID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{workspaceId}", url.PathEscape(workspaceID))
if apiID == "" {
return nil, errors.New("parameter apiID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{apiId}", url.PathEscape(apiID))
if diagnosticID == "" {
return nil, errors.New("parameter diagnosticID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{diagnosticId}", url.PathEscape(diagnosticID))
if client.subscriptionID == "" {
return nil, errors.New("parameter client.subscriptionID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2024-05-01")
req.Raw().URL.RawQuery = reqQP.Encode()
req.Raw().Header["Accept"] = []string{"application/json"}
return req, nil
}
// getHandleResponse handles the Get response.
func (client *WorkspaceAPIDiagnosticClient) getHandleResponse(resp *http.Response) (WorkspaceAPIDiagnosticClientGetResponse, error) {
result := WorkspaceAPIDiagnosticClientGetResponse{}
if val := resp.Header.Get("ETag"); val != "" {
result.ETag = &val
}
if err := runtime.UnmarshalAsJSON(resp, &result.DiagnosticContract); err != nil {
return WorkspaceAPIDiagnosticClientGetResponse{}, err
}
return result, nil
}
// GetEntityTag - Gets the entity state (Etag) version of the Diagnostic for an API specified by its identifier.
//
// Generated from API version 2024-05-01
// - resourceGroupName - The name of the resource group. The name is case insensitive.
// - serviceName - The name of the API Management service.
// - workspaceID - Workspace identifier. Must be unique in the current API Management service instance.
// - apiID - API identifier. Must be unique in the current API Management service instance.
// - diagnosticID - Diagnostic identifier. Must be unique in the current API Management service instance.
// - options - WorkspaceAPIDiagnosticClientGetEntityTagOptions contains the optional parameters for the WorkspaceAPIDiagnosticClient.GetEntityTag
// method.
func (client *WorkspaceAPIDiagnosticClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, workspaceID string, apiID string, diagnosticID string, options *WorkspaceAPIDiagnosticClientGetEntityTagOptions) (WorkspaceAPIDiagnosticClientGetEntityTagResponse, error) {
var err error
const operationName = "WorkspaceAPIDiagnosticClient.GetEntityTag"
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
defer func() { endSpan(err) }()
req, err := client.getEntityTagCreateRequest(ctx, resourceGroupName, serviceName, workspaceID, apiID, diagnosticID, options)
if err != nil {
return WorkspaceAPIDiagnosticClientGetEntityTagResponse{}, err
}
httpResp, err := client.internal.Pipeline().Do(req)
if err != nil {
return WorkspaceAPIDiagnosticClientGetEntityTagResponse{}, err
}
if !runtime.HasStatusCode(httpResp, http.StatusOK) {
err = runtime.NewResponseError(httpResp)
return WorkspaceAPIDiagnosticClientGetEntityTagResponse{}, err
}
resp, err := client.getEntityTagHandleResponse(httpResp)
return resp, err
}
// getEntityTagCreateRequest creates the GetEntityTag request.
func (client *WorkspaceAPIDiagnosticClient) getEntityTagCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, workspaceID string, apiID string, diagnosticID string, _ *WorkspaceAPIDiagnosticClientGetEntityTagOptions) (*policy.Request, error) {
urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/workspaces/{workspaceId}/apis/{apiId}/diagnostics/{diagnosticId}"
if resourceGroupName == "" {
return nil, errors.New("parameter resourceGroupName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
if serviceName == "" {
return nil, errors.New("parameter serviceName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
if workspaceID == "" {
return nil, errors.New("parameter workspaceID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{workspaceId}", url.PathEscape(workspaceID))
if apiID == "" {
return nil, errors.New("parameter apiID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{apiId}", url.PathEscape(apiID))
if diagnosticID == "" {
return nil, errors.New("parameter diagnosticID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{diagnosticId}", url.PathEscape(diagnosticID))
if client.subscriptionID == "" {
return nil, errors.New("parameter client.subscriptionID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
req, err := runtime.NewRequest(ctx, http.MethodHead, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2024-05-01")
req.Raw().URL.RawQuery = reqQP.Encode()
req.Raw().Header["Accept"] = []string{"application/json"}
return req, nil
}
// getEntityTagHandleResponse handles the GetEntityTag response.
func (client *WorkspaceAPIDiagnosticClient) getEntityTagHandleResponse(resp *http.Response) (WorkspaceAPIDiagnosticClientGetEntityTagResponse, error) {
result := WorkspaceAPIDiagnosticClientGetEntityTagResponse{Success: resp.StatusCode >= 200 && resp.StatusCode < 300}
if val := resp.Header.Get("ETag"); val != "" {
result.ETag = &val
}
return result, nil
}
// NewListByWorkspacePager - Lists all diagnostics of an API.
//
// Generated from API version 2024-05-01
// - resourceGroupName - The name of the resource group. The name is case insensitive.
// - serviceName - The name of the API Management service.
// - workspaceID - Workspace identifier. Must be unique in the current API Management service instance.
// - apiID - API identifier. Must be unique in the current API Management service instance.
// - options - WorkspaceAPIDiagnosticClientListByWorkspaceOptions contains the optional parameters for the WorkspaceAPIDiagnosticClient.NewListByWorkspacePager
// method.
func (client *WorkspaceAPIDiagnosticClient) NewListByWorkspacePager(resourceGroupName string, serviceName string, workspaceID string, apiID string, options *WorkspaceAPIDiagnosticClientListByWorkspaceOptions) *runtime.Pager[WorkspaceAPIDiagnosticClientListByWorkspaceResponse] {
return runtime.NewPager(runtime.PagingHandler[WorkspaceAPIDiagnosticClientListByWorkspaceResponse]{
More: func(page WorkspaceAPIDiagnosticClientListByWorkspaceResponse) bool {
return page.NextLink != nil && len(*page.NextLink) > 0
},
Fetcher: func(ctx context.Context, page *WorkspaceAPIDiagnosticClientListByWorkspaceResponse) (WorkspaceAPIDiagnosticClientListByWorkspaceResponse, error) {
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "WorkspaceAPIDiagnosticClient.NewListByWorkspacePager")
nextLink := ""
if page != nil {
nextLink = *page.NextLink
}
resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
return client.listByWorkspaceCreateRequest(ctx, resourceGroupName, serviceName, workspaceID, apiID, options)
}, nil)
if err != nil {
return WorkspaceAPIDiagnosticClientListByWorkspaceResponse{}, err
}
return client.listByWorkspaceHandleResponse(resp)
},
Tracer: client.internal.Tracer(),
})
}
// listByWorkspaceCreateRequest creates the ListByWorkspace request.
func (client *WorkspaceAPIDiagnosticClient) listByWorkspaceCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, workspaceID string, apiID string, options *WorkspaceAPIDiagnosticClientListByWorkspaceOptions) (*policy.Request, error) {
urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/workspaces/{workspaceId}/apis/{apiId}/diagnostics"
if resourceGroupName == "" {
return nil, errors.New("parameter resourceGroupName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
if serviceName == "" {
return nil, errors.New("parameter serviceName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
if workspaceID == "" {
return nil, errors.New("parameter workspaceID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{workspaceId}", url.PathEscape(workspaceID))
if apiID == "" {
return nil, errors.New("parameter apiID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{apiId}", url.PathEscape(apiID))
if client.subscriptionID == "" {
return nil, errors.New("parameter client.subscriptionID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
if options != nil && options.Filter != nil {
reqQP.Set("$filter", *options.Filter)
}
if options != nil && options.Skip != nil {
reqQP.Set("$skip", strconv.FormatInt(int64(*options.Skip), 10))
}
if options != nil && options.Top != nil {
reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10))
}
reqQP.Set("api-version", "2024-05-01")
req.Raw().URL.RawQuery = reqQP.Encode()
req.Raw().Header["Accept"] = []string{"application/json"}
return req, nil
}
// listByWorkspaceHandleResponse handles the ListByWorkspace response.
func (client *WorkspaceAPIDiagnosticClient) listByWorkspaceHandleResponse(resp *http.Response) (WorkspaceAPIDiagnosticClientListByWorkspaceResponse, error) {
result := WorkspaceAPIDiagnosticClientListByWorkspaceResponse{}
if err := runtime.UnmarshalAsJSON(resp, &result.DiagnosticCollection); err != nil {
return WorkspaceAPIDiagnosticClientListByWorkspaceResponse{}, err
}
return result, nil
}
// Update - Updates the details of the Diagnostic for an API specified by its identifier.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-05-01
// - resourceGroupName - The name of the resource group. The name is case insensitive.
// - serviceName - The name of the API Management service.
// - workspaceID - Workspace identifier. Must be unique in the current API Management service instance.
// - apiID - API identifier. Must be unique in the current API Management service instance.
// - diagnosticID - Diagnostic identifier. Must be unique in the current API Management service instance.
// - ifMatch - ETag of the Entity. ETag should match the current entity state from the header response of the GET request or
// it should be * for unconditional update.
// - parameters - Diagnostic Update parameters.
// - options - WorkspaceAPIDiagnosticClientUpdateOptions contains the optional parameters for the WorkspaceAPIDiagnosticClient.Update
// method.
func (client *WorkspaceAPIDiagnosticClient) Update(ctx context.Context, resourceGroupName string, serviceName string, workspaceID string, apiID string, diagnosticID string, ifMatch string, parameters DiagnosticUpdateContract, options *WorkspaceAPIDiagnosticClientUpdateOptions) (WorkspaceAPIDiagnosticClientUpdateResponse, error) {
var err error
const operationName = "WorkspaceAPIDiagnosticClient.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, resourceGroupName, serviceName, workspaceID, apiID, diagnosticID, ifMatch, parameters, options)
if err != nil {
return WorkspaceAPIDiagnosticClientUpdateResponse{}, err
}
httpResp, err := client.internal.Pipeline().Do(req)
if err != nil {
return WorkspaceAPIDiagnosticClientUpdateResponse{}, err
}
if !runtime.HasStatusCode(httpResp, http.StatusOK) {
err = runtime.NewResponseError(httpResp)
return WorkspaceAPIDiagnosticClientUpdateResponse{}, err
}
resp, err := client.updateHandleResponse(httpResp)
return resp, err
}
// updateCreateRequest creates the Update request.
func (client *WorkspaceAPIDiagnosticClient) updateCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, workspaceID string, apiID string, diagnosticID string, ifMatch string, parameters DiagnosticUpdateContract, _ *WorkspaceAPIDiagnosticClientUpdateOptions) (*policy.Request, error) {
urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/workspaces/{workspaceId}/apis/{apiId}/diagnostics/{diagnosticId}"
if resourceGroupName == "" {
return nil, errors.New("parameter resourceGroupName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
if serviceName == "" {
return nil, errors.New("parameter serviceName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName))
if workspaceID == "" {
return nil, errors.New("parameter workspaceID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{workspaceId}", url.PathEscape(workspaceID))
if apiID == "" {
return nil, errors.New("parameter apiID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{apiId}", url.PathEscape(apiID))
if diagnosticID == "" {
return nil, errors.New("parameter diagnosticID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{diagnosticId}", url.PathEscape(diagnosticID))
if client.subscriptionID == "" {
return nil, errors.New("parameter client.subscriptionID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2024-05-01")
req.Raw().URL.RawQuery = reqQP.Encode()
req.Raw().Header["Accept"] = []string{"application/json"}
req.Raw().Header["If-Match"] = []string{ifMatch}
if err := runtime.MarshalAsJSON(req, parameters); err != nil {
return nil, err
}
return req, nil
}
// updateHandleResponse handles the Update response.
func (client *WorkspaceAPIDiagnosticClient) updateHandleResponse(resp *http.Response) (WorkspaceAPIDiagnosticClientUpdateResponse, error) {
result := WorkspaceAPIDiagnosticClientUpdateResponse{}
if val := resp.Header.Get("ETag"); val != "" {
result.ETag = &val
}
if err := runtime.UnmarshalAsJSON(resp, &result.DiagnosticContract); err != nil {
return WorkspaceAPIDiagnosticClientUpdateResponse{}, err
}
return result, nil
}