Skip to content

Commit

Permalink
Updating based on e21d38ad4
Browse files Browse the repository at this point in the history
  • Loading branch information
hc-github-team-tf-azure committed Jan 31, 2024
1 parent 724037f commit 4c2f693
Show file tree
Hide file tree
Showing 1,911 changed files with 140,778 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies` Documentation

The `backupshorttermretentionpolicies` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`).

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-sdk/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies"
```


### Client Initialization

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


### Example Usage: `BackupShortTermRetentionPoliciesClient.CreateOrUpdate`

```go
ctx := context.TODO()
id := backupshorttermretentionpolicies.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue")

payload := backupshorttermretentionpolicies.BackupShortTermRetentionPolicy{
// ...
}


if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil {
// handle the error
}
```


### Example Usage: `BackupShortTermRetentionPoliciesClient.Get`

```go
ctx := context.TODO()
id := backupshorttermretentionpolicies.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue")

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


### Example Usage: `BackupShortTermRetentionPoliciesClient.ListByDatabase`

```go
ctx := context.TODO()
id := backupshorttermretentionpolicies.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue")

// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination
items, err := client.ListByDatabaseComplete(ctx, id)
if err != nil {
// handle the error
}
for _, item := range items {
// do something
}
```


### Example Usage: `BackupShortTermRetentionPoliciesClient.Update`

```go
ctx := context.TODO()
id := backupshorttermretentionpolicies.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue")

payload := backupshorttermretentionpolicies.BackupShortTermRetentionPolicy{
// ...
}


if err := client.UpdateThenPoll(ctx, id, payload); err != nil {
// handle the error
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package backupshorttermretentionpolicies

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 BackupShortTermRetentionPoliciesClient struct {
Client *resourcemanager.Client
}

func NewBackupShortTermRetentionPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*BackupShortTermRetentionPoliciesClient, error) {
client, err := resourcemanager.NewResourceManagerClient(sdkApi, "backupshorttermretentionpolicies", defaultApiVersion)
if err != nil {
return nil, fmt.Errorf("instantiating BackupShortTermRetentionPoliciesClient: %+v", err)
}

return &BackupShortTermRetentionPoliciesClient{
Client: client,
}, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package backupshorttermretentionpolicies

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

type DiffBackupIntervalInHours int64

const (
DiffBackupIntervalInHoursOneTwo DiffBackupIntervalInHours = 12
DiffBackupIntervalInHoursTwoFour DiffBackupIntervalInHours = 24
)

func PossibleValuesForDiffBackupIntervalInHours() []int64 {
return []int64{
int64(DiffBackupIntervalInHoursOneTwo),
int64(DiffBackupIntervalInHoursTwoFour),
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package backupshorttermretentionpolicies

import (
"context"
"fmt"
"net/http"

"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-sdk/sdk/client"
"github.com/hashicorp/go-azure-sdk/sdk/client/pollers"
"github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager"
"github.com/hashicorp/go-azure-sdk/sdk/odata"
)

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

type CreateOrUpdateOperationResponse struct {
Poller pollers.Poller
HttpResponse *http.Response
OData *odata.OData
Model *BackupShortTermRetentionPolicy
}

// CreateOrUpdate ...
func (c BackupShortTermRetentionPoliciesClient) CreateOrUpdate(ctx context.Context, id commonids.SqlDatabaseId, input BackupShortTermRetentionPolicy) (result CreateOrUpdateOperationResponse, err error) {
opts := client.RequestOptions{
ContentType: "application/json; charset=utf-8",
ExpectedStatusCodes: []int{
http.StatusAccepted,
http.StatusOK,
},
HttpMethod: http.MethodPut,
Path: fmt.Sprintf("%s/backupShortTermRetentionPolicies/default", id.ID()),
}

req, err := c.Client.NewRequest(ctx, opts)
if err != nil {
return
}

if err = req.Marshal(input); err != nil {
return
}

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
result.OData = resp.OData
result.HttpResponse = resp.Response
}
if err != nil {
return
}

result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client)
if err != nil {
return
}

return
}

// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed
func (c BackupShortTermRetentionPoliciesClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlDatabaseId, input BackupShortTermRetentionPolicy) error {
result, err := c.CreateOrUpdate(ctx, id, input)
if err != nil {
return fmt.Errorf("performing CreateOrUpdate: %+v", err)
}

if err := result.Poller.PollUntilDone(ctx); err != nil {
return fmt.Errorf("polling after CreateOrUpdate: %+v", err)
}

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package backupshorttermretentionpolicies

import (
"context"
"fmt"
"net/http"

"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-sdk/sdk/client"
"github.com/hashicorp/go-azure-sdk/sdk/odata"
)

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

type GetOperationResponse struct {
HttpResponse *http.Response
OData *odata.OData
Model *BackupShortTermRetentionPolicy
}

// Get ...
func (c BackupShortTermRetentionPoliciesClient) Get(ctx context.Context, id commonids.SqlDatabaseId) (result GetOperationResponse, err error) {
opts := client.RequestOptions{
ContentType: "application/json; charset=utf-8",
ExpectedStatusCodes: []int{
http.StatusOK,
},
HttpMethod: http.MethodGet,
Path: fmt.Sprintf("%s/backupShortTermRetentionPolicies/default", id.ID()),
}

req, err := c.Client.NewRequest(ctx, opts)
if err != nil {
return
}

var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
result.OData = resp.OData
result.HttpResponse = resp.Response
}
if err != nil {
return
}

if err = resp.Unmarshal(&result.Model); err != nil {
return
}

return
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package backupshorttermretentionpolicies

import (
"context"
"fmt"
"net/http"

"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-sdk/sdk/client"
"github.com/hashicorp/go-azure-sdk/sdk/odata"
)

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

type ListByDatabaseOperationResponse struct {
HttpResponse *http.Response
OData *odata.OData
Model *[]BackupShortTermRetentionPolicy
}

type ListByDatabaseCompleteResult struct {
LatestHttpResponse *http.Response
Items []BackupShortTermRetentionPolicy
}

// ListByDatabase ...
func (c BackupShortTermRetentionPoliciesClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ListByDatabaseOperationResponse, err error) {
opts := client.RequestOptions{
ContentType: "application/json; charset=utf-8",
ExpectedStatusCodes: []int{
http.StatusOK,
},
HttpMethod: http.MethodGet,
Path: fmt.Sprintf("%s/backupShortTermRetentionPolicies", id.ID()),
}

req, err := c.Client.NewRequest(ctx, opts)
if err != nil {
return
}

var resp *client.Response
resp, err = req.ExecutePaged(ctx)
if resp != nil {
result.OData = resp.OData
result.HttpResponse = resp.Response
}
if err != nil {
return
}

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

result.Model = values.Values

return
}

// ListByDatabaseComplete retrieves all the results into a single object
func (c BackupShortTermRetentionPoliciesClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByDatabaseCompleteResult, error) {
return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, BackupShortTermRetentionPolicyOperationPredicate{})
}

// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate
func (c BackupShortTermRetentionPoliciesClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate BackupShortTermRetentionPolicyOperationPredicate) (result ListByDatabaseCompleteResult, err error) {
items := make([]BackupShortTermRetentionPolicy, 0)

resp, err := c.ListByDatabase(ctx, id)
if err != nil {
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 = ListByDatabaseCompleteResult{
LatestHttpResponse: resp.HttpResponse,
Items: items,
}
return
}
Loading

0 comments on commit 4c2f693

Please sign in to comment.