diff --git a/sdk/resourcemanager/selfhelp/armselfhelp/CHANGELOG.md b/sdk/resourcemanager/selfhelp/armselfhelp/CHANGELOG.md new file mode 100644 index 000000000000..c911fac2b588 --- /dev/null +++ b/sdk/resourcemanager/selfhelp/armselfhelp/CHANGELOG.md @@ -0,0 +1,7 @@ +# Release History + +## 0.1.0 (2023-04-28) + +The package of `github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/selfhelp/armselfhelp` is using our [next generation design principles](https://azure.github.io/azure-sdk/general_introduction.html). + +To learn more, please refer to our documentation [Quick Start](https://aka.ms/azsdk/go/mgmt). \ No newline at end of file diff --git a/sdk/resourcemanager/selfhelp/armselfhelp/LICENSE.txt b/sdk/resourcemanager/selfhelp/armselfhelp/LICENSE.txt new file mode 100644 index 000000000000..dc0c2ffb3dc1 --- /dev/null +++ b/sdk/resourcemanager/selfhelp/armselfhelp/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) Microsoft Corporation. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/sdk/resourcemanager/selfhelp/armselfhelp/README.md b/sdk/resourcemanager/selfhelp/armselfhelp/README.md new file mode 100644 index 000000000000..71af77c1f6e5 --- /dev/null +++ b/sdk/resourcemanager/selfhelp/armselfhelp/README.md @@ -0,0 +1,85 @@ +# Azure Selfhelp Module for Go + +[![PkgGoDev](https://pkg.go.dev/badge/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/selfhelp/armselfhelp)](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/selfhelp/armselfhelp) + +The `armselfhelp` module provides operations for working with Azure Selfhelp. + +[Source code](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/resourcemanager/selfhelp/armselfhelp) + +# Getting started + +## Prerequisites + +- an [Azure subscription](https://azure.microsoft.com/free/) +- Go 1.18 or above (You could download and install the latest version of Go from [here](https://go.dev/doc/install). It will replace the existing Go on your machine. If you want to install multiple Go versions on the same machine, you could refer this [doc](https://go.dev/doc/manage-install).) + +## Install the package + +This project uses [Go modules](https://github.com/golang/go/wiki/Modules) for versioning and dependency management. + +Install the Azure Selfhelp module: + +```sh +go get github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/selfhelp/armselfhelp +``` + +## Authorization + +When creating a client, you will need to provide a credential for authenticating with Azure Selfhelp. The `azidentity` module provides facilities for various ways of authenticating with Azure including client/secret, certificate, managed identity, and more. + +```go +cred, err := azidentity.NewDefaultAzureCredential(nil) +``` + +For more information on authentication, please see the documentation for `azidentity` at [pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity). + +## Client Factory + +Azure Selfhelp module consists of one or more clients. We provide a client factory which could be used to create any client in this module. + +```go +clientFactory, err := armselfhelp.NewClientFactory(, cred, nil) +``` + +You can use `ClientOptions` in package `github.com/Azure/azure-sdk-for-go/sdk/azcore/arm` to set endpoint to connect with public and sovereign clouds as well as Azure Stack. For more information, please see the documentation for `azcore` at [pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore). + +```go +options := arm.ClientOptions { + ClientOptions: azcore.ClientOptions { + Cloud: cloud.AzureChina, + }, +} +clientFactory, err := armselfhelp.NewClientFactory(, cred, &options) +``` + +## Clients + +A client groups a set of related APIs, providing access to its functionality. Create one or more clients to access the APIs you require using client factory. + +```go +client := clientFactory.NewDiagnosticsClient() +``` + +## Provide Feedback + +If you encounter bugs or have suggestions, please +[open an issue](https://github.com/Azure/azure-sdk-for-go/issues) and assign the `Selfhelp` label. + +# Contributing + +This project welcomes contributions and suggestions. Most contributions require +you to agree to a Contributor License Agreement (CLA) declaring that you have +the right to, and actually do, grant us the rights to use your contribution. +For details, visit [https://cla.microsoft.com](https://cla.microsoft.com). + +When you submit a pull request, a CLA-bot will automatically determine whether +you need to provide a CLA and decorate the PR appropriately (e.g., label, +comment). Simply follow the instructions provided by the bot. You will only +need to do this once across all repos using our CLA. + +This project has adopted the +[Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). +For more information, see the +[Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) +or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any +additional questions or comments. \ No newline at end of file diff --git a/sdk/resourcemanager/selfhelp/armselfhelp/autorest.md b/sdk/resourcemanager/selfhelp/armselfhelp/autorest.md new file mode 100644 index 000000000000..079ac149467b --- /dev/null +++ b/sdk/resourcemanager/selfhelp/armselfhelp/autorest.md @@ -0,0 +1,13 @@ +### AutoRest Configuration + +> see https://aka.ms/autorest + +``` yaml +azure-arm: true +require: +- https://github.com/Azure/azure-rest-api-specs/blob/d938a209ffd813aafe13b1899f0a1328fe186c87/specification/help/resource-manager/readme.md +- https://github.com/Azure/azure-rest-api-specs/blob/d938a209ffd813aafe13b1899f0a1328fe186c87/specification/help/resource-manager/readme.go.md +license-header: MICROSOFT_MIT_NO_VERSION +module-version: 0.1.0 +tag: package-2023-01-01-preview +``` \ No newline at end of file diff --git a/sdk/resourcemanager/selfhelp/armselfhelp/build.go b/sdk/resourcemanager/selfhelp/armselfhelp/build.go new file mode 100644 index 000000000000..c1485c89731a --- /dev/null +++ b/sdk/resourcemanager/selfhelp/armselfhelp/build.go @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +// This file enables 'go generate' to regenerate this specific SDK +//go:generate pwsh ../../../../eng/scripts/build.ps1 -skipBuild -cleanGenerated -format -tidy -generate -alwaysSetBodyParamRequired -removeUnreferencedTypes resourcemanager/selfhelp/armselfhelp + +package armselfhelp diff --git a/sdk/resourcemanager/selfhelp/armselfhelp/ci.yml b/sdk/resourcemanager/selfhelp/armselfhelp/ci.yml new file mode 100644 index 000000000000..151015313962 --- /dev/null +++ b/sdk/resourcemanager/selfhelp/armselfhelp/ci.yml @@ -0,0 +1,28 @@ +# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file. +trigger: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/resourcemanager/selfhelp/armselfhelp/ + +pr: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/resourcemanager/selfhelp/armselfhelp/ + +stages: +- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml + parameters: + IncludeRelease: true + ServiceDirectory: 'resourcemanager/selfhelp/armselfhelp' diff --git a/sdk/resourcemanager/selfhelp/armselfhelp/client_factory.go b/sdk/resourcemanager/selfhelp/armselfhelp/client_factory.go new file mode 100644 index 000000000000..a5ea1dd238d4 --- /dev/null +++ b/sdk/resourcemanager/selfhelp/armselfhelp/client_factory.go @@ -0,0 +1,52 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. + +package armselfhelp + +import ( + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" +) + +// ClientFactory is a client factory used to create any client in this module. +// Don't use this type directly, use NewClientFactory instead. +type ClientFactory struct { + credential azcore.TokenCredential + options *arm.ClientOptions +} + +// NewClientFactory creates a new instance of ClientFactory with the specified values. +// The parameter values will be propagated to any client created from this factory. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewClientFactory(credential azcore.TokenCredential, options *arm.ClientOptions) (*ClientFactory, error) { + _, err := arm.NewClient(moduleName+".ClientFactory", moduleVersion, credential, options) + if err != nil { + return nil, err + } + return &ClientFactory{ + credential: credential, + options: options.Clone(), + }, nil +} + +func (c *ClientFactory) NewOperationsClient() *OperationsClient { + subClient, _ := NewOperationsClient(c.credential, c.options) + return subClient +} + +func (c *ClientFactory) NewDiagnosticsClient() *DiagnosticsClient { + subClient, _ := NewDiagnosticsClient(c.credential, c.options) + return subClient +} + +func (c *ClientFactory) NewDiscoverySolutionClient() *DiscoverySolutionClient { + subClient, _ := NewDiscoverySolutionClient(c.credential, c.options) + return subClient +} diff --git a/sdk/resourcemanager/selfhelp/armselfhelp/constants.go b/sdk/resourcemanager/selfhelp/armselfhelp/constants.go new file mode 100644 index 000000000000..2536aa999084 --- /dev/null +++ b/sdk/resourcemanager/selfhelp/armselfhelp/constants.go @@ -0,0 +1,140 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. + +package armselfhelp + +const ( + moduleName = "armselfhelp" + moduleVersion = "v0.1.0" +) + +// ActionType - Enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. +type ActionType string + +const ( + ActionTypeInternal ActionType = "Internal" +) + +// PossibleActionTypeValues returns the possible values for the ActionType const type. +func PossibleActionTypeValues() []ActionType { + return []ActionType{ + ActionTypeInternal, + } +} + +// CreatedByType - The type of identity that created the resource. +type CreatedByType string + +const ( + CreatedByTypeApplication CreatedByType = "Application" + CreatedByTypeKey CreatedByType = "Key" + CreatedByTypeManagedIdentity CreatedByType = "ManagedIdentity" + CreatedByTypeUser CreatedByType = "User" +) + +// PossibleCreatedByTypeValues returns the possible values for the CreatedByType const type. +func PossibleCreatedByTypeValues() []CreatedByType { + return []CreatedByType{ + CreatedByTypeApplication, + CreatedByTypeKey, + CreatedByTypeManagedIdentity, + CreatedByTypeUser, + } +} + +// ImportanceLevel - Importance level of the insight. +type ImportanceLevel string + +const ( + // ImportanceLevelCritical - A critical insight has been found after running the diagnostic. + ImportanceLevelCritical ImportanceLevel = "Critical" + // ImportanceLevelInformation - An information insight has been found after running the diagnostic. + ImportanceLevelInformation ImportanceLevel = "Information" + // ImportanceLevelWarning - A warning insight has been found after running the diagnostic. + ImportanceLevelWarning ImportanceLevel = "Warning" +) + +// PossibleImportanceLevelValues returns the possible values for the ImportanceLevel const type. +func PossibleImportanceLevelValues() []ImportanceLevel { + return []ImportanceLevel{ + ImportanceLevelCritical, + ImportanceLevelInformation, + ImportanceLevelWarning, + } +} + +// Origin - The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default +// value is "user,system" +type Origin string + +const ( + OriginSystem Origin = "system" + OriginUser Origin = "user" + OriginUserSystem Origin = "user,system" +) + +// PossibleOriginValues returns the possible values for the Origin const type. +func PossibleOriginValues() []Origin { + return []Origin{ + OriginSystem, + OriginUser, + OriginUserSystem, + } +} + +// ProvisioningState - Status of diagnostic provisioning. +type ProvisioningState string + +const ( + // ProvisioningStateCanceled - When Diagnostic request gets canceled. + ProvisioningStateCanceled ProvisioningState = "Canceled" + // ProvisioningStateFailed - All Diagnostics failed to run. + ProvisioningStateFailed ProvisioningState = "Failed" + // ProvisioningStatePartialComplete - Some Diagnostics are still running or failed. + ProvisioningStatePartialComplete ProvisioningState = "PartialComplete" + // ProvisioningStateSucceeded - All Diagnostics in the Batch succeeded. + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +// PossibleProvisioningStateValues returns the possible values for the ProvisioningState const type. +func PossibleProvisioningStateValues() []ProvisioningState { + return []ProvisioningState{ + ProvisioningStateCanceled, + ProvisioningStateFailed, + ProvisioningStatePartialComplete, + ProvisioningStateSucceeded, + } +} + +// Status - Denotes the status of the diagnostic resource. +type Status string + +const ( + // StatusFailed - Diagnostic creation failed. + StatusFailed Status = "Failed" + // StatusMissingInputs - Request is missing required inputs to run. + StatusMissingInputs Status = "MissingInputs" + // StatusRunning - Diagnostic is still running. + StatusRunning Status = "Running" + // StatusSucceeded - Diagnostic creation succeeded. + StatusSucceeded Status = "Succeeded" + // StatusTimeout - Diagnostic was timed out. + StatusTimeout Status = "Timeout" +) + +// PossibleStatusValues returns the possible values for the Status const type. +func PossibleStatusValues() []Status { + return []Status{ + StatusFailed, + StatusMissingInputs, + StatusRunning, + StatusSucceeded, + StatusTimeout, + } +} diff --git a/sdk/resourcemanager/selfhelp/armselfhelp/diagnostics_client.go b/sdk/resourcemanager/selfhelp/armselfhelp/diagnostics_client.go new file mode 100644 index 000000000000..db078824b98d --- /dev/null +++ b/sdk/resourcemanager/selfhelp/armselfhelp/diagnostics_client.go @@ -0,0 +1,209 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. + +package armselfhelp + +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" + "strings" +) + +// DiagnosticsClient contains the methods for the Diagnostics group. +// Don't use this type directly, use NewDiagnosticsClient() instead. +type DiagnosticsClient struct { + internal *arm.Client +} + +// NewDiagnosticsClient creates a new instance of DiagnosticsClient with the specified values. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewDiagnosticsClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*DiagnosticsClient, error) { + cl, err := arm.NewClient(moduleName+".DiagnosticsClient", moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &DiagnosticsClient{ + internal: cl, + } + return client, nil +} + +// CheckNameAvailability - This API is used to check the uniqueness of a resource name used for a diagnostic check. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2023-01-01-preview +// - scope - This is an extension resource provider and only resource level extension is supported at the moment. +// - options - DiagnosticsClientCheckNameAvailabilityOptions contains the optional parameters for the DiagnosticsClient.CheckNameAvailability +// method. +func (client *DiagnosticsClient) CheckNameAvailability(ctx context.Context, scope string, options *DiagnosticsClientCheckNameAvailabilityOptions) (DiagnosticsClientCheckNameAvailabilityResponse, error) { + req, err := client.checkNameAvailabilityCreateRequest(ctx, scope, options) + if err != nil { + return DiagnosticsClientCheckNameAvailabilityResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return DiagnosticsClientCheckNameAvailabilityResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return DiagnosticsClientCheckNameAvailabilityResponse{}, runtime.NewResponseError(resp) + } + return client.checkNameAvailabilityHandleResponse(resp) +} + +// checkNameAvailabilityCreateRequest creates the CheckNameAvailability request. +func (client *DiagnosticsClient) checkNameAvailabilityCreateRequest(ctx context.Context, scope string, options *DiagnosticsClientCheckNameAvailabilityOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.Help/checkNameAvailability" + urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2023-01-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + if options != nil && options.CheckNameAvailabilityRequest != nil { + return req, runtime.MarshalAsJSON(req, *options.CheckNameAvailabilityRequest) + } + return req, nil +} + +// checkNameAvailabilityHandleResponse handles the CheckNameAvailability response. +func (client *DiagnosticsClient) checkNameAvailabilityHandleResponse(resp *http.Response) (DiagnosticsClientCheckNameAvailabilityResponse, error) { + result := DiagnosticsClientCheckNameAvailabilityResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.CheckNameAvailabilityResponse); err != nil { + return DiagnosticsClientCheckNameAvailabilityResponse{}, err + } + return result, nil +} + +// BeginCreate - Diagnostics tells you precisely the root cause of the issue and how to address it. You can get diagnostics +// once you discover and identify the relevant solution for your Azure issue. +// You can create diagnostics using the ‘solutionId’ from Solution Discovery API response and ‘additionalParameters’ +// Note: ‘requiredParameterSets’ from Solutions Discovery API response must be passed via ‘additionalParameters’ as an input +// to Diagnostics API +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2023-01-01-preview +// - scope - This is an extension resource provider and only resource level extension is supported at the moment. +// - diagnosticsResourceName - Unique resource name for insight resources +// - diagnosticResourceRequest - The required request body for this insightResource invocation. +// - options - DiagnosticsClientBeginCreateOptions contains the optional parameters for the DiagnosticsClient.BeginCreate method. +func (client *DiagnosticsClient) BeginCreate(ctx context.Context, scope string, diagnosticsResourceName string, diagnosticResourceRequest DiagnosticResource, options *DiagnosticsClientBeginCreateOptions) (*runtime.Poller[DiagnosticsClientCreateResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.create(ctx, scope, diagnosticsResourceName, diagnosticResourceRequest, options) + if err != nil { + return nil, err + } + return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DiagnosticsClientCreateResponse]{ + FinalStateVia: runtime.FinalStateViaAzureAsyncOp, + }) + } else { + return runtime.NewPollerFromResumeToken[DiagnosticsClientCreateResponse](options.ResumeToken, client.internal.Pipeline(), nil) + } +} + +// Create - Diagnostics tells you precisely the root cause of the issue and how to address it. You can get diagnostics once +// you discover and identify the relevant solution for your Azure issue. +// You can create diagnostics using the ‘solutionId’ from Solution Discovery API response and ‘additionalParameters’ +// Note: ‘requiredParameterSets’ from Solutions Discovery API response must be passed via ‘additionalParameters’ as an input +// to Diagnostics API +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2023-01-01-preview +func (client *DiagnosticsClient) create(ctx context.Context, scope string, diagnosticsResourceName string, diagnosticResourceRequest DiagnosticResource, options *DiagnosticsClientBeginCreateOptions) (*http.Response, error) { + req, err := client.createCreateRequest(ctx, scope, diagnosticsResourceName, diagnosticResourceRequest, options) + if err != nil { + return nil, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusCreated) { + return nil, runtime.NewResponseError(resp) + } + return resp, nil +} + +// createCreateRequest creates the Create request. +func (client *DiagnosticsClient) createCreateRequest(ctx context.Context, scope string, diagnosticsResourceName string, diagnosticResourceRequest DiagnosticResource, options *DiagnosticsClientBeginCreateOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.Help/diagnostics/{diagnosticsResourceName}" + urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) + if diagnosticsResourceName == "" { + return nil, errors.New("parameter diagnosticsResourceName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{diagnosticsResourceName}", url.PathEscape(diagnosticsResourceName)) + 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", "2023-01-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, runtime.MarshalAsJSON(req, diagnosticResourceRequest) +} + +// Get - Get the diagnostics using the 'diagnosticsResourceName' you chose while creating the diagnostic. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2023-01-01-preview +// - scope - This is an extension resource provider and only resource level extension is supported at the moment. +// - diagnosticsResourceName - Unique resource name for insight resources +// - options - DiagnosticsClientGetOptions contains the optional parameters for the DiagnosticsClient.Get method. +func (client *DiagnosticsClient) Get(ctx context.Context, scope string, diagnosticsResourceName string, options *DiagnosticsClientGetOptions) (DiagnosticsClientGetResponse, error) { + req, err := client.getCreateRequest(ctx, scope, diagnosticsResourceName, options) + if err != nil { + return DiagnosticsClientGetResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return DiagnosticsClientGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return DiagnosticsClientGetResponse{}, runtime.NewResponseError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *DiagnosticsClient) getCreateRequest(ctx context.Context, scope string, diagnosticsResourceName string, options *DiagnosticsClientGetOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.Help/diagnostics/{diagnosticsResourceName}" + urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) + if diagnosticsResourceName == "" { + return nil, errors.New("parameter diagnosticsResourceName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{diagnosticsResourceName}", url.PathEscape(diagnosticsResourceName)) + 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", "2023-01-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *DiagnosticsClient) getHandleResponse(resp *http.Response) (DiagnosticsClientGetResponse, error) { + result := DiagnosticsClientGetResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.DiagnosticResource); err != nil { + return DiagnosticsClientGetResponse{}, err + } + return result, nil +} diff --git a/sdk/resourcemanager/selfhelp/armselfhelp/diagnostics_client_example_test.go b/sdk/resourcemanager/selfhelp/armselfhelp/diagnostics_client_example_test.go new file mode 100644 index 000000000000..517e83ce3359 --- /dev/null +++ b/sdk/resourcemanager/selfhelp/armselfhelp/diagnostics_client_example_test.go @@ -0,0 +1,141 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. + +package armselfhelp_test + +import ( + "context" + "log" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/selfhelp/armselfhelp" +) + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d938a209ffd813aafe13b1899f0a1328fe186c87/specification/help/resource-manager/Microsoft.Help/preview/2023-01-01-preview/examples/CheckNameAvailabilityForDiagnosticWhenNameIsAvailable.json +func ExampleDiagnosticsClient_CheckNameAvailability_exampleWhenNameIsAvailableForADiagnosticResource() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armselfhelp.NewClientFactory(cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + res, err := clientFactory.NewDiagnosticsClient().CheckNameAvailability(ctx, "subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6", &armselfhelp.DiagnosticsClientCheckNameAvailabilityOptions{CheckNameAvailabilityRequest: &armselfhelp.CheckNameAvailabilityRequest{ + Name: to.Ptr("sampleName"), + Type: to.Ptr("Microsoft.Help/diagnostics"), + }, + }) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.CheckNameAvailabilityResponse = armselfhelp.CheckNameAvailabilityResponse{ + // NameAvailable: to.Ptr(true), + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d938a209ffd813aafe13b1899f0a1328fe186c87/specification/help/resource-manager/Microsoft.Help/preview/2023-01-01-preview/examples/CheckNameAvailabilityForDiagnosticWhenNameIsNotAvailable.json +func ExampleDiagnosticsClient_CheckNameAvailability_exampleWhenNameIsNotAvailableForADiagnosticResource() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armselfhelp.NewClientFactory(cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + res, err := clientFactory.NewDiagnosticsClient().CheckNameAvailability(ctx, "subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6", &armselfhelp.DiagnosticsClientCheckNameAvailabilityOptions{CheckNameAvailabilityRequest: &armselfhelp.CheckNameAvailabilityRequest{ + Name: to.Ptr("sampleName"), + Type: to.Ptr("Microsoft.Help/diagnostics"), + }, + }) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.CheckNameAvailabilityResponse = armselfhelp.CheckNameAvailabilityResponse{ + // Message: to.Ptr("Name not available"), + // NameAvailable: to.Ptr(false), + // Reason: to.Ptr("Name is already in use"), + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d938a209ffd813aafe13b1899f0a1328fe186c87/specification/help/resource-manager/Microsoft.Help/preview/2023-01-01-preview/examples/CreateDiagnosticForKeyVaultResource.json +func ExampleDiagnosticsClient_BeginCreate() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armselfhelp.NewClientFactory(cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewDiagnosticsClient().BeginCreate(ctx, "subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6/resourcegroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read", "VMNotWorkingInsight", armselfhelp.DiagnosticResource{}, nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + _, err = poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d938a209ffd813aafe13b1899f0a1328fe186c87/specification/help/resource-manager/Microsoft.Help/preview/2023-01-01-preview/examples/GetDiagnosticForKeyVaultResource.json +func ExampleDiagnosticsClient_Get() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armselfhelp.NewClientFactory(cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + res, err := clientFactory.NewDiagnosticsClient().Get(ctx, "subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6/resourcegroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read", "VMNotWorkingInsight", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.DiagnosticResource = armselfhelp.DiagnosticResource{ + // Name: to.Ptr("Microsoft.Help/diagnostics"), + // Type: to.Ptr("VMNotWorkingInsight"), + // ID: to.Ptr("subscriptions/mySubscription/resourcegroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read/providers/Microsoft.Help/diagnostics/VMNotWorkingInsight"), + // Properties: &armselfhelp.DiagnosticResourceProperties{ + // AcceptedAt: to.Ptr("2023-03-10T03:04:40Z"), + // Diagnostics: []*armselfhelp.Diagnostic{ + // { + // Error: &armselfhelp.Error{ + // Code: to.Ptr("errorCode"), + // Message: to.Ptr("errorMessage"), + // }, + // Insights: []*armselfhelp.Insight{ + // { + // ID: to.Ptr("InsightArticleId"), + // ImportanceLevel: to.Ptr(armselfhelp.ImportanceLevelCritical), + // Results: to.Ptr("Article Content"), + // Title: to.Ptr("An example title for an Insight"), + // }}, + // SolutionID: to.Ptr("sampleSolutionId"), + // Status: to.Ptr(armselfhelp.StatusSucceeded), + // }}, + // ProvisioningState: to.Ptr(armselfhelp.ProvisioningStateSucceeded), + // }, + // } +} diff --git a/sdk/resourcemanager/selfhelp/armselfhelp/discoverysolution_client.go b/sdk/resourcemanager/selfhelp/armselfhelp/discoverysolution_client.go new file mode 100644 index 000000000000..c08148235c50 --- /dev/null +++ b/sdk/resourcemanager/selfhelp/armselfhelp/discoverysolution_client.go @@ -0,0 +1,112 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. + +package armselfhelp + +import ( + "context" + "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" + "strings" +) + +// DiscoverySolutionClient contains the methods for the DiscoverySolution group. +// Don't use this type directly, use NewDiscoverySolutionClient() instead. +type DiscoverySolutionClient struct { + internal *arm.Client +} + +// NewDiscoverySolutionClient creates a new instance of DiscoverySolutionClient with the specified values. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewDiscoverySolutionClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*DiscoverySolutionClient, error) { + cl, err := arm.NewClient(moduleName+".DiscoverySolutionClient", moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &DiscoverySolutionClient{ + internal: cl, + } + return client, nil +} + +// NewListPager - Solutions Discovery is the initial point of entry within Help API, which helps you identify the relevant +// solutions for your Azure issue. +// You can discover solutions using resourceUri OR resourceUri + problemClassificationId. +// We will do our best in returning relevant diagnostics for your Azure issue. +// Get the problemClassificationId(s) using this reference [https://learn.microsoft.com/rest/api/support/problem-classifications/list?tabs=HTTP]. +// Note: ‘requiredParameterSets’ from Solutions Discovery API response must be passed via ‘additionalParameters’ as an input +// to Diagnostics API. +// +// Generated from API version 2023-01-01-preview +// - scope - This is an extension resource provider and only resource level extension is supported at the moment. +// - options - DiscoverySolutionClientListOptions contains the optional parameters for the DiscoverySolutionClient.NewListPager +// method. +func (client *DiscoverySolutionClient) NewListPager(scope string, options *DiscoverySolutionClientListOptions) *runtime.Pager[DiscoverySolutionClientListResponse] { + return runtime.NewPager(runtime.PagingHandler[DiscoverySolutionClientListResponse]{ + More: func(page DiscoverySolutionClientListResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *DiscoverySolutionClientListResponse) (DiscoverySolutionClientListResponse, error) { + var req *policy.Request + var err error + if page == nil { + req, err = client.listCreateRequest(ctx, scope, options) + } else { + req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + } + if err != nil { + return DiscoverySolutionClientListResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return DiscoverySolutionClientListResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return DiscoverySolutionClientListResponse{}, runtime.NewResponseError(resp) + } + return client.listHandleResponse(resp) + }, + }) +} + +// listCreateRequest creates the List request. +func (client *DiscoverySolutionClient) listCreateRequest(ctx context.Context, scope string, options *DiscoverySolutionClientListOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.Help/discoverySolutions" + urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) + 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", "2023-01-01-preview") + if options != nil && options.Skiptoken != nil { + reqQP.Set("$skiptoken", *options.Skiptoken) + } + req.Raw().URL.RawQuery = reqQP.Encode() + unencodedParams := []string{req.Raw().URL.RawQuery} + if options != nil && options.Filter != nil { + unencodedParams = append(unencodedParams, "$filter="+*options.Filter) + } + req.Raw().URL.RawQuery = strings.Join(unencodedParams, "&") + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listHandleResponse handles the List response. +func (client *DiscoverySolutionClient) listHandleResponse(resp *http.Response) (DiscoverySolutionClientListResponse, error) { + result := DiscoverySolutionClientListResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.DiscoveryResponse); err != nil { + return DiscoverySolutionClientListResponse{}, err + } + return result, nil +} diff --git a/sdk/resourcemanager/selfhelp/armselfhelp/discoverysolution_client_example_test.go b/sdk/resourcemanager/selfhelp/armselfhelp/discoverysolution_client_example_test.go new file mode 100644 index 000000000000..b591060c3be7 --- /dev/null +++ b/sdk/resourcemanager/selfhelp/armselfhelp/discoverysolution_client_example_test.go @@ -0,0 +1,87 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. + +package armselfhelp_test + +import ( + "context" + "log" + + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/selfhelp/armselfhelp" +) + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d938a209ffd813aafe13b1899f0a1328fe186c87/specification/help/resource-manager/Microsoft.Help/preview/2023-01-01-preview/examples/ListDiscoverySolutionsForKeyVaultResource.json +func ExampleDiscoverySolutionClient_NewListPager() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armselfhelp.NewClientFactory(cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + pager := clientFactory.NewDiscoverySolutionClient().NewListPager("subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6/resourcegroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read", &armselfhelp.DiscoverySolutionClientListOptions{Filter: nil, + Skiptoken: nil, + }) + for pager.More() { + page, err := pager.NextPage(ctx) + if err != nil { + log.Fatalf("failed to advance page: %v", err) + } + for _, v := range page.Value { + // You could use page here. We use blank identifier for just demo purposes. + _ = v + } + // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // page.DiscoveryResponse = armselfhelp.DiscoveryResponse{ + // Value: []*armselfhelp.SolutionMetadataResource{ + // { + // Name: to.Ptr("SampleSolutionId1"), + // Type: to.Ptr("Microsoft.Help/discoverySolutions"), + // ID: to.Ptr("subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6/resourcegroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read/providers/Microsoft.Help/discoverySolutions/SampleSolutionId1"), + // Properties: &armselfhelp.SolutionMetadataProperties{ + // Description: to.Ptr("This is a diagnostic"), + // RequiredParameterSets: [][]*string{ + // []*string{ + // to.Ptr("ResourceUri")}}, + // SolutionID: to.Ptr("SampleSolutionId1"), + // SolutionType: to.Ptr("Diagnostics"), + // }, + // }, + // { + // Name: to.Ptr("SampleSolutionId2"), + // Type: to.Ptr("Microsoft.Help/discoverySolutions"), + // ID: to.Ptr("subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6/resourcegroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read/providers/Microsoft.Help/discoverySolutions/SampleSolutionId2"), + // Properties: &armselfhelp.SolutionMetadataProperties{ + // Description: to.Ptr("This is a diagnostic"), + // RequiredParameterSets: [][]*string{ + // []*string{ + // to.Ptr("ResourceUri")}}, + // SolutionID: to.Ptr("SampleSolutionId2"), + // SolutionType: to.Ptr("Diagnostics"), + // }, + // }, + // { + // Name: to.Ptr("SampleSolutionId3"), + // Type: to.Ptr("Microsoft.Help/discoverySolutions"), + // ID: to.Ptr("subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6/resourcegroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read/providers/Microsoft.Help/discoverySolutions/SampleSolutionId3"), + // Properties: &armselfhelp.SolutionMetadataProperties{ + // Description: to.Ptr("This is a diagnostic"), + // RequiredParameterSets: [][]*string{ + // []*string{ + // to.Ptr("ResourceUri")}}, + // SolutionID: to.Ptr("SampleSolutionId3"), + // SolutionType: to.Ptr("Diagnostics"), + // }, + // }}, + // } + } +} diff --git a/sdk/resourcemanager/selfhelp/armselfhelp/go.mod b/sdk/resourcemanager/selfhelp/armselfhelp/go.mod new file mode 100644 index 000000000000..1b976a84ffa7 --- /dev/null +++ b/sdk/resourcemanager/selfhelp/armselfhelp/go.mod @@ -0,0 +1,21 @@ +module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/selfhelp/armselfhelp + +go 1.18 + +require ( + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 + github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2 +) + +require ( + github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 // indirect + github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0 // indirect + github.com/golang-jwt/jwt/v4 v4.5.0 // indirect + github.com/google/uuid v1.3.0 // indirect + github.com/kylelemons/godebug v1.1.0 // indirect + github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect + golang.org/x/crypto v0.6.0 // indirect + golang.org/x/net v0.7.0 // indirect + golang.org/x/sys v0.5.0 // indirect + golang.org/x/text v0.7.0 // indirect +) diff --git a/sdk/resourcemanager/selfhelp/armselfhelp/go.sum b/sdk/resourcemanager/selfhelp/armselfhelp/go.sum new file mode 100644 index 000000000000..8ba445a8c4da --- /dev/null +++ b/sdk/resourcemanager/selfhelp/armselfhelp/go.sum @@ -0,0 +1,31 @@ +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 h1:rTnT/Jrcm+figWlYz4Ixzt0SJVR2cMC8lvZcimipiEY= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0/go.mod h1:ON4tFdPTwRcgWEaVDrN3584Ef+b7GgSJaXxe5fW9t4M= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2 h1:uqM+VoHjVH6zdlkLF2b6O0ZANcHoj3rO0PoQ3jglUJA= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2/go.mod h1:twTKAa1E6hLmSDjLhaCkbTMQKc7p/rNLU40rLxGEOCI= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 h1:leh5DwKv6Ihwi+h60uHtn6UWAxBbZ0q8DwQVMzf61zw= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w= +github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0 h1:UE9n9rkJF62ArLb1F3DEjRt8O3jLwMWdSoypKV4f3MU= +github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c= +github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= +github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc= +golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= +golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= diff --git a/sdk/resourcemanager/selfhelp/armselfhelp/models.go b/sdk/resourcemanager/selfhelp/armselfhelp/models.go new file mode 100644 index 000000000000..3f369d55d4c6 --- /dev/null +++ b/sdk/resourcemanager/selfhelp/armselfhelp/models.go @@ -0,0 +1,270 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. + +package armselfhelp + +import "time" + +// CheckNameAvailabilityRequest - The check availability request body. +type CheckNameAvailabilityRequest struct { + // The name of the resource for which availability needs to be checked. + Name *string `json:"name,omitempty"` + + // The resource type. + Type *string `json:"type,omitempty"` +} + +// CheckNameAvailabilityResponse - Response for whether the requested resource name is available or not. +type CheckNameAvailabilityResponse struct { + // Gets an error message explaining the 'reason' value with more details. This field is returned iif nameAvailable is false. + Message *string `json:"message,omitempty"` + + // Returns true or false depending on the availability of the name + NameAvailable *bool `json:"nameAvailable,omitempty"` + + // Reason for why value is not available. This field is returned if nameAvailable is false. + Reason *string `json:"reason,omitempty"` +} + +// Diagnostic - Properties returned with in an insight. +type Diagnostic struct { + // Error definition. + Error *Error `json:"error,omitempty"` + + // The problems (if any) detected by this insight. + Insights []*Insight `json:"insights,omitempty"` + + // Solution Id + SolutionID *string `json:"solutionId,omitempty"` + + // Denotes the status of the diagnostic resource. + Status *Status `json:"status,omitempty"` +} + +// DiagnosticInvocation - Solution Invocation with additional params needed for invocation. +type DiagnosticInvocation struct { + // Additional parameters required to invoke the solutionId. + AdditionalParameters map[string]*string `json:"additionalParameters,omitempty"` + + // Solution Id to invoke. + SolutionID *string `json:"solutionId,omitempty"` +} + +// DiagnosticResource - Diagnostic resource +type DiagnosticResource struct { + // Diagnostic Resource properties. + Properties *DiagnosticResourceProperties `json:"properties,omitempty"` + + // READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string `json:"id,omitempty" azure:"ro"` + + // READ-ONLY; The name of the resource + Name *string `json:"name,omitempty" azure:"ro"` + + // READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData `json:"systemData,omitempty" azure:"ro"` + + // READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string `json:"type,omitempty" azure:"ro"` +} + +// DiagnosticResourceProperties - Diagnostic resource properties. +type DiagnosticResourceProperties struct { + // Global parameters that can be passed to all solutionIds. + GlobalParameters map[string]*string `json:"globalParameters,omitempty"` + + // SolutionIds that are needed to be invoked. + Insights []*DiagnosticInvocation `json:"insights,omitempty"` + + // READ-ONLY; Diagnostic Request Accepted time. + AcceptedAt *string `json:"acceptedAt,omitempty" azure:"ro"` + + // READ-ONLY; Array of Diagnostics. + Diagnostics []*Diagnostic `json:"diagnostics,omitempty" azure:"ro"` + + // READ-ONLY; Status of diagnostic provisioning. + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty" azure:"ro"` +} + +// DiagnosticsClientBeginCreateOptions contains the optional parameters for the DiagnosticsClient.BeginCreate method. +type DiagnosticsClientBeginCreateOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// DiagnosticsClientCheckNameAvailabilityOptions contains the optional parameters for the DiagnosticsClient.CheckNameAvailability +// method. +type DiagnosticsClientCheckNameAvailabilityOptions struct { + // The required parameters for availability check. + CheckNameAvailabilityRequest *CheckNameAvailabilityRequest +} + +// DiagnosticsClientGetOptions contains the optional parameters for the DiagnosticsClient.Get method. +type DiagnosticsClientGetOptions struct { + // placeholder for future optional parameters +} + +// DiscoveryResponse - Discovery response. +type DiscoveryResponse struct { + // The link used to get the next page of solution metadata. + NextLink *string `json:"nextLink,omitempty"` + + // The list of solution metadata. + Value []*SolutionMetadataResource `json:"value,omitempty"` +} + +// DiscoverySolutionClientListOptions contains the optional parameters for the DiscoverySolutionClient.NewListPager method. +type DiscoverySolutionClientListOptions struct { + // Can be used to filter solutionIds by 'ProblemClassificationId'. The filter supports only 'and' and 'eq' operators. Example: + // $filter=ProblemClassificationId eq '1ddda5b4-cf6c-4d4f-91ad-bc38ab0e811e' + // and ProblemClassificationId eq '0a9673c2-7af6-4e19-90d3-4ee2461076d9'. + Filter *string + // Skiptoken is only used if a previous operation returned a partial result. If a previous response contains a nextLink element, + // the value of the nextLink element will include a skiptoken parameter that + // specifies a starting point to use for subsequent calls. + Skiptoken *string +} + +// Error definition. +type Error struct { + // An array of additional nested error response info objects, as described by this contract. + Details []*Error `json:"details,omitempty"` + + // READ-ONLY; Service specific error code which serves as the substatus for the HTTP error code. + Code *string `json:"code,omitempty" azure:"ro"` + + // READ-ONLY; Description of the error. + Message *string `json:"message,omitempty" azure:"ro"` + + // READ-ONLY; Service specific error type which serves as additional context for the error herein. + Type *string `json:"type,omitempty" azure:"ro"` +} + +// Insight - Detailed insights(s) obtained via the invocation of an insight diagnostic troubleshooter. +type Insight struct { + // Article id. + ID *string `json:"id,omitempty"` + + // Importance level of the insight. + ImportanceLevel *ImportanceLevel `json:"importanceLevel,omitempty"` + + // Detailed result content. + Results *string `json:"results,omitempty"` + + // This insight's title. + Title *string `json:"title,omitempty"` +} + +// Operation - Details of a REST API operation, returned from the Resource Provider Operations API +type Operation struct { + // Localized display information for this particular operation. + Display *OperationDisplay `json:"display,omitempty"` + + // READ-ONLY; Enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. + ActionType *ActionType `json:"actionType,omitempty" azure:"ro"` + + // READ-ONLY; Whether the operation applies to data-plane. This is "true" for data-plane operations and "false" for ARM/control-plane + // operations. + IsDataAction *bool `json:"isDataAction,omitempty" azure:"ro"` + + // READ-ONLY; The name of the operation, as per Resource-Based Access Control (RBAC). Examples: "Microsoft.Compute/virtualMachines/write", + // "Microsoft.Compute/virtualMachines/capture/action" + Name *string `json:"name,omitempty" azure:"ro"` + + // READ-ONLY; The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default + // value is "user,system" + Origin *Origin `json:"origin,omitempty" azure:"ro"` +} + +// OperationDisplay - Localized display information for this particular operation. +type OperationDisplay struct { + // READ-ONLY; The short, localized friendly description of the operation; suitable for tool tips and detailed views. + Description *string `json:"description,omitempty" azure:"ro"` + + // READ-ONLY; The concise, localized friendly name for the operation; suitable for dropdowns. E.g. "Create or Update Virtual + // Machine", "Restart Virtual Machine". + Operation *string `json:"operation,omitempty" azure:"ro"` + + // READ-ONLY; The localized friendly form of the resource provider name, e.g. "Microsoft Monitoring Insights" or "Microsoft + // Compute". + Provider *string `json:"provider,omitempty" azure:"ro"` + + // READ-ONLY; The localized friendly name of the resource type related to this operation. E.g. "Virtual Machines" or "Job + // Schedule Collections". + Resource *string `json:"resource,omitempty" azure:"ro"` +} + +// OperationListResult - A list of REST API operations supported by an Azure Resource Provider. It contains an URL link to +// get the next set of results. +type OperationListResult struct { + // READ-ONLY; URL to get the next set of operation list results (if there are any). + NextLink *string `json:"nextLink,omitempty" azure:"ro"` + + // READ-ONLY; List of operations supported by the resource provider + Value []*Operation `json:"value,omitempty" azure:"ro"` +} + +// OperationsClientListOptions contains the optional parameters for the OperationsClient.NewListPager method. +type OperationsClientListOptions struct { + // placeholder for future optional parameters +} + +// SolutionMetadataProperties - Diagnostic solution metadata. +type SolutionMetadataProperties struct { + // A detailed description of solution. + Description *string `json:"description,omitempty"` + + // Required parameters for invoking this particular solution. + RequiredParameterSets [][]*string `json:"requiredParameterSets,omitempty"` + + // Solution Id. + SolutionID *string `json:"solutionId,omitempty"` + + // Solution Type. + SolutionType *string `json:"solutionType,omitempty"` +} + +// SolutionMetadataResource - Solution Metadata resource +type SolutionMetadataResource struct { + // Solution metadata Resource properties. + Properties *SolutionMetadataProperties `json:"properties,omitempty"` + + // READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string `json:"id,omitempty" azure:"ro"` + + // READ-ONLY; The name of the resource + Name *string `json:"name,omitempty" azure:"ro"` + + // READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData `json:"systemData,omitempty" azure:"ro"` + + // READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string `json:"type,omitempty" azure:"ro"` +} + +// SystemData - Metadata pertaining to creation and last modification of the resource. +type SystemData struct { + // The timestamp of resource creation (UTC). + CreatedAt *time.Time `json:"createdAt,omitempty"` + + // The identity that created the resource. + CreatedBy *string `json:"createdBy,omitempty"` + + // The type of identity that created the resource. + CreatedByType *CreatedByType `json:"createdByType,omitempty"` + + // The timestamp of resource last modification (UTC) + LastModifiedAt *time.Time `json:"lastModifiedAt,omitempty"` + + // The identity that last modified the resource. + LastModifiedBy *string `json:"lastModifiedBy,omitempty"` + + // The type of identity that last modified the resource. + LastModifiedByType *CreatedByType `json:"lastModifiedByType,omitempty"` +} diff --git a/sdk/resourcemanager/selfhelp/armselfhelp/models_serde.go b/sdk/resourcemanager/selfhelp/armselfhelp/models_serde.go new file mode 100644 index 000000000000..1c9862f11c18 --- /dev/null +++ b/sdk/resourcemanager/selfhelp/armselfhelp/models_serde.go @@ -0,0 +1,610 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. + +package armselfhelp + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" +) + +// MarshalJSON implements the json.Marshaller interface for type CheckNameAvailabilityRequest. +func (c CheckNameAvailabilityRequest) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "name", c.Name) + populate(objectMap, "type", c.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type CheckNameAvailabilityRequest. +func (c *CheckNameAvailabilityRequest) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "name": + err = unpopulate(val, "Name", &c.Name) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &c.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type CheckNameAvailabilityResponse. +func (c CheckNameAvailabilityResponse) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "message", c.Message) + populate(objectMap, "nameAvailable", c.NameAvailable) + populate(objectMap, "reason", c.Reason) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type CheckNameAvailabilityResponse. +func (c *CheckNameAvailabilityResponse) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "message": + err = unpopulate(val, "Message", &c.Message) + delete(rawMsg, key) + case "nameAvailable": + err = unpopulate(val, "NameAvailable", &c.NameAvailable) + delete(rawMsg, key) + case "reason": + err = unpopulate(val, "Reason", &c.Reason) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type Diagnostic. +func (d Diagnostic) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "error", d.Error) + populate(objectMap, "insights", d.Insights) + populate(objectMap, "solutionId", d.SolutionID) + populate(objectMap, "status", d.Status) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Diagnostic. +func (d *Diagnostic) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", d, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "error": + err = unpopulate(val, "Error", &d.Error) + delete(rawMsg, key) + case "insights": + err = unpopulate(val, "Insights", &d.Insights) + delete(rawMsg, key) + case "solutionId": + err = unpopulate(val, "SolutionID", &d.SolutionID) + delete(rawMsg, key) + case "status": + err = unpopulate(val, "Status", &d.Status) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", d, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type DiagnosticInvocation. +func (d DiagnosticInvocation) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "additionalParameters", d.AdditionalParameters) + populate(objectMap, "solutionId", d.SolutionID) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type DiagnosticInvocation. +func (d *DiagnosticInvocation) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", d, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "additionalParameters": + err = unpopulate(val, "AdditionalParameters", &d.AdditionalParameters) + delete(rawMsg, key) + case "solutionId": + err = unpopulate(val, "SolutionID", &d.SolutionID) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", d, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type DiagnosticResource. +func (d DiagnosticResource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", d.ID) + populate(objectMap, "name", d.Name) + populate(objectMap, "properties", d.Properties) + populate(objectMap, "systemData", d.SystemData) + populate(objectMap, "type", d.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type DiagnosticResource. +func (d *DiagnosticResource) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", d, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &d.ID) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &d.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &d.Properties) + delete(rawMsg, key) + case "systemData": + err = unpopulate(val, "SystemData", &d.SystemData) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &d.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", d, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type DiagnosticResourceProperties. +func (d DiagnosticResourceProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "acceptedAt", d.AcceptedAt) + populate(objectMap, "diagnostics", d.Diagnostics) + populate(objectMap, "globalParameters", d.GlobalParameters) + populate(objectMap, "insights", d.Insights) + populate(objectMap, "provisioningState", d.ProvisioningState) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type DiagnosticResourceProperties. +func (d *DiagnosticResourceProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", d, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "acceptedAt": + err = unpopulate(val, "AcceptedAt", &d.AcceptedAt) + delete(rawMsg, key) + case "diagnostics": + err = unpopulate(val, "Diagnostics", &d.Diagnostics) + delete(rawMsg, key) + case "globalParameters": + err = unpopulate(val, "GlobalParameters", &d.GlobalParameters) + delete(rawMsg, key) + case "insights": + err = unpopulate(val, "Insights", &d.Insights) + delete(rawMsg, key) + case "provisioningState": + err = unpopulate(val, "ProvisioningState", &d.ProvisioningState) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", d, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type DiscoveryResponse. +func (d DiscoveryResponse) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "nextLink", d.NextLink) + populate(objectMap, "value", d.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type DiscoveryResponse. +func (d *DiscoveryResponse) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", d, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "nextLink": + err = unpopulate(val, "NextLink", &d.NextLink) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &d.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", d, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type Error. +func (e Error) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "code", e.Code) + populate(objectMap, "details", e.Details) + populate(objectMap, "message", e.Message) + populate(objectMap, "type", e.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Error. +func (e *Error) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "code": + err = unpopulate(val, "Code", &e.Code) + delete(rawMsg, key) + case "details": + err = unpopulate(val, "Details", &e.Details) + delete(rawMsg, key) + case "message": + err = unpopulate(val, "Message", &e.Message) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &e.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type Insight. +func (i Insight) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", i.ID) + populate(objectMap, "importanceLevel", i.ImportanceLevel) + populate(objectMap, "results", i.Results) + populate(objectMap, "title", i.Title) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Insight. +func (i *Insight) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", i, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &i.ID) + delete(rawMsg, key) + case "importanceLevel": + err = unpopulate(val, "ImportanceLevel", &i.ImportanceLevel) + delete(rawMsg, key) + case "results": + err = unpopulate(val, "Results", &i.Results) + delete(rawMsg, key) + case "title": + err = unpopulate(val, "Title", &i.Title) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", i, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type Operation. +func (o Operation) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "actionType", o.ActionType) + populate(objectMap, "display", o.Display) + populate(objectMap, "isDataAction", o.IsDataAction) + populate(objectMap, "name", o.Name) + populate(objectMap, "origin", o.Origin) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Operation. +func (o *Operation) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "actionType": + err = unpopulate(val, "ActionType", &o.ActionType) + delete(rawMsg, key) + case "display": + err = unpopulate(val, "Display", &o.Display) + delete(rawMsg, key) + case "isDataAction": + err = unpopulate(val, "IsDataAction", &o.IsDataAction) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &o.Name) + delete(rawMsg, key) + case "origin": + err = unpopulate(val, "Origin", &o.Origin) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type OperationDisplay. +func (o OperationDisplay) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "description", o.Description) + populate(objectMap, "operation", o.Operation) + populate(objectMap, "provider", o.Provider) + populate(objectMap, "resource", o.Resource) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type OperationDisplay. +func (o *OperationDisplay) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "description": + err = unpopulate(val, "Description", &o.Description) + delete(rawMsg, key) + case "operation": + err = unpopulate(val, "Operation", &o.Operation) + delete(rawMsg, key) + case "provider": + err = unpopulate(val, "Provider", &o.Provider) + delete(rawMsg, key) + case "resource": + err = unpopulate(val, "Resource", &o.Resource) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type OperationListResult. +func (o OperationListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "nextLink", o.NextLink) + populate(objectMap, "value", o.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type OperationListResult. +func (o *OperationListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "nextLink": + err = unpopulate(val, "NextLink", &o.NextLink) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &o.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type SolutionMetadataProperties. +func (s SolutionMetadataProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "description", s.Description) + populate(objectMap, "requiredParameterSets", s.RequiredParameterSets) + populate(objectMap, "solutionId", s.SolutionID) + populate(objectMap, "solutionType", s.SolutionType) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SolutionMetadataProperties. +func (s *SolutionMetadataProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "description": + err = unpopulate(val, "Description", &s.Description) + delete(rawMsg, key) + case "requiredParameterSets": + err = unpopulate(val, "RequiredParameterSets", &s.RequiredParameterSets) + delete(rawMsg, key) + case "solutionId": + err = unpopulate(val, "SolutionID", &s.SolutionID) + delete(rawMsg, key) + case "solutionType": + err = unpopulate(val, "SolutionType", &s.SolutionType) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type SolutionMetadataResource. +func (s SolutionMetadataResource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", s.ID) + populate(objectMap, "name", s.Name) + populate(objectMap, "properties", s.Properties) + populate(objectMap, "systemData", s.SystemData) + populate(objectMap, "type", s.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SolutionMetadataResource. +func (s *SolutionMetadataResource) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &s.ID) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &s.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &s.Properties) + delete(rawMsg, key) + case "systemData": + err = unpopulate(val, "SystemData", &s.SystemData) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &s.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type SystemData. +func (s SystemData) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populateTimeRFC3339(objectMap, "createdAt", s.CreatedAt) + populate(objectMap, "createdBy", s.CreatedBy) + populate(objectMap, "createdByType", s.CreatedByType) + populateTimeRFC3339(objectMap, "lastModifiedAt", s.LastModifiedAt) + populate(objectMap, "lastModifiedBy", s.LastModifiedBy) + populate(objectMap, "lastModifiedByType", s.LastModifiedByType) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SystemData. +func (s *SystemData) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "createdAt": + err = unpopulateTimeRFC3339(val, "CreatedAt", &s.CreatedAt) + delete(rawMsg, key) + case "createdBy": + err = unpopulate(val, "CreatedBy", &s.CreatedBy) + delete(rawMsg, key) + case "createdByType": + err = unpopulate(val, "CreatedByType", &s.CreatedByType) + delete(rawMsg, key) + case "lastModifiedAt": + err = unpopulateTimeRFC3339(val, "LastModifiedAt", &s.LastModifiedAt) + delete(rawMsg, key) + case "lastModifiedBy": + err = unpopulate(val, "LastModifiedBy", &s.LastModifiedBy) + delete(rawMsg, key) + case "lastModifiedByType": + err = unpopulate(val, "LastModifiedByType", &s.LastModifiedByType) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +func populate(m map[string]any, k string, v any) { + if v == nil { + return + } else if azcore.IsNullValue(v) { + m[k] = nil + } else if !reflect.ValueOf(v).IsNil() { + m[k] = v + } +} + +func unpopulate(data json.RawMessage, fn string, v any) error { + if data == nil { + return nil + } + if err := json.Unmarshal(data, v); err != nil { + return fmt.Errorf("struct field %s: %v", fn, err) + } + return nil +} diff --git a/sdk/resourcemanager/selfhelp/armselfhelp/operations_client.go b/sdk/resourcemanager/selfhelp/armselfhelp/operations_client.go new file mode 100644 index 000000000000..95545a41bfcc --- /dev/null +++ b/sdk/resourcemanager/selfhelp/armselfhelp/operations_client.go @@ -0,0 +1,94 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. + +package armselfhelp + +import ( + "context" + "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" +) + +// OperationsClient contains the methods for the Operations group. +// Don't use this type directly, use NewOperationsClient() instead. +type OperationsClient struct { + internal *arm.Client +} + +// NewOperationsClient creates a new instance of OperationsClient with the specified values. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewOperationsClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*OperationsClient, error) { + cl, err := arm.NewClient(moduleName+".OperationsClient", moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &OperationsClient{ + internal: cl, + } + return client, nil +} + +// NewListPager - Returns list of operations. +// +// Generated from API version 2023-01-01-preview +// - options - OperationsClientListOptions contains the optional parameters for the OperationsClient.NewListPager method. +func (client *OperationsClient) NewListPager(options *OperationsClientListOptions) *runtime.Pager[OperationsClientListResponse] { + return runtime.NewPager(runtime.PagingHandler[OperationsClientListResponse]{ + More: func(page OperationsClientListResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *OperationsClientListResponse) (OperationsClientListResponse, error) { + var req *policy.Request + var err error + if page == nil { + req, err = client.listCreateRequest(ctx, options) + } else { + req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + } + if err != nil { + return OperationsClientListResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return OperationsClientListResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return OperationsClientListResponse{}, runtime.NewResponseError(resp) + } + return client.listHandleResponse(resp) + }, + }) +} + +// listCreateRequest creates the List request. +func (client *OperationsClient) listCreateRequest(ctx context.Context, options *OperationsClientListOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Help/operations" + 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", "2023-01-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listHandleResponse handles the List response. +func (client *OperationsClient) listHandleResponse(resp *http.Response) (OperationsClientListResponse, error) { + result := OperationsClientListResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.OperationListResult); err != nil { + return OperationsClientListResponse{}, err + } + return result, nil +} diff --git a/sdk/resourcemanager/selfhelp/armselfhelp/operations_client_example_test.go b/sdk/resourcemanager/selfhelp/armselfhelp/operations_client_example_test.go new file mode 100644 index 000000000000..58f9a0a9f3c4 --- /dev/null +++ b/sdk/resourcemanager/selfhelp/armselfhelp/operations_client_example_test.go @@ -0,0 +1,66 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. + +package armselfhelp_test + +import ( + "context" + "log" + + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/selfhelp/armselfhelp" +) + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d938a209ffd813aafe13b1899f0a1328fe186c87/specification/help/resource-manager/Microsoft.Help/preview/2023-01-01-preview/examples/ListOperations.json +func ExampleOperationsClient_NewListPager() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armselfhelp.NewClientFactory(cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + pager := clientFactory.NewOperationsClient().NewListPager(nil) + for pager.More() { + page, err := pager.NextPage(ctx) + if err != nil { + log.Fatalf("failed to advance page: %v", err) + } + for _, v := range page.Value { + // You could use page here. We use blank identifier for just demo purposes. + _ = v + } + // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // page.OperationListResult = armselfhelp.OperationListResult{ + // Value: []*armselfhelp.Operation{ + // { + // Name: to.Ptr("Microsoft.Help/diagnostics/read"), + // Display: &armselfhelp.OperationDisplay{ + // Description: to.Ptr("Created and Reads a diagnostic resource to troubleshoot an issue with a resource."), + // Operation: to.Ptr("Create/Read a Diagnostic"), + // Provider: to.Ptr("Microsoft.Diagnostics"), + // Resource: to.Ptr("Diagnostics"), + // }, + // IsDataAction: to.Ptr(false), + // }, + // { + // Name: to.Ptr("Microsoft.Help/discoverySolutions/read"), + // Display: &armselfhelp.OperationDisplay{ + // Description: to.Ptr("Returns list of solutions based on ResourceType or ProblemClassficationId"), + // Operation: to.Ptr("List of available solutions."), + // Provider: to.Ptr("Microsoft.Help"), + // Resource: to.Ptr("DiscoverySolutions"), + // }, + // IsDataAction: to.Ptr(false), + // }}, + // } + } +} diff --git a/sdk/resourcemanager/selfhelp/armselfhelp/response_types.go b/sdk/resourcemanager/selfhelp/armselfhelp/response_types.go new file mode 100644 index 000000000000..894703a93387 --- /dev/null +++ b/sdk/resourcemanager/selfhelp/armselfhelp/response_types.go @@ -0,0 +1,35 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. + +package armselfhelp + +// DiagnosticsClientCheckNameAvailabilityResponse contains the response from method DiagnosticsClient.CheckNameAvailability. +type DiagnosticsClientCheckNameAvailabilityResponse struct { + CheckNameAvailabilityResponse +} + +// DiagnosticsClientCreateResponse contains the response from method DiagnosticsClient.BeginCreate. +type DiagnosticsClientCreateResponse struct { + DiagnosticResource +} + +// DiagnosticsClientGetResponse contains the response from method DiagnosticsClient.Get. +type DiagnosticsClientGetResponse struct { + DiagnosticResource +} + +// DiscoverySolutionClientListResponse contains the response from method DiscoverySolutionClient.NewListPager. +type DiscoverySolutionClientListResponse struct { + DiscoveryResponse +} + +// OperationsClientListResponse contains the response from method OperationsClient.NewListPager. +type OperationsClientListResponse struct { + OperationListResult +} diff --git a/sdk/resourcemanager/selfhelp/armselfhelp/time_rfc3339.go b/sdk/resourcemanager/selfhelp/armselfhelp/time_rfc3339.go new file mode 100644 index 000000000000..9e230ffe26dc --- /dev/null +++ b/sdk/resourcemanager/selfhelp/armselfhelp/time_rfc3339.go @@ -0,0 +1,87 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. + +package armselfhelp + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" + "regexp" + "strings" + "time" +) + +const ( + utcLayoutJSON = `"2006-01-02T15:04:05.999999999"` + utcLayout = "2006-01-02T15:04:05.999999999" + rfc3339JSON = `"` + time.RFC3339Nano + `"` +) + +// 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+)*"*$`) + +type timeRFC3339 time.Time + +func (t timeRFC3339) MarshalJSON() (json []byte, err error) { + tt := time.Time(t) + return tt.MarshalJSON() +} + +func (t timeRFC3339) MarshalText() (text []byte, err error) { + tt := time.Time(t) + return tt.MarshalText() +} + +func (t *timeRFC3339) UnmarshalJSON(data []byte) error { + layout := utcLayoutJSON + if tzOffsetRegex.Match(data) { + layout = rfc3339JSON + } + return t.Parse(layout, string(data)) +} + +func (t *timeRFC3339) UnmarshalText(data []byte) (err error) { + layout := utcLayout + if tzOffsetRegex.Match(data) { + layout = time.RFC3339Nano + } + return t.Parse(layout, string(data)) +} + +func (t *timeRFC3339) Parse(layout, value string) error { + p, err := time.Parse(layout, strings.ToUpper(value)) + *t = timeRFC3339(p) + return err +} + +func populateTimeRFC3339(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] = (*timeRFC3339)(t) +} + +func unpopulateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { + if data == nil || strings.EqualFold(string(data), "null") { + return nil + } + var aux timeRFC3339 + if err := json.Unmarshal(data, &aux); err != nil { + return fmt.Errorf("struct field %s: %v", fn, err) + } + *t = (*time.Time)(&aux) + return nil +}