Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ if model := read.Model; model != nil {
ctx := context.TODO()
id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012")

read, err := client.CreationSupportedList(ctx, id, createresource.DefaultCreationSupportedListOperationOptions())
// alternatively `client.CreationSupportedList(ctx, id, createresource.DefaultCreationSupportedListOperationOptions())` can be used to do batched pagination
items, err := client.CreationSupportedListComplete(ctx, id, createresource.DefaultCreationSupportedListOperationOptions())
if err != nil {
// handle the error
}
if model := read.Model; model != nil {
// do something with the model/response object
for _, item := range items {
// do something
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import (
type CreationSupportedListOperationResponse struct {
HttpResponse *http.Response
OData *odata.OData
Model *CreateResourceSupportedResponseList
Model *[]CreateResourceSupportedResponse
}

type CreationSupportedListCompleteResult struct {
LatestHttpResponse *http.Response
Items []CreateResourceSupportedResponse
}

type CreationSupportedListOperationOptions struct {
Expand Down Expand Up @@ -47,6 +52,18 @@ func (o CreationSupportedListOperationOptions) ToQuery() *client.QueryParams {
return &out
}

type CreationSupportedListCustomPager struct {
NextLink *odata.Link `json:"nextLink"`
}

func (p *CreationSupportedListCustomPager) NextPageLink() *odata.Link {
defer func() {
p.NextLink = nil
}()

return p.NextLink
}

// CreationSupportedList ...
func (c CreateResourceClient) CreationSupportedList(ctx context.Context, id commonids.SubscriptionId, options CreationSupportedListOperationOptions) (result CreationSupportedListOperationResponse, err error) {
opts := client.RequestOptions{
Expand All @@ -56,6 +73,7 @@ func (c CreateResourceClient) CreationSupportedList(ctx context.Context, id comm
},
HttpMethod: http.MethodGet,
OptionsObject: options,
Pager: &CreationSupportedListCustomPager{},
Path: fmt.Sprintf("%s/providers/Microsoft.Datadog/subscriptionStatuses", id.ID()),
}

Expand All @@ -65,7 +83,7 @@ func (c CreateResourceClient) CreationSupportedList(ctx context.Context, id comm
}

var resp *client.Response
resp, err = req.Execute(ctx)
resp, err = req.ExecutePaged(ctx)
if resp != nil {
result.OData = resp.OData
result.HttpResponse = resp.Response
Expand All @@ -74,11 +92,44 @@ func (c CreateResourceClient) CreationSupportedList(ctx context.Context, id comm
return
}

var model CreateResourceSupportedResponseList
result.Model = &model
if err = resp.Unmarshal(result.Model); err != nil {
var values struct {
Values *[]CreateResourceSupportedResponse `json:"value"`
}
if err = resp.Unmarshal(&values); err != nil {
return
}

result.Model = values.Values

return
}

// CreationSupportedListComplete retrieves all the results into a single object
func (c CreateResourceClient) CreationSupportedListComplete(ctx context.Context, id commonids.SubscriptionId, options CreationSupportedListOperationOptions) (CreationSupportedListCompleteResult, error) {
return c.CreationSupportedListCompleteMatchingPredicate(ctx, id, options, CreateResourceSupportedResponseOperationPredicate{})
}

// CreationSupportedListCompleteMatchingPredicate retrieves all the results and then applies the predicate
func (c CreateResourceClient) CreationSupportedListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options CreationSupportedListOperationOptions, predicate CreateResourceSupportedResponseOperationPredicate) (result CreationSupportedListCompleteResult, err error) {
items := make([]CreateResourceSupportedResponse, 0)

resp, err := c.CreationSupportedList(ctx, id, options)
if err != nil {
result.LatestHttpResponse = resp.HttpResponse
err = fmt.Errorf("loading results: %+v", err)
return
}
if resp.Model != nil {
for _, v := range *resp.Model {
if predicate.Matches(v) {
items = append(items, v)
}
}
}

result = CreationSupportedListCompleteResult{
LatestHttpResponse: resp.HttpResponse,
Items: items,
}
return
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package createresource

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See NOTICE.txt in the project root for license information.

type CreateResourceSupportedResponseOperationPredicate struct {
}

func (p CreateResourceSupportedResponseOperationPredicate) Matches(input CreateResourceSupportedResponse) bool {

return true
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ if model := read.Model; model != nil {
ctx := context.TODO()
id := monitoredsubscriptions.NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName")

read, err := client.List(ctx, id)
// alternatively `client.List(ctx, id)` can be used to do batched pagination
items, err := client.ListComplete(ctx, id)
if err != nil {
// handle the error
}
if model := read.Model; model != nil {
// do something with the model/response object
for _, item := range items {
// do something
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,24 @@ import (
type ListOperationResponse struct {
HttpResponse *http.Response
OData *odata.OData
Model *MonitoredSubscriptionPropertiesList
Model *[]MonitoredSubscriptionProperties
}

type ListCompleteResult struct {
LatestHttpResponse *http.Response
Items []MonitoredSubscriptionProperties
}

type ListCustomPager struct {
NextLink *odata.Link `json:"nextLink"`
}

func (p *ListCustomPager) NextPageLink() *odata.Link {
defer func() {
p.NextLink = nil
}()

return p.NextLink
}

// List ...
Expand All @@ -26,6 +43,7 @@ func (c MonitoredSubscriptionsClient) List(ctx context.Context, id MonitorId) (r
http.StatusOK,
},
HttpMethod: http.MethodGet,
Pager: &ListCustomPager{},
Path: fmt.Sprintf("%s/monitoredSubscriptions", id.ID()),
}

Expand All @@ -35,7 +53,7 @@ func (c MonitoredSubscriptionsClient) List(ctx context.Context, id MonitorId) (r
}

var resp *client.Response
resp, err = req.Execute(ctx)
resp, err = req.ExecutePaged(ctx)
if resp != nil {
result.OData = resp.OData
result.HttpResponse = resp.Response
Expand All @@ -44,11 +62,44 @@ func (c MonitoredSubscriptionsClient) List(ctx context.Context, id MonitorId) (r
return
}

var model MonitoredSubscriptionPropertiesList
result.Model = &model
if err = resp.Unmarshal(result.Model); err != nil {
var values struct {
Values *[]MonitoredSubscriptionProperties `json:"value"`
}
if err = resp.Unmarshal(&values); err != nil {
return
}

result.Model = values.Values

return
}

// ListComplete retrieves all the results into a single object
func (c MonitoredSubscriptionsClient) ListComplete(ctx context.Context, id MonitorId) (ListCompleteResult, error) {
return c.ListCompleteMatchingPredicate(ctx, id, MonitoredSubscriptionPropertiesOperationPredicate{})
}

// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate
func (c MonitoredSubscriptionsClient) ListCompleteMatchingPredicate(ctx context.Context, id MonitorId, predicate MonitoredSubscriptionPropertiesOperationPredicate) (result ListCompleteResult, err error) {
items := make([]MonitoredSubscriptionProperties, 0)

resp, err := c.List(ctx, id)
if err != nil {
result.LatestHttpResponse = resp.HttpResponse
err = fmt.Errorf("loading results: %+v", err)
return
}
if resp.Model != nil {
for _, v := range *resp.Model {
if predicate.Matches(v) {
items = append(items, v)
}
}
}

result = ListCompleteResult{
LatestHttpResponse: resp.HttpResponse,
Items: items,
}
return
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package monitoredsubscriptions

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See NOTICE.txt in the project root for license information.

type MonitoredSubscriptionPropertiesOperationPredicate struct {
Id *string
Name *string
Type *string
}

func (p MonitoredSubscriptionPropertiesOperationPredicate) Matches(input MonitoredSubscriptionProperties) bool {

if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) {
return false
}

if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) {
return false
}

if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) {
return false
}

return true
}
59 changes: 59 additions & 0 deletions resource-manager/datadog/2023-10-20/agreements/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

## `github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/agreements` Documentation

The `agreements` SDK allows for interaction with Azure Resource Manager `datadog` (API Version `2023-10-20`).

This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs).

### Import Path

```go
import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
import "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/agreements"
```


### Client Initialization

```go
client := agreements.NewAgreementsClientWithBaseURI("https://management.azure.com")
client.Client.Authorizer = authorizer
```


### Example Usage: `AgreementsClient.MarketplaceAgreementsCreateOrUpdate`

```go
ctx := context.TODO()
id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012")

payload := agreements.DatadogAgreementResource{
// ...
}


read, err := client.MarketplaceAgreementsCreateOrUpdate(ctx, id, payload)
if err != nil {
// handle the error
}
if model := read.Model; model != nil {
// do something with the model/response object
}
```


### Example Usage: `AgreementsClient.MarketplaceAgreementsList`

```go
ctx := context.TODO()
id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012")

// alternatively `client.MarketplaceAgreementsList(ctx, id)` can be used to do batched pagination
items, err := client.MarketplaceAgreementsListComplete(ctx, id)
if err != nil {
// handle the error
}
for _, item := range items {
// do something
}
```
26 changes: 26 additions & 0 deletions resource-manager/datadog/2023-10-20/agreements/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package agreements

import (
"fmt"

"github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager"
sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments"
)

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See NOTICE.txt in the project root for license information.

type AgreementsClient struct {
Client *resourcemanager.Client
}

func NewAgreementsClientWithBaseURI(sdkApi sdkEnv.Api) (*AgreementsClient, error) {
client, err := resourcemanager.NewClient(sdkApi, "agreements", defaultApiVersion)
if err != nil {
return nil, fmt.Errorf("instantiating AgreementsClient: %+v", err)
}

return &AgreementsClient{
Client: client,
}, nil
}
Loading
Loading