diff --git a/sdk/resourcemanager/changeanalysis/armchangeanalysis/CHANGELOG.md b/sdk/resourcemanager/changeanalysis/armchangeanalysis/CHANGELOG.md new file mode 100644 index 000000000000..6846c27ffeb7 --- /dev/null +++ b/sdk/resourcemanager/changeanalysis/armchangeanalysis/CHANGELOG.md @@ -0,0 +1,3 @@ +# Release History + +## 0.1.0 (2021-11-24) diff --git a/sdk/resourcemanager/changeanalysis/armchangeanalysis/LICENSE.txt b/sdk/resourcemanager/changeanalysis/armchangeanalysis/LICENSE.txt new file mode 100644 index 000000000000..dc0c2ffb3dc1 --- /dev/null +++ b/sdk/resourcemanager/changeanalysis/armchangeanalysis/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/changeanalysis/armchangeanalysis/README.md b/sdk/resourcemanager/changeanalysis/armchangeanalysis/README.md new file mode 100644 index 000000000000..73736d03f090 --- /dev/null +++ b/sdk/resourcemanager/changeanalysis/armchangeanalysis/README.md @@ -0,0 +1,75 @@ +# Azure Changeanalysis Module for Go + +[![PkgGoDev](https://pkg.go.dev/badge/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/changeanalysis/armchangeanalysis)](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/changeanalysis/armchangeanalysis) + +The `armchangeanalysis` module provides operations for working with Azure Changeanalysis. + +[Source code](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/resourcemanager/changeanalysis/armchangeanalysis) + +# Getting started + +## Prerequisites + +- an [Azure subscription](https://azure.microsoft.com/free/) +- Go 1.13 or above + +## Install the package + +This project uses [Go modules](https://github.com/golang/go/wiki/Modules) for versioning and dependency management. + +Install the Azure Changeanalysis module: + +```sh +go get github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/changeanalysis/armchangeanalysis +``` + +## Authorization + +When creating a client, you will need to provide a credential for authenticating with Azure Changeanalysis. 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). + +## Clients + +Azure Changeanalysis modules consist of one or more clients. A client groups a set of related APIs, providing access to its functionality within the specified subscription. Create one or more clients to access the APIs you require using your credential. + +```go +client := armchangeanalysis.NewChangesClient(, 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{ + Host: arm.AzureChina, +} +client := armchangeanalysis.NewChangesClient(, cred, &options) +``` + +## 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 `Changeanalysis` 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/changeanalysis/armchangeanalysis/autorest.md b/sdk/resourcemanager/changeanalysis/armchangeanalysis/autorest.md new file mode 100644 index 000000000000..d0eb6375e95f --- /dev/null +++ b/sdk/resourcemanager/changeanalysis/armchangeanalysis/autorest.md @@ -0,0 +1,12 @@ +### AutoRest Configuration + +> see https://aka.ms/autorest + +``` yaml +azure-arm: true +require: +- /home/vsts/work/1/s/azure-rest-api-specs/specification/changeanalysis/resource-manager/readme.md +- /home/vsts/work/1/s/azure-rest-api-specs/specification/changeanalysis/resource-manager/readme.go.md +license-header: MICROSOFT_MIT_NO_VERSION +module-version: 0.1.0 +``` \ No newline at end of file diff --git a/sdk/resourcemanager/changeanalysis/armchangeanalysis/build.go b/sdk/resourcemanager/changeanalysis/armchangeanalysis/build.go new file mode 100644 index 000000000000..e46c2cd50ab2 --- /dev/null +++ b/sdk/resourcemanager/changeanalysis/armchangeanalysis/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.exe ../../../../eng/scripts/build.ps1 -skipBuild -cleanGenerated -format -tidy -generate resourcemanager/changeanalysis/armchangeanalysis + +package armchangeanalysis diff --git a/sdk/resourcemanager/changeanalysis/armchangeanalysis/ci.yml b/sdk/resourcemanager/changeanalysis/armchangeanalysis/ci.yml new file mode 100644 index 000000000000..3204456f1df1 --- /dev/null +++ b/sdk/resourcemanager/changeanalysis/armchangeanalysis/ci.yml @@ -0,0 +1,27 @@ +# 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/changeanalysis/armchangeanalysis/ + +pr: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/resourcemanager/changeanalysis/armchangeanalysis/ + +stages: +- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml + parameters: + ServiceDirectory: 'resourcemanager/changeanalysis/armchangeanalysis' diff --git a/sdk/resourcemanager/changeanalysis/armchangeanalysis/go.mod b/sdk/resourcemanager/changeanalysis/armchangeanalysis/go.mod new file mode 100644 index 000000000000..54ba9204ea89 --- /dev/null +++ b/sdk/resourcemanager/changeanalysis/armchangeanalysis/go.mod @@ -0,0 +1,8 @@ +module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/changeanalysis/armchangeanalysis + +go 1.16 + +require ( + github.com/Azure/azure-sdk-for-go v59.3.0+incompatible + github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0 +) diff --git a/sdk/resourcemanager/changeanalysis/armchangeanalysis/go.sum b/sdk/resourcemanager/changeanalysis/armchangeanalysis/go.sum new file mode 100644 index 000000000000..76d3fa8fd576 --- /dev/null +++ b/sdk/resourcemanager/changeanalysis/armchangeanalysis/go.sum @@ -0,0 +1,37 @@ +github.com/Azure/azure-sdk-for-go v59.3.0+incompatible h1:dPIm0BO4jsMXFcCI/sLTPkBtE7mk8WMuRHA0JeWhlcQ= +github.com/Azure/azure-sdk-for-go v59.3.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0 h1:KQgdWmEOmaJKxaUUZwHAYh12t+b+ZJf8q3friycK1kA= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0/go.mod h1:ZPW/Z0kLCTdDZaDbYTetxc9Cxl/2lNqxYHYNOF2bti0= +github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.1 h1:BUYIbDf/mMZ8945v3QkG3OuqGVyS4Iek0AOLwdRAYoc= +github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.1/go.mod h1:KLF4gFr6DcKFZwSuH8w8yEK6DpFl3LP5rhdvAb7Yz5I= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko= +github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210610132358-84b48f89b13b h1:k+E048sYJHyVnsr1GDrRZWQ32D2C7lWs9JRc0bel53A= +golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/sdk/resourcemanager/changeanalysis/armchangeanalysis/go_mod_tidy_hack.go b/sdk/resourcemanager/changeanalysis/armchangeanalysis/go_mod_tidy_hack.go new file mode 100644 index 000000000000..51a9548b22e2 --- /dev/null +++ b/sdk/resourcemanager/changeanalysis/armchangeanalysis/go_mod_tidy_hack.go @@ -0,0 +1,13 @@ +//go:build modhack +// +build modhack + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +// This file, and the github.com/Azure/azure-sdk-for-go import, won't actually become part of +// the resultant binary. + +package armchangeanalysis + +// Necessary for safely adding multi-module repo. See: https://github.com/golang/go/wiki/Modules#is-it-possible-to-add-a-module-to-a-multi-module-repository +import _ "github.com/Azure/azure-sdk-for-go" diff --git a/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_changes_client.go b/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_changes_client.go new file mode 100644 index 000000000000..8090ecb3c301 --- /dev/null +++ b/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_changes_client.go @@ -0,0 +1,166 @@ +//go:build go1.16 +// +build go1.16 + +// 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. + +package armchangeanalysis + +import ( + "context" + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "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" + "time" +) + +// ChangesClient contains the methods for the Changes group. +// Don't use this type directly, use NewChangesClient() instead. +type ChangesClient struct { + ep string + pl runtime.Pipeline + subscriptionID string +} + +// NewChangesClient creates a new instance of ChangesClient with the specified values. +func NewChangesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) *ChangesClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &ChangesClient{subscriptionID: subscriptionID, ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// ListChangesByResourceGroup - List the changes of a resource group within the specified time range. Customer data will always be masked. +// If the operation fails it returns the *ErrorResponse error type. +func (client *ChangesClient) ListChangesByResourceGroup(resourceGroupName string, startTime time.Time, endTime time.Time, options *ChangesListChangesByResourceGroupOptions) *ChangesListChangesByResourceGroupPager { + return &ChangesListChangesByResourceGroupPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listChangesByResourceGroupCreateRequest(ctx, resourceGroupName, startTime, endTime, options) + }, + advancer: func(ctx context.Context, resp ChangesListChangesByResourceGroupResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.ChangeList.NextLink) + }, + } +} + +// listChangesByResourceGroupCreateRequest creates the ListChangesByResourceGroup request. +func (client *ChangesClient) listChangesByResourceGroupCreateRequest(ctx context.Context, resourceGroupName string, startTime time.Time, endTime time.Time, options *ChangesListChangesByResourceGroupOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ChangeAnalysis/changes" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-04-01") + reqQP.Set("$startTime", startTime.Format(time.RFC3339Nano)) + reqQP.Set("$endTime", endTime.Format(time.RFC3339Nano)) + if options != nil && options.SkipToken != nil { + reqQP.Set("$skipToken", *options.SkipToken) + } + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listChangesByResourceGroupHandleResponse handles the ListChangesByResourceGroup response. +func (client *ChangesClient) listChangesByResourceGroupHandleResponse(resp *http.Response) (ChangesListChangesByResourceGroupResponse, error) { + result := ChangesListChangesByResourceGroupResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ChangeList); err != nil { + return ChangesListChangesByResourceGroupResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// listChangesByResourceGroupHandleError handles the ListChangesByResourceGroup error response. +func (client *ChangesClient) listChangesByResourceGroupHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// ListChangesBySubscription - List the changes of a subscription within the specified time range. Customer data will always be masked. +// If the operation fails it returns the *ErrorResponse error type. +func (client *ChangesClient) ListChangesBySubscription(startTime time.Time, endTime time.Time, options *ChangesListChangesBySubscriptionOptions) *ChangesListChangesBySubscriptionPager { + return &ChangesListChangesBySubscriptionPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listChangesBySubscriptionCreateRequest(ctx, startTime, endTime, options) + }, + advancer: func(ctx context.Context, resp ChangesListChangesBySubscriptionResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.ChangeList.NextLink) + }, + } +} + +// listChangesBySubscriptionCreateRequest creates the ListChangesBySubscription request. +func (client *ChangesClient) listChangesBySubscriptionCreateRequest(ctx context.Context, startTime time.Time, endTime time.Time, options *ChangesListChangesBySubscriptionOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.ChangeAnalysis/changes" + 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.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-04-01") + reqQP.Set("$startTime", startTime.Format(time.RFC3339Nano)) + reqQP.Set("$endTime", endTime.Format(time.RFC3339Nano)) + if options != nil && options.SkipToken != nil { + reqQP.Set("$skipToken", *options.SkipToken) + } + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listChangesBySubscriptionHandleResponse handles the ListChangesBySubscription response. +func (client *ChangesClient) listChangesBySubscriptionHandleResponse(resp *http.Response) (ChangesListChangesBySubscriptionResponse, error) { + result := ChangesListChangesBySubscriptionResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ChangeList); err != nil { + return ChangesListChangesBySubscriptionResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// listChangesBySubscriptionHandleError handles the ListChangesBySubscription error response. +func (client *ChangesClient) listChangesBySubscriptionHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_constants.go b/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_constants.go new file mode 100644 index 000000000000..801c76badd77 --- /dev/null +++ b/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_constants.go @@ -0,0 +1,80 @@ +//go:build go1.16 +// +build go1.16 + +// 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. + +package armchangeanalysis + +const ( + module = "armchangeanalysis" + version = "v0.1.0" +) + +// ChangeCategory - The change category. +type ChangeCategory string + +const ( + ChangeCategoryUser ChangeCategory = "User" + ChangeCategorySystem ChangeCategory = "System" +) + +// PossibleChangeCategoryValues returns the possible values for the ChangeCategory const type. +func PossibleChangeCategoryValues() []ChangeCategory { + return []ChangeCategory{ + ChangeCategoryUser, + ChangeCategorySystem, + } +} + +// ToPtr returns a *ChangeCategory pointing to the current value. +func (c ChangeCategory) ToPtr() *ChangeCategory { + return &c +} + +// ChangeType - The type of the change. +type ChangeType string + +const ( + ChangeTypeAdd ChangeType = "Add" + ChangeTypeRemove ChangeType = "Remove" + ChangeTypeUpdate ChangeType = "Update" +) + +// PossibleChangeTypeValues returns the possible values for the ChangeType const type. +func PossibleChangeTypeValues() []ChangeType { + return []ChangeType{ + ChangeTypeAdd, + ChangeTypeRemove, + ChangeTypeUpdate, + } +} + +// ToPtr returns a *ChangeType pointing to the current value. +func (c ChangeType) ToPtr() *ChangeType { + return &c +} + +type Level string + +const ( + LevelImportant Level = "Important" + LevelNoisy Level = "Noisy" + LevelNormal Level = "Normal" +) + +// PossibleLevelValues returns the possible values for the Level const type. +func PossibleLevelValues() []Level { + return []Level{ + LevelImportant, + LevelNoisy, + LevelNormal, + } +} + +// ToPtr returns a *Level pointing to the current value. +func (c Level) ToPtr() *Level { + return &c +} diff --git a/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_models.go b/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_models.go new file mode 100644 index 000000000000..1163e485a287 --- /dev/null +++ b/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_models.go @@ -0,0 +1,286 @@ +//go:build go1.16 +// +build go1.16 + +// 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. + +package armchangeanalysis + +import ( + "encoding/json" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" + "time" +) + +// Change - The detected change. +type Change struct { + ProxyResource + // The properties of a change. + Properties *ChangeProperties `json:"properties,omitempty"` +} + +// ChangeList - The list of detected changes. +type ChangeList struct { + // The URI that can be used to request the next page of changes. + NextLink *string `json:"nextLink,omitempty"` + + // The list of changes. + Value []*Change `json:"value,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ChangeList. +func (c ChangeList) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", c.NextLink) + populate(objectMap, "value", c.Value) + return json.Marshal(objectMap) +} + +// ChangeProperties - The properties of a change. +type ChangeProperties struct { + // The type of the change. + ChangeType *ChangeType `json:"changeType,omitempty"` + + // The list of identities who might initiated the change. The identity could be user name (email address) or the object ID of the Service Principal. + InitiatedByList []*string `json:"initiatedByList,omitempty"` + + // The list of detailed changes at json property level. + PropertyChanges []*PropertyChange `json:"propertyChanges,omitempty"` + + // The resource id that the change is attached to. + ResourceID *string `json:"resourceId,omitempty"` + + // The time when the change is detected. + TimeStamp *time.Time `json:"timeStamp,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ChangeProperties. +func (c ChangeProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "changeType", c.ChangeType) + populate(objectMap, "initiatedByList", c.InitiatedByList) + populate(objectMap, "propertyChanges", c.PropertyChanges) + populate(objectMap, "resourceId", c.ResourceID) + populateTimeRFC3339(objectMap, "timeStamp", c.TimeStamp) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ChangeProperties. +func (c *ChangeProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "changeType": + err = unpopulate(val, &c.ChangeType) + delete(rawMsg, key) + case "initiatedByList": + err = unpopulate(val, &c.InitiatedByList) + delete(rawMsg, key) + case "propertyChanges": + err = unpopulate(val, &c.PropertyChanges) + delete(rawMsg, key) + case "resourceId": + err = unpopulate(val, &c.ResourceID) + delete(rawMsg, key) + case "timeStamp": + err = unpopulateTimeRFC3339(val, &c.TimeStamp) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// ChangesListChangesByResourceGroupOptions contains the optional parameters for the Changes.ListChangesByResourceGroup method. +type ChangesListChangesByResourceGroupOptions struct { + // A skip token is used to continue retrieving items after an operation returns 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 +} + +// ChangesListChangesBySubscriptionOptions contains the optional parameters for the Changes.ListChangesBySubscription method. +type ChangesListChangesBySubscriptionOptions struct { + // A skip token is used to continue retrieving items after an operation returns 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 +} + +// ErrorAdditionalInfo - The resource management error additional info. +type ErrorAdditionalInfo struct { + // READ-ONLY; The additional info. + Info map[string]interface{} `json:"info,omitempty" azure:"ro"` + + // READ-ONLY; The additional info type. + Type *string `json:"type,omitempty" azure:"ro"` +} + +// ErrorDetail - The error detail. +type ErrorDetail struct { + // READ-ONLY; The error additional info. + AdditionalInfo []*ErrorAdditionalInfo `json:"additionalInfo,omitempty" azure:"ro"` + + // READ-ONLY; The error code. + Code *string `json:"code,omitempty" azure:"ro"` + + // READ-ONLY; The error details. + Details []*ErrorDetail `json:"details,omitempty" azure:"ro"` + + // READ-ONLY; The error message. + Message *string `json:"message,omitempty" azure:"ro"` + + // READ-ONLY; The error target. + Target *string `json:"target,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ErrorDetail. +func (e ErrorDetail) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "additionalInfo", e.AdditionalInfo) + populate(objectMap, "code", e.Code) + populate(objectMap, "details", e.Details) + populate(objectMap, "message", e.Message) + populate(objectMap, "target", e.Target) + return json.Marshal(objectMap) +} + +// ErrorResponse - Common error response for all Azure Resource Manager APIs to return error details for failed operations. (This also follows the OData +// error response format.). +// Implements the error and azcore.HTTPResponse interfaces. +type ErrorResponse struct { + raw string + // The error object. + InnerError *ErrorDetail `json:"error,omitempty"` +} + +// Error implements the error interface for type ErrorResponse. +// The contents of the error text are not contractual and subject to change. +func (e ErrorResponse) Error() string { + return e.raw +} + +// OperationsListOptions contains the optional parameters for the Operations.List method. +type OperationsListOptions struct { + // A skip token is used to continue retrieving items after an operation returns 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 +} + +// PropertyChange - Data of a property change. +type PropertyChange struct { + // The change category. + ChangeCategory *ChangeCategory `json:"changeCategory,omitempty"` + + // The type of the change. + ChangeType *ChangeType `json:"changeType,omitempty"` + + // The description of the changed property. + Description *string `json:"description,omitempty"` + + // The enhanced display name of the json path. E.g., the json path value[0].properties will be translated to something meaningful like slots["Staging"].properties. + DisplayName *string `json:"displayName,omitempty"` + + // The boolean indicating whether the oldValue and newValue are masked. The values are masked if it contains sensitive information that the user doesn't + // have access to. + IsDataMasked *bool `json:"isDataMasked,omitempty"` + + // The json path of the changed property. + JSONPath *string `json:"jsonPath,omitempty"` + Level *Level `json:"level,omitempty"` + + // The value of the property after the change. + NewValue *string `json:"newValue,omitempty"` + + // The value of the property before the change. + OldValue *string `json:"oldValue,omitempty"` +} + +// ProxyResource - The resource model definition for a Azure Resource Manager proxy resource. It will not have tags and a location +type ProxyResource struct { + Resource +} + +// Resource - Common fields that are returned in the response for all Azure Resource Manager resources +type Resource struct { + // 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; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string `json:"type,omitempty" azure:"ro"` +} + +// ResourceChangesListOptions contains the optional parameters for the ResourceChanges.List method. +type ResourceChangesListOptions struct { + // A skip token is used to continue retrieving items after an operation returns 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 +} + +// ResourceProviderOperationDefinition - The resource provider operation definition. +type ResourceProviderOperationDefinition struct { + // The resource provider operation details. + Display *ResourceProviderOperationDisplay `json:"display,omitempty"` + + // The resource provider operation name. + Name *string `json:"name,omitempty"` +} + +// ResourceProviderOperationDisplay - The resource provider operation details. +type ResourceProviderOperationDisplay struct { + // Description of the resource provider operation. + Description *string `json:"description,omitempty"` + + // Name of the resource provider operation. + Operation *string `json:"operation,omitempty"` + + // Name of the resource provider. + Provider *string `json:"provider,omitempty"` + + // Name of the resource type. + Resource *string `json:"resource,omitempty"` +} + +// ResourceProviderOperationList - The resource provider operation list. +type ResourceProviderOperationList struct { + // The URI that can be used to request the next page for list of Azure operations. + NextLink *string `json:"nextLink,omitempty"` + + // Resource provider operations list. + Value []*ResourceProviderOperationDefinition `json:"value,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ResourceProviderOperationList. +func (r ResourceProviderOperationList) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", r.NextLink) + populate(objectMap, "value", r.Value) + return json.Marshal(objectMap) +} + +func populate(m map[string]interface{}, k string, v interface{}) { + 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, v interface{}) error { + if data == nil { + return nil + } + return json.Unmarshal(data, v) +} diff --git a/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_operations_client.go b/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_operations_client.go new file mode 100644 index 000000000000..cf4669cb10c0 --- /dev/null +++ b/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_operations_client.go @@ -0,0 +1,92 @@ +//go:build go1.16 +// +build go1.16 + +// 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. + +package armchangeanalysis + +import ( + "context" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "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 { + ep string + pl runtime.Pipeline +} + +// NewOperationsClient creates a new instance of OperationsClient with the specified values. +func NewOperationsClient(credential azcore.TokenCredential, options *arm.ClientOptions) *OperationsClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &OperationsClient{ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// List - Lists all the supported operations by the Microsoft.ChangeAnalysis resource provider along with their descriptions. +// If the operation fails it returns the *ErrorResponse error type. +func (client *OperationsClient) List(options *OperationsListOptions) *OperationsListPager { + return &OperationsListPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listCreateRequest(ctx, options) + }, + advancer: func(ctx context.Context, resp OperationsListResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.ResourceProviderOperationList.NextLink) + }, + } +} + +// listCreateRequest creates the List request. +func (client *OperationsClient) listCreateRequest(ctx context.Context, options *OperationsListOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.ChangeAnalysis/operations" + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-04-01") + if options != nil && options.SkipToken != nil { + reqQP.Set("$skipToken", *options.SkipToken) + } + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listHandleResponse handles the List response. +func (client *OperationsClient) listHandleResponse(resp *http.Response) (OperationsListResponse, error) { + result := OperationsListResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ResourceProviderOperationList); err != nil { + return OperationsListResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// listHandleError handles the List error response. +func (client *OperationsClient) listHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_pagers.go b/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_pagers.go new file mode 100644 index 000000000000..fb4c3b938c15 --- /dev/null +++ b/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_pagers.go @@ -0,0 +1,233 @@ +//go:build go1.16 +// +build go1.16 + +// 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. + +package armchangeanalysis + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "reflect" +) + +// ChangesListChangesByResourceGroupPager provides operations for iterating over paged responses. +type ChangesListChangesByResourceGroupPager struct { + client *ChangesClient + current ChangesListChangesByResourceGroupResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, ChangesListChangesByResourceGroupResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *ChangesListChangesByResourceGroupPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *ChangesListChangesByResourceGroupPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.ChangeList.NextLink == nil || len(*p.current.ChangeList.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listChangesByResourceGroupHandleError(resp) + return false + } + result, err := p.client.listChangesByResourceGroupHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current ChangesListChangesByResourceGroupResponse page. +func (p *ChangesListChangesByResourceGroupPager) PageResponse() ChangesListChangesByResourceGroupResponse { + return p.current +} + +// ChangesListChangesBySubscriptionPager provides operations for iterating over paged responses. +type ChangesListChangesBySubscriptionPager struct { + client *ChangesClient + current ChangesListChangesBySubscriptionResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, ChangesListChangesBySubscriptionResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *ChangesListChangesBySubscriptionPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *ChangesListChangesBySubscriptionPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.ChangeList.NextLink == nil || len(*p.current.ChangeList.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listChangesBySubscriptionHandleError(resp) + return false + } + result, err := p.client.listChangesBySubscriptionHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current ChangesListChangesBySubscriptionResponse page. +func (p *ChangesListChangesBySubscriptionPager) PageResponse() ChangesListChangesBySubscriptionResponse { + return p.current +} + +// OperationsListPager provides operations for iterating over paged responses. +type OperationsListPager struct { + client *OperationsClient + current OperationsListResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, OperationsListResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *OperationsListPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *OperationsListPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.ResourceProviderOperationList.NextLink == nil || len(*p.current.ResourceProviderOperationList.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listHandleError(resp) + return false + } + result, err := p.client.listHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current OperationsListResponse page. +func (p *OperationsListPager) PageResponse() OperationsListResponse { + return p.current +} + +// ResourceChangesListPager provides operations for iterating over paged responses. +type ResourceChangesListPager struct { + client *ResourceChangesClient + current ResourceChangesListResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, ResourceChangesListResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *ResourceChangesListPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *ResourceChangesListPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.ChangeList.NextLink == nil || len(*p.current.ChangeList.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listHandleError(resp) + return false + } + result, err := p.client.listHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current ResourceChangesListResponse page. +func (p *ResourceChangesListPager) PageResponse() ResourceChangesListResponse { + return p.current +} diff --git a/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_resourcechanges_client.go b/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_resourcechanges_client.go new file mode 100644 index 000000000000..e218bc560472 --- /dev/null +++ b/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_resourcechanges_client.go @@ -0,0 +1,102 @@ +//go:build go1.16 +// +build go1.16 + +// 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. + +package armchangeanalysis + +import ( + "context" + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "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" + "time" +) + +// ResourceChangesClient contains the methods for the ResourceChanges group. +// Don't use this type directly, use NewResourceChangesClient() instead. +type ResourceChangesClient struct { + ep string + pl runtime.Pipeline +} + +// NewResourceChangesClient creates a new instance of ResourceChangesClient with the specified values. +func NewResourceChangesClient(credential azcore.TokenCredential, options *arm.ClientOptions) *ResourceChangesClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &ResourceChangesClient{ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// List - List the changes of a resource within the specified time range. Customer data will be masked if the user doesn't have access. +// If the operation fails it returns the *ErrorResponse error type. +func (client *ResourceChangesClient) List(resourceID string, startTime time.Time, endTime time.Time, options *ResourceChangesListOptions) *ResourceChangesListPager { + return &ResourceChangesListPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listCreateRequest(ctx, resourceID, startTime, endTime, options) + }, + advancer: func(ctx context.Context, resp ResourceChangesListResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.ChangeList.NextLink) + }, + } +} + +// listCreateRequest creates the List request. +func (client *ResourceChangesClient) listCreateRequest(ctx context.Context, resourceID string, startTime time.Time, endTime time.Time, options *ResourceChangesListOptions) (*policy.Request, error) { + urlPath := "/{resourceId}/providers/Microsoft.ChangeAnalysis/resourceChanges" + if resourceID == "" { + return nil, errors.New("parameter resourceID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceId}", url.PathEscape(resourceID)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-04-01") + reqQP.Set("$startTime", startTime.Format(time.RFC3339Nano)) + reqQP.Set("$endTime", endTime.Format(time.RFC3339Nano)) + if options != nil && options.SkipToken != nil { + reqQP.Set("$skipToken", *options.SkipToken) + } + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listHandleResponse handles the List response. +func (client *ResourceChangesClient) listHandleResponse(resp *http.Response) (ResourceChangesListResponse, error) { + result := ResourceChangesListResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ChangeList); err != nil { + return ResourceChangesListResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// listHandleError handles the List error response. +func (client *ResourceChangesClient) listHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_response_types.go b/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_response_types.go new file mode 100644 index 000000000000..e995ce93f1e4 --- /dev/null +++ b/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_response_types.go @@ -0,0 +1,59 @@ +//go:build go1.16 +// +build go1.16 + +// 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. + +package armchangeanalysis + +import "net/http" + +// ChangesListChangesByResourceGroupResponse contains the response from method Changes.ListChangesByResourceGroup. +type ChangesListChangesByResourceGroupResponse struct { + ChangesListChangesByResourceGroupResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ChangesListChangesByResourceGroupResult contains the result from method Changes.ListChangesByResourceGroup. +type ChangesListChangesByResourceGroupResult struct { + ChangeList +} + +// ChangesListChangesBySubscriptionResponse contains the response from method Changes.ListChangesBySubscription. +type ChangesListChangesBySubscriptionResponse struct { + ChangesListChangesBySubscriptionResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ChangesListChangesBySubscriptionResult contains the result from method Changes.ListChangesBySubscription. +type ChangesListChangesBySubscriptionResult struct { + ChangeList +} + +// OperationsListResponse contains the response from method Operations.List. +type OperationsListResponse struct { + OperationsListResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// OperationsListResult contains the result from method Operations.List. +type OperationsListResult struct { + ResourceProviderOperationList +} + +// ResourceChangesListResponse contains the response from method ResourceChanges.List. +type ResourceChangesListResponse struct { + ResourceChangesListResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ResourceChangesListResult contains the result from method ResourceChanges.List. +type ResourceChangesListResult struct { + ChangeList +} diff --git a/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_time_rfc3339.go b/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_time_rfc3339.go new file mode 100644 index 000000000000..3e10e54fab23 --- /dev/null +++ b/sdk/resourcemanager/changeanalysis/armchangeanalysis/zz_generated_time_rfc3339.go @@ -0,0 +1,85 @@ +//go:build go1.16 +// +build go1.16 + +// 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. + +package armchangeanalysis + +import ( + "encoding/json" + "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]interface{}, 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, 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 err + } + *t = (*time.Time)(&aux) + return nil +}