Azure App Configuration SDK (#17093)
This commit is contained in:
Родитель
9bab6b4207
Коммит
f4feba5dcf
|
@ -18,6 +18,7 @@
|
|||
],
|
||||
"words": [
|
||||
"azcore",
|
||||
"azappconfig",
|
||||
"azidentity",
|
||||
"unpopulate",
|
||||
"etag",
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
## Go
|
||||
|
||||
These settings apply only when `--go` is specified on the command line.
|
||||
|
||||
``` yaml
|
||||
go: true
|
||||
version: "^3.0.0"
|
||||
input-file:
|
||||
- https://github.com/Azure/azure-rest-api-specs/blob/e01d8afe9be7633ed36db014af16d47fec01f737/specification/appconfiguration/data-plane/Microsoft.AppConfiguration/stable/1.0/appconfiguration.json
|
||||
license-header: MICROSOFT_MIT_NO_VERSION
|
||||
clear-output-folder: true
|
||||
output-folder: internal/generated
|
||||
module: azappconfig
|
||||
openapi-type: "data-plane"
|
||||
security: "AADToken"
|
||||
use: "@autorest/go@4.0.0-preview.35"
|
||||
module-version: 0.1.0
|
||||
export-clients: true
|
||||
```
|
|
@ -0,0 +1,444 @@
|
|||
//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.
|
||||
|
||||
package azappconfig
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/appconfiguration/azappconfig/internal/generated"
|
||||
)
|
||||
|
||||
const timeFormat = time.RFC3339Nano
|
||||
|
||||
// Client is the struct for interacting with an Azure App Configuration instance.
|
||||
type Client struct {
|
||||
appConfigClient *generated.AzureAppConfigurationClient
|
||||
syncTokenPolicy *syncTokenPolicy
|
||||
}
|
||||
|
||||
// ClientOptions are the configurable options on a Client.
|
||||
type ClientOptions struct {
|
||||
azcore.ClientOptions
|
||||
}
|
||||
|
||||
func (c *ClientOptions) toConnectionOptions() *policy.ClientOptions {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &policy.ClientOptions{
|
||||
Logging: c.Logging,
|
||||
Retry: c.Retry,
|
||||
Telemetry: c.Telemetry,
|
||||
Transport: c.Transport,
|
||||
PerCallPolicies: c.PerCallPolicies,
|
||||
PerRetryPolicies: c.PerRetryPolicies,
|
||||
}
|
||||
}
|
||||
func getDefaultScope(endpoint string) (string, error) {
|
||||
url, err := url.Parse(endpoint)
|
||||
if err != nil {
|
||||
return "", errors.New("error parsing endpoint url")
|
||||
}
|
||||
|
||||
return url.Scheme + "://" + url.Host + "/.default", nil
|
||||
}
|
||||
|
||||
// NewClient returns a pointer to a Client object affinitized to an endpointUrl.
|
||||
func NewClient(endpointUrl string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error) {
|
||||
if options == nil {
|
||||
options = &ClientOptions{}
|
||||
}
|
||||
|
||||
genOptions := options.toConnectionOptions()
|
||||
|
||||
tokenScope, err := getDefaultScope(endpointUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
syncTokenPolicy := newSyncTokenPolicy()
|
||||
genOptions.PerRetryPolicies = append(
|
||||
genOptions.PerRetryPolicies,
|
||||
runtime.NewBearerTokenPolicy(cred, []string{tokenScope}, nil),
|
||||
syncTokenPolicy,
|
||||
)
|
||||
|
||||
pl := runtime.NewPipeline(generated.ModuleName, generated.ModuleVersion, runtime.PipelineOptions{}, genOptions)
|
||||
return &Client{
|
||||
appConfigClient: generated.NewAzureAppConfigurationClient(endpointUrl, nil, pl),
|
||||
syncTokenPolicy: syncTokenPolicy,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NewClientFromConnectionString parses the connection string and returns a pointer to a Client object.
|
||||
func NewClientFromConnectionString(connectionString string, options *ClientOptions) (*Client, error) {
|
||||
if options == nil {
|
||||
options = &ClientOptions{}
|
||||
}
|
||||
|
||||
genOptions := options.toConnectionOptions()
|
||||
|
||||
endpoint, credential, secret, err := parseConnectionString(connectionString)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
syncTokenPolicy := newSyncTokenPolicy()
|
||||
genOptions.PerRetryPolicies = append(
|
||||
genOptions.PerRetryPolicies,
|
||||
newHmacAuthenticationPolicy(credential, secret),
|
||||
syncTokenPolicy,
|
||||
)
|
||||
|
||||
pl := runtime.NewPipeline(generated.ModuleName, generated.ModuleVersion, runtime.PipelineOptions{}, genOptions)
|
||||
return &Client{
|
||||
appConfigClient: generated.NewAzureAppConfigurationClient(endpoint, nil, pl),
|
||||
syncTokenPolicy: syncTokenPolicy,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateSyncToken sets an external synchronization token to ensure service requests receive up-to-date values.
|
||||
func (c *Client) UpdateSyncToken(token string) {
|
||||
c.syncTokenPolicy.addToken(token)
|
||||
}
|
||||
|
||||
func (cs Setting) toGeneratedPutOptions(ifMatch *azcore.ETag, ifNoneMatch *azcore.ETag) *generated.AzureAppConfigurationClientPutKeyValueOptions {
|
||||
return &generated.AzureAppConfigurationClientPutKeyValueOptions{
|
||||
Entity: cs.toGenerated(),
|
||||
IfMatch: (*string)(ifMatch),
|
||||
IfNoneMatch: (*string)(ifNoneMatch),
|
||||
Label: cs.Label,
|
||||
}
|
||||
}
|
||||
|
||||
// AddSettingResponse contains the response from AddSetting method.
|
||||
type AddSettingResponse struct {
|
||||
Setting
|
||||
|
||||
// Sync token for the Azure App Configuration client, corresponding to the current state of the client.
|
||||
SyncToken *string
|
||||
}
|
||||
|
||||
func fromGeneratedAdd(g generated.AzureAppConfigurationClientPutKeyValueResponse) AddSettingResponse {
|
||||
return AddSettingResponse{
|
||||
Setting: settingFromGenerated(g.KeyValue),
|
||||
SyncToken: g.SyncToken,
|
||||
}
|
||||
}
|
||||
|
||||
// AddSettingOptions contains the optional parameters for the AddSetting method.
|
||||
type AddSettingOptions struct {
|
||||
// placeholder for future options
|
||||
}
|
||||
|
||||
// AddSetting creates a configuration setting only if the setting does not already exist in the configuration store.
|
||||
func (c *Client) AddSetting(ctx context.Context, setting Setting, options *AddSettingOptions) (AddSettingResponse, error) {
|
||||
etagAny := azcore.ETagAny
|
||||
resp, err := c.appConfigClient.PutKeyValue(ctx, *setting.Key, setting.toGeneratedPutOptions(nil, &etagAny))
|
||||
if err != nil {
|
||||
return AddSettingResponse{}, err
|
||||
}
|
||||
|
||||
return (AddSettingResponse)(fromGeneratedAdd(resp)), nil
|
||||
}
|
||||
|
||||
// DeleteSettingResponse contains the response from DeleteSetting method.
|
||||
type DeleteSettingResponse struct {
|
||||
Setting
|
||||
|
||||
// Sync token for the Azure App Configuration client, corresponding to the current state of the client.
|
||||
SyncToken *string
|
||||
}
|
||||
|
||||
func fromGeneratedDelete(g generated.AzureAppConfigurationClientDeleteKeyValueResponse) DeleteSettingResponse {
|
||||
return DeleteSettingResponse{
|
||||
Setting: settingFromGenerated(g.KeyValue),
|
||||
SyncToken: g.SyncToken,
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteSettingOptions contains the optional parameters for the DeleteSetting method.
|
||||
type DeleteSettingOptions struct {
|
||||
// If set to true and the configuration setting exists in the configuration store,
|
||||
// delete the setting if the passed-in configuration setting is the same version as the one in the configuration store.
|
||||
// The setting versions are the same if their ETag fields match.
|
||||
OnlyIfUnchanged bool
|
||||
}
|
||||
|
||||
func (cs Setting) toGeneratedDeleteOptions(ifMatch *azcore.ETag) *generated.AzureAppConfigurationClientDeleteKeyValueOptions {
|
||||
return &generated.AzureAppConfigurationClientDeleteKeyValueOptions{
|
||||
IfMatch: (*string)(ifMatch),
|
||||
Label: cs.Label,
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteSetting deletes a configuration setting from the configuration store.
|
||||
func (c *Client) DeleteSetting(ctx context.Context, setting Setting, options *DeleteSettingOptions) (DeleteSettingResponse, error) {
|
||||
var ifMatch *azcore.ETag
|
||||
if options != nil && options.OnlyIfUnchanged {
|
||||
ifMatch = setting.ETag
|
||||
}
|
||||
|
||||
resp, err := c.appConfigClient.DeleteKeyValue(ctx, *setting.Key, setting.toGeneratedDeleteOptions(ifMatch))
|
||||
if err != nil {
|
||||
return DeleteSettingResponse{}, err
|
||||
}
|
||||
|
||||
return fromGeneratedDelete(resp), nil
|
||||
}
|
||||
|
||||
// GetSettingResponse contains the configuration setting retrieved by GetSetting method.
|
||||
type GetSettingResponse struct {
|
||||
Setting
|
||||
|
||||
// Sync token for the Azure App Configuration client, corresponding to the current state of the client.
|
||||
SyncToken *string
|
||||
|
||||
// Contains the timestamp of when the configuration setting was last modified.
|
||||
LastModified *time.Time
|
||||
}
|
||||
|
||||
func fromGeneratedGet(g generated.AzureAppConfigurationClientGetKeyValueResponse) GetSettingResponse {
|
||||
var t *time.Time
|
||||
if g.LastModified != nil {
|
||||
if tt, err := time.Parse(timeFormat, *g.LastModified); err == nil {
|
||||
t = &tt
|
||||
}
|
||||
}
|
||||
|
||||
return GetSettingResponse{
|
||||
Setting: settingFromGenerated(g.KeyValue),
|
||||
SyncToken: g.SyncToken,
|
||||
LastModified: t,
|
||||
}
|
||||
}
|
||||
|
||||
// GetSettingOptions contains the optional parameters for the GetSetting method.
|
||||
type GetSettingOptions struct {
|
||||
// If set to true, only retrieve the setting from the configuration store if it has changed since the client last retrieved it.
|
||||
// It is determined to have changed if the ETag field on the passed-in configuration setting is different from the ETag
|
||||
// of the setting in the configuration store.
|
||||
OnlyIfChanged bool
|
||||
|
||||
// The setting will be retrieved exactly as it existed at the provided time.
|
||||
AcceptDateTime *time.Time
|
||||
}
|
||||
|
||||
func (cs Setting) toGeneratedGetOptions(ifNoneMatch *azcore.ETag, acceptDateTime *time.Time) *generated.AzureAppConfigurationClientGetKeyValueOptions {
|
||||
var dt *string
|
||||
if acceptDateTime != nil {
|
||||
str := acceptDateTime.Format(timeFormat)
|
||||
dt = &str
|
||||
}
|
||||
|
||||
return &generated.AzureAppConfigurationClientGetKeyValueOptions{
|
||||
AcceptDatetime: dt,
|
||||
IfNoneMatch: (*string)(ifNoneMatch),
|
||||
Label: cs.Label,
|
||||
}
|
||||
}
|
||||
|
||||
// GetSetting retrieves an existing configuration setting from the configuration store.
|
||||
func (c *Client) GetSetting(ctx context.Context, setting Setting, options *GetSettingOptions) (GetSettingResponse, error) {
|
||||
var ifNoneMatch *azcore.ETag
|
||||
var acceptDateTime *time.Time
|
||||
if options != nil {
|
||||
if options.OnlyIfChanged {
|
||||
ifNoneMatch = setting.ETag
|
||||
}
|
||||
|
||||
acceptDateTime = options.AcceptDateTime
|
||||
}
|
||||
|
||||
resp, err := c.appConfigClient.GetKeyValue(ctx, *setting.Key, setting.toGeneratedGetOptions(ifNoneMatch, acceptDateTime))
|
||||
if err != nil {
|
||||
return GetSettingResponse{}, err
|
||||
}
|
||||
|
||||
return fromGeneratedGet(resp), nil
|
||||
}
|
||||
|
||||
// SetReadOnlyResponse contains the response from SetReadOnly method.
|
||||
type SetReadOnlyResponse struct {
|
||||
Setting
|
||||
|
||||
// Sync token for the Azure App Configuration client, corresponding to the current state of the client.
|
||||
SyncToken *string
|
||||
}
|
||||
|
||||
func fromGeneratedPutLock(g generated.AzureAppConfigurationClientPutLockResponse) SetReadOnlyResponse {
|
||||
return SetReadOnlyResponse{
|
||||
Setting: settingFromGenerated(g.KeyValue),
|
||||
SyncToken: g.SyncToken,
|
||||
}
|
||||
}
|
||||
|
||||
func fromGeneratedDeleteLock(g generated.AzureAppConfigurationClientDeleteLockResponse) SetReadOnlyResponse {
|
||||
return SetReadOnlyResponse{
|
||||
Setting: settingFromGenerated(g.KeyValue),
|
||||
SyncToken: g.SyncToken,
|
||||
}
|
||||
}
|
||||
|
||||
// SetReadOnlyOptions contains the optional parameters for the SetReadOnly method.
|
||||
type SetReadOnlyOptions struct {
|
||||
// If set to true and the configuration setting exists in the configuration store, update the setting
|
||||
// if the passed-in configuration setting is the same version as the one in the configuration store.
|
||||
// The setting versions are the same if their ETag fields match.
|
||||
OnlyIfUnchanged bool
|
||||
}
|
||||
|
||||
func (cs Setting) toGeneratedPutLockOptions(ifMatch *azcore.ETag) *generated.AzureAppConfigurationClientPutLockOptions {
|
||||
return &generated.AzureAppConfigurationClientPutLockOptions{
|
||||
IfMatch: (*string)(ifMatch),
|
||||
Label: cs.Label,
|
||||
}
|
||||
}
|
||||
|
||||
func (cs Setting) toGeneratedDeleteLockOptions(ifMatch *azcore.ETag) *generated.AzureAppConfigurationClientDeleteLockOptions {
|
||||
return &generated.AzureAppConfigurationClientDeleteLockOptions{
|
||||
IfMatch: (*string)(ifMatch),
|
||||
Label: cs.Label,
|
||||
}
|
||||
}
|
||||
|
||||
// SetReadOnly sets an existing configuration setting to read only or read write state in the configuration store.
|
||||
func (c *Client) SetReadOnly(ctx context.Context, setting Setting, isReadOnly bool, options *SetReadOnlyOptions) (SetReadOnlyResponse, error) {
|
||||
var ifMatch *azcore.ETag
|
||||
if options != nil && options.OnlyIfUnchanged {
|
||||
ifMatch = setting.ETag
|
||||
}
|
||||
|
||||
var err error
|
||||
if isReadOnly {
|
||||
var resp generated.AzureAppConfigurationClientPutLockResponse
|
||||
resp, err = c.appConfigClient.PutLock(ctx, *setting.Key, setting.toGeneratedPutLockOptions(ifMatch))
|
||||
if err == nil {
|
||||
return fromGeneratedPutLock(resp), nil
|
||||
}
|
||||
} else {
|
||||
var resp generated.AzureAppConfigurationClientDeleteLockResponse
|
||||
resp, err = c.appConfigClient.DeleteLock(ctx, *setting.Key, setting.toGeneratedDeleteLockOptions(ifMatch))
|
||||
if err == nil {
|
||||
return fromGeneratedDeleteLock(resp), nil
|
||||
}
|
||||
}
|
||||
|
||||
return SetReadOnlyResponse{}, err
|
||||
}
|
||||
|
||||
// SetSettingResponse contains the response from SetSetting method.
|
||||
type SetSettingResponse struct {
|
||||
Setting
|
||||
|
||||
// Sync token for the Azure App Configuration client, corresponding to the current state of the client.
|
||||
SyncToken *string
|
||||
}
|
||||
|
||||
func fromGeneratedSet(g generated.AzureAppConfigurationClientPutKeyValueResponse) SetSettingResponse {
|
||||
return SetSettingResponse{
|
||||
Setting: settingFromGenerated(g.KeyValue),
|
||||
SyncToken: g.SyncToken,
|
||||
}
|
||||
}
|
||||
|
||||
// SetSettingOptions contains the optional parameters for the SetSetting method.
|
||||
type SetSettingOptions struct {
|
||||
// If set to true and the configuration setting exists in the configuration store, overwrite the setting
|
||||
// if the passed-in configuration setting is the same version as the one in the configuration store.
|
||||
// The setting versions are the same if their ETag fields match.
|
||||
OnlyIfUnchanged bool
|
||||
}
|
||||
|
||||
// SetSetting creates a configuration setting if it doesn't exist or overwrites the existing setting in the configuration store.
|
||||
func (c *Client) SetSetting(ctx context.Context, setting Setting, options *SetSettingOptions) (SetSettingResponse, error) {
|
||||
var ifMatch *azcore.ETag
|
||||
if options != nil && options.OnlyIfUnchanged {
|
||||
ifMatch = setting.ETag
|
||||
}
|
||||
|
||||
resp, err := c.appConfigClient.PutKeyValue(ctx, *setting.Key, setting.toGeneratedPutOptions(ifMatch, nil))
|
||||
if err != nil {
|
||||
return SetSettingResponse{}, err
|
||||
}
|
||||
|
||||
return (SetSettingResponse)(fromGeneratedSet(resp)), nil
|
||||
}
|
||||
|
||||
// ListRevisionsPage contains the configuration settings returned by ListRevisionsPager.
|
||||
type ListRevisionsPage struct {
|
||||
// Contains the configuration settings returned that match the setting selector provided.
|
||||
Settings []Setting
|
||||
|
||||
// Sync token for the Azure App Configuration client, corresponding to the current state of the client.
|
||||
SyncToken *string
|
||||
}
|
||||
|
||||
func fromGeneratedGetRevisionsPage(g generated.AzureAppConfigurationClientGetRevisionsResponse) ListRevisionsPage {
|
||||
var css []Setting
|
||||
for _, cs := range g.Items {
|
||||
if cs != nil {
|
||||
css = append(css, settingFromGenerated(*cs))
|
||||
}
|
||||
}
|
||||
|
||||
return ListRevisionsPage{
|
||||
Settings: css,
|
||||
SyncToken: g.SyncToken,
|
||||
}
|
||||
}
|
||||
|
||||
// ListRevisionsPager is a Pager for revision list operations.
|
||||
//
|
||||
// NextPage should be called first. It fetches the next available page of results from the service.
|
||||
// If the fetched page contains results, the return value is true, else false.
|
||||
// Results fetched from the service can be evaluated by calling PageResponse on this Pager.
|
||||
// If the result is false, the value of Err() will indicate if an error occurred.
|
||||
type ListRevisionsPager interface {
|
||||
// PageResponse returns the current ListRevisionsPage.
|
||||
PageResponse() ListRevisionsPage
|
||||
|
||||
// Err returns an error if there was an error on the last request.
|
||||
Err() error
|
||||
|
||||
// NextPage returns true if there is another page of data available, false if not.
|
||||
NextPage(context.Context) bool
|
||||
}
|
||||
|
||||
type listRevisionsPager struct {
|
||||
genPager *generated.AzureAppConfigurationClientGetRevisionsPager
|
||||
}
|
||||
|
||||
func (p listRevisionsPager) PageResponse() ListRevisionsPage {
|
||||
return fromGeneratedGetRevisionsPage(p.genPager.PageResponse())
|
||||
}
|
||||
|
||||
func (p listRevisionsPager) Err() error {
|
||||
return p.genPager.Err()
|
||||
}
|
||||
|
||||
func (p listRevisionsPager) NextPage(ctx context.Context) bool {
|
||||
return p.genPager.NextPage(ctx)
|
||||
}
|
||||
|
||||
// ListRevisionsOptions contains the optional parameters for the ListRevisions method.
|
||||
type ListRevisionsOptions struct {
|
||||
// placeholder for future options
|
||||
}
|
||||
|
||||
// ListRevisions retrieves the revisions of one or more configuration setting entities that match the specified setting selector.
|
||||
func (c *Client) ListRevisions(selector SettingSelector, options *ListRevisionsOptions) ListRevisionsPager {
|
||||
return listRevisionsPager{genPager: c.appConfigClient.GetRevisions(selector.toGenerated())}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
//go:build go1.16
|
||||
// +build go1.16
|
||||
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
package azappconfig
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestClient(t *testing.T) {
|
||||
key := "key"
|
||||
label := "label"
|
||||
value := "value"
|
||||
client, err := NewClientFromConnectionString(os.Getenv("APPCONFIGURATION_CONNECTION_STRING"), nil)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, client)
|
||||
|
||||
addResp, err2 := client.AddSetting(context.TODO(), Setting{Key: &key, Label: &label, Value: &value}, nil)
|
||||
require.NoError(t, err2)
|
||||
require.NotEmpty(t, addResp)
|
||||
require.NotNil(t, addResp.Key)
|
||||
require.NotNil(t, addResp.Label)
|
||||
require.NotNil(t, addResp.Value)
|
||||
require.Equal(t, key, *addResp.Key)
|
||||
require.Equal(t, label, *addResp.Label)
|
||||
require.Equal(t, value, *addResp.Value)
|
||||
|
||||
getResp, err3 := client.GetSetting(context.TODO(), Setting{Key: &key, Label: &label}, nil)
|
||||
require.NoError(t, err3)
|
||||
require.NotEmpty(t, getResp)
|
||||
require.NotNil(t, getResp.Key)
|
||||
require.NotNil(t, getResp.Label)
|
||||
require.NotNil(t, getResp.Value)
|
||||
require.Equal(t, key, *getResp.Key)
|
||||
require.Equal(t, label, *getResp.Label)
|
||||
require.Equal(t, value, *getResp.Value)
|
||||
|
||||
value = "value2"
|
||||
setResp, err4 := client.SetSetting(context.TODO(), Setting{Key: &key, Label: &label, Value: &value}, nil)
|
||||
require.NoError(t, err4)
|
||||
require.NotEmpty(t, setResp)
|
||||
require.NotNil(t, setResp.Key)
|
||||
require.NotNil(t, setResp.Label)
|
||||
require.NotNil(t, setResp.Value)
|
||||
require.Equal(t, key, *setResp.Key)
|
||||
require.Equal(t, label, *setResp.Label)
|
||||
require.Equal(t, value, *setResp.Value)
|
||||
|
||||
roResp, err5 := client.SetReadOnly(context.TODO(), Setting{Key: &key, Label: &label}, true, nil)
|
||||
require.NoError(t, err5)
|
||||
require.NotEmpty(t, roResp)
|
||||
require.NotNil(t, roResp.Key)
|
||||
require.NotNil(t, roResp.Label)
|
||||
require.NotNil(t, roResp.Value)
|
||||
require.NotNil(t, roResp.IsReadOnly)
|
||||
require.Equal(t, key, *roResp.Key)
|
||||
require.Equal(t, label, *roResp.Label)
|
||||
require.Equal(t, value, *roResp.Value)
|
||||
require.True(t, *roResp.IsReadOnly)
|
||||
|
||||
roResp2, err6 := client.SetReadOnly(context.TODO(), Setting{Key: &key, Label: &label}, false, nil)
|
||||
require.NoError(t, err6)
|
||||
require.NotEmpty(t, roResp2)
|
||||
require.NotNil(t, roResp2.Key)
|
||||
require.NotNil(t, roResp2.Label)
|
||||
require.NotNil(t, roResp2.Value)
|
||||
require.NotNil(t, roResp2.IsReadOnly)
|
||||
require.Equal(t, key, *roResp2.Key)
|
||||
require.Equal(t, label, *roResp2.Label)
|
||||
require.Equal(t, value, *roResp2.Value)
|
||||
require.False(t, *roResp2.IsReadOnly)
|
||||
|
||||
any := "*"
|
||||
revPgr := client.ListRevisions(SettingSelector{KeyFilter: &any, LabelFilter: &any, Fields: AllSettingFields()}, nil)
|
||||
require.NotEmpty(t, revPgr)
|
||||
revHasPage := revPgr.NextPage(context.TODO())
|
||||
require.True(t, revHasPage)
|
||||
revResp := revPgr.PageResponse()
|
||||
require.NotEmpty(t, revResp)
|
||||
require.Equal(t, key, *revResp.Settings[0].Key)
|
||||
require.Equal(t, label, *revResp.Settings[0].Label)
|
||||
require.Equal(t, value, *revResp.Settings[0].Value)
|
||||
|
||||
delResp, err7 := client.DeleteSetting(context.TODO(), Setting{Key: &key, Label: &label}, nil)
|
||||
require.NoError(t, err7)
|
||||
require.NotEmpty(t, delResp)
|
||||
require.NotNil(t, delResp.Key)
|
||||
require.NotNil(t, delResp.Label)
|
||||
require.NotNil(t, delResp.Value)
|
||||
require.Equal(t, key, *delResp.Key)
|
||||
require.Equal(t, label, *delResp.Label)
|
||||
require.Equal(t, value, *delResp.Value)
|
||||
}
|
|
@ -0,0 +1,904 @@
|
|||
//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 generated
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
|
||||
)
|
||||
|
||||
// AzureAppConfigurationClient contains the methods for the AzureAppConfiguration group.
|
||||
// Don't use this type directly, use NewAzureAppConfigurationClient() instead.
|
||||
type AzureAppConfigurationClient struct {
|
||||
endpoint string
|
||||
syncToken *string
|
||||
pl runtime.Pipeline
|
||||
}
|
||||
|
||||
// NewAzureAppConfigurationClient creates a new instance of AzureAppConfigurationClient with the specified values.
|
||||
// endpoint - The endpoint of the App Configuration instance to send requests to.
|
||||
// syncToken - Used to guarantee real-time consistency between requests.
|
||||
// pl - the pipeline used for sending requests and handling responses.
|
||||
func NewAzureAppConfigurationClient(endpoint string, syncToken *string, pl runtime.Pipeline) *AzureAppConfigurationClient {
|
||||
client := &AzureAppConfigurationClient{
|
||||
endpoint: endpoint,
|
||||
syncToken: syncToken,
|
||||
pl: pl,
|
||||
}
|
||||
return client
|
||||
}
|
||||
|
||||
// CheckKeyValue - Requests the headers and status of the given resource.
|
||||
// If the operation fails it returns an *azcore.ResponseError type.
|
||||
// key - The key of the key-value to retrieve.
|
||||
// options - AzureAppConfigurationClientCheckKeyValueOptions contains the optional parameters for the AzureAppConfigurationClient.CheckKeyValue
|
||||
// method.
|
||||
func (client *AzureAppConfigurationClient) CheckKeyValue(ctx context.Context, key string, options *AzureAppConfigurationClientCheckKeyValueOptions) (AzureAppConfigurationClientCheckKeyValueResponse, error) {
|
||||
req, err := client.checkKeyValueCreateRequest(ctx, key, options)
|
||||
if err != nil {
|
||||
return AzureAppConfigurationClientCheckKeyValueResponse{}, err
|
||||
}
|
||||
resp, err := client.pl.Do(req)
|
||||
if err != nil {
|
||||
return AzureAppConfigurationClientCheckKeyValueResponse{}, err
|
||||
}
|
||||
if !runtime.HasStatusCode(resp, http.StatusOK) {
|
||||
return AzureAppConfigurationClientCheckKeyValueResponse{}, runtime.NewResponseError(resp)
|
||||
}
|
||||
return client.checkKeyValueHandleResponse(resp)
|
||||
}
|
||||
|
||||
// checkKeyValueCreateRequest creates the CheckKeyValue request.
|
||||
func (client *AzureAppConfigurationClient) checkKeyValueCreateRequest(ctx context.Context, key string, options *AzureAppConfigurationClientCheckKeyValueOptions) (*policy.Request, error) {
|
||||
urlPath := "/kv/{key}"
|
||||
if key == "" {
|
||||
return nil, errors.New("parameter key cannot be empty")
|
||||
}
|
||||
urlPath = strings.ReplaceAll(urlPath, "{key}", url.PathEscape(key))
|
||||
req, err := runtime.NewRequest(ctx, http.MethodHead, runtime.JoinPaths(client.endpoint, urlPath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reqQP := req.Raw().URL.Query()
|
||||
if options != nil && options.Label != nil {
|
||||
reqQP.Set("label", *options.Label)
|
||||
}
|
||||
reqQP.Set("api-version", "1.0")
|
||||
if options != nil && options.Select != nil {
|
||||
reqQP.Set("$Select", strings.Join(strings.Fields(strings.Trim(fmt.Sprint(options.Select), "[]")), ","))
|
||||
}
|
||||
req.Raw().URL.RawQuery = reqQP.Encode()
|
||||
if client.syncToken != nil {
|
||||
req.Raw().Header.Set("Sync-Token", *client.syncToken)
|
||||
}
|
||||
if options != nil && options.AcceptDatetime != nil {
|
||||
req.Raw().Header.Set("Accept-Datetime", *options.AcceptDatetime)
|
||||
}
|
||||
if options != nil && options.IfMatch != nil {
|
||||
req.Raw().Header.Set("If-Match", *options.IfMatch)
|
||||
}
|
||||
if options != nil && options.IfNoneMatch != nil {
|
||||
req.Raw().Header.Set("If-None-Match", *options.IfNoneMatch)
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// checkKeyValueHandleResponse handles the CheckKeyValue response.
|
||||
func (client *AzureAppConfigurationClient) checkKeyValueHandleResponse(resp *http.Response) (AzureAppConfigurationClientCheckKeyValueResponse, error) {
|
||||
result := AzureAppConfigurationClientCheckKeyValueResponse{RawResponse: resp}
|
||||
if val := resp.Header.Get("Sync-Token"); val != "" {
|
||||
result.SyncToken = &val
|
||||
}
|
||||
if val := resp.Header.Get("ETag"); val != "" {
|
||||
result.ETag = &val
|
||||
}
|
||||
if val := resp.Header.Get("Last-Modified"); val != "" {
|
||||
result.LastModified = &val
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// CheckKeyValues - Requests the headers and status of the given resource.
|
||||
// If the operation fails it returns an *azcore.ResponseError type.
|
||||
// options - AzureAppConfigurationClientCheckKeyValuesOptions contains the optional parameters for the AzureAppConfigurationClient.CheckKeyValues
|
||||
// method.
|
||||
func (client *AzureAppConfigurationClient) CheckKeyValues(ctx context.Context, options *AzureAppConfigurationClientCheckKeyValuesOptions) (AzureAppConfigurationClientCheckKeyValuesResponse, error) {
|
||||
req, err := client.checkKeyValuesCreateRequest(ctx, options)
|
||||
if err != nil {
|
||||
return AzureAppConfigurationClientCheckKeyValuesResponse{}, err
|
||||
}
|
||||
resp, err := client.pl.Do(req)
|
||||
if err != nil {
|
||||
return AzureAppConfigurationClientCheckKeyValuesResponse{}, err
|
||||
}
|
||||
if !runtime.HasStatusCode(resp, http.StatusOK) {
|
||||
return AzureAppConfigurationClientCheckKeyValuesResponse{}, runtime.NewResponseError(resp)
|
||||
}
|
||||
return client.checkKeyValuesHandleResponse(resp)
|
||||
}
|
||||
|
||||
// checkKeyValuesCreateRequest creates the CheckKeyValues request.
|
||||
func (client *AzureAppConfigurationClient) checkKeyValuesCreateRequest(ctx context.Context, options *AzureAppConfigurationClientCheckKeyValuesOptions) (*policy.Request, error) {
|
||||
urlPath := "/kv"
|
||||
req, err := runtime.NewRequest(ctx, http.MethodHead, runtime.JoinPaths(client.endpoint, urlPath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reqQP := req.Raw().URL.Query()
|
||||
if options != nil && options.Key != nil {
|
||||
reqQP.Set("key", *options.Key)
|
||||
}
|
||||
if options != nil && options.Label != nil {
|
||||
reqQP.Set("label", *options.Label)
|
||||
}
|
||||
reqQP.Set("api-version", "1.0")
|
||||
if options != nil && options.After != nil {
|
||||
reqQP.Set("After", *options.After)
|
||||
}
|
||||
if options != nil && options.Select != nil {
|
||||
reqQP.Set("$Select", strings.Join(strings.Fields(strings.Trim(fmt.Sprint(options.Select), "[]")), ","))
|
||||
}
|
||||
req.Raw().URL.RawQuery = reqQP.Encode()
|
||||
if client.syncToken != nil {
|
||||
req.Raw().Header.Set("Sync-Token", *client.syncToken)
|
||||
}
|
||||
if options != nil && options.AcceptDatetime != nil {
|
||||
req.Raw().Header.Set("Accept-Datetime", *options.AcceptDatetime)
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// checkKeyValuesHandleResponse handles the CheckKeyValues response.
|
||||
func (client *AzureAppConfigurationClient) checkKeyValuesHandleResponse(resp *http.Response) (AzureAppConfigurationClientCheckKeyValuesResponse, error) {
|
||||
result := AzureAppConfigurationClientCheckKeyValuesResponse{RawResponse: resp}
|
||||
if val := resp.Header.Get("Sync-Token"); val != "" {
|
||||
result.SyncToken = &val
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// CheckKeys - Requests the headers and status of the given resource.
|
||||
// If the operation fails it returns an *azcore.ResponseError type.
|
||||
// options - AzureAppConfigurationClientCheckKeysOptions contains the optional parameters for the AzureAppConfigurationClient.CheckKeys
|
||||
// method.
|
||||
func (client *AzureAppConfigurationClient) CheckKeys(ctx context.Context, options *AzureAppConfigurationClientCheckKeysOptions) (AzureAppConfigurationClientCheckKeysResponse, error) {
|
||||
req, err := client.checkKeysCreateRequest(ctx, options)
|
||||
if err != nil {
|
||||
return AzureAppConfigurationClientCheckKeysResponse{}, err
|
||||
}
|
||||
resp, err := client.pl.Do(req)
|
||||
if err != nil {
|
||||
return AzureAppConfigurationClientCheckKeysResponse{}, err
|
||||
}
|
||||
if !runtime.HasStatusCode(resp, http.StatusOK) {
|
||||
return AzureAppConfigurationClientCheckKeysResponse{}, runtime.NewResponseError(resp)
|
||||
}
|
||||
return client.checkKeysHandleResponse(resp)
|
||||
}
|
||||
|
||||
// checkKeysCreateRequest creates the CheckKeys request.
|
||||
func (client *AzureAppConfigurationClient) checkKeysCreateRequest(ctx context.Context, options *AzureAppConfigurationClientCheckKeysOptions) (*policy.Request, error) {
|
||||
urlPath := "/keys"
|
||||
req, err := runtime.NewRequest(ctx, http.MethodHead, runtime.JoinPaths(client.endpoint, urlPath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reqQP := req.Raw().URL.Query()
|
||||
if options != nil && options.Name != nil {
|
||||
reqQP.Set("name", *options.Name)
|
||||
}
|
||||
reqQP.Set("api-version", "1.0")
|
||||
if options != nil && options.After != nil {
|
||||
reqQP.Set("After", *options.After)
|
||||
}
|
||||
req.Raw().URL.RawQuery = reqQP.Encode()
|
||||
if client.syncToken != nil {
|
||||
req.Raw().Header.Set("Sync-Token", *client.syncToken)
|
||||
}
|
||||
if options != nil && options.AcceptDatetime != nil {
|
||||
req.Raw().Header.Set("Accept-Datetime", *options.AcceptDatetime)
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// checkKeysHandleResponse handles the CheckKeys response.
|
||||
func (client *AzureAppConfigurationClient) checkKeysHandleResponse(resp *http.Response) (AzureAppConfigurationClientCheckKeysResponse, error) {
|
||||
result := AzureAppConfigurationClientCheckKeysResponse{RawResponse: resp}
|
||||
if val := resp.Header.Get("Sync-Token"); val != "" {
|
||||
result.SyncToken = &val
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// CheckLabels - Requests the headers and status of the given resource.
|
||||
// If the operation fails it returns an *azcore.ResponseError type.
|
||||
// options - AzureAppConfigurationClientCheckLabelsOptions contains the optional parameters for the AzureAppConfigurationClient.CheckLabels
|
||||
// method.
|
||||
func (client *AzureAppConfigurationClient) CheckLabels(ctx context.Context, options *AzureAppConfigurationClientCheckLabelsOptions) (AzureAppConfigurationClientCheckLabelsResponse, error) {
|
||||
req, err := client.checkLabelsCreateRequest(ctx, options)
|
||||
if err != nil {
|
||||
return AzureAppConfigurationClientCheckLabelsResponse{}, err
|
||||
}
|
||||
resp, err := client.pl.Do(req)
|
||||
if err != nil {
|
||||
return AzureAppConfigurationClientCheckLabelsResponse{}, err
|
||||
}
|
||||
if !runtime.HasStatusCode(resp, http.StatusOK) {
|
||||
return AzureAppConfigurationClientCheckLabelsResponse{}, runtime.NewResponseError(resp)
|
||||
}
|
||||
return client.checkLabelsHandleResponse(resp)
|
||||
}
|
||||
|
||||
// checkLabelsCreateRequest creates the CheckLabels request.
|
||||
func (client *AzureAppConfigurationClient) checkLabelsCreateRequest(ctx context.Context, options *AzureAppConfigurationClientCheckLabelsOptions) (*policy.Request, error) {
|
||||
urlPath := "/labels"
|
||||
req, err := runtime.NewRequest(ctx, http.MethodHead, runtime.JoinPaths(client.endpoint, urlPath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reqQP := req.Raw().URL.Query()
|
||||
if options != nil && options.Name != nil {
|
||||
reqQP.Set("name", *options.Name)
|
||||
}
|
||||
reqQP.Set("api-version", "1.0")
|
||||
if options != nil && options.After != nil {
|
||||
reqQP.Set("After", *options.After)
|
||||
}
|
||||
if options != nil && options.Select != nil {
|
||||
reqQP.Set("$Select", strings.Join(strings.Fields(strings.Trim(fmt.Sprint(options.Select), "[]")), ","))
|
||||
}
|
||||
req.Raw().URL.RawQuery = reqQP.Encode()
|
||||
if client.syncToken != nil {
|
||||
req.Raw().Header.Set("Sync-Token", *client.syncToken)
|
||||
}
|
||||
if options != nil && options.AcceptDatetime != nil {
|
||||
req.Raw().Header.Set("Accept-Datetime", *options.AcceptDatetime)
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// checkLabelsHandleResponse handles the CheckLabels response.
|
||||
func (client *AzureAppConfigurationClient) checkLabelsHandleResponse(resp *http.Response) (AzureAppConfigurationClientCheckLabelsResponse, error) {
|
||||
result := AzureAppConfigurationClientCheckLabelsResponse{RawResponse: resp}
|
||||
if val := resp.Header.Get("Sync-Token"); val != "" {
|
||||
result.SyncToken = &val
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// CheckRevisions - Requests the headers and status of the given resource.
|
||||
// If the operation fails it returns an *azcore.ResponseError type.
|
||||
// options - AzureAppConfigurationClientCheckRevisionsOptions contains the optional parameters for the AzureAppConfigurationClient.CheckRevisions
|
||||
// method.
|
||||
func (client *AzureAppConfigurationClient) CheckRevisions(ctx context.Context, options *AzureAppConfigurationClientCheckRevisionsOptions) (AzureAppConfigurationClientCheckRevisionsResponse, error) {
|
||||
req, err := client.checkRevisionsCreateRequest(ctx, options)
|
||||
if err != nil {
|
||||
return AzureAppConfigurationClientCheckRevisionsResponse{}, err
|
||||
}
|
||||
resp, err := client.pl.Do(req)
|
||||
if err != nil {
|
||||
return AzureAppConfigurationClientCheckRevisionsResponse{}, err
|
||||
}
|
||||
if !runtime.HasStatusCode(resp, http.StatusOK) {
|
||||
return AzureAppConfigurationClientCheckRevisionsResponse{}, runtime.NewResponseError(resp)
|
||||
}
|
||||
return client.checkRevisionsHandleResponse(resp)
|
||||
}
|
||||
|
||||
// checkRevisionsCreateRequest creates the CheckRevisions request.
|
||||
func (client *AzureAppConfigurationClient) checkRevisionsCreateRequest(ctx context.Context, options *AzureAppConfigurationClientCheckRevisionsOptions) (*policy.Request, error) {
|
||||
urlPath := "/revisions"
|
||||
req, err := runtime.NewRequest(ctx, http.MethodHead, runtime.JoinPaths(client.endpoint, urlPath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reqQP := req.Raw().URL.Query()
|
||||
if options != nil && options.Key != nil {
|
||||
reqQP.Set("key", *options.Key)
|
||||
}
|
||||
if options != nil && options.Label != nil {
|
||||
reqQP.Set("label", *options.Label)
|
||||
}
|
||||
reqQP.Set("api-version", "1.0")
|
||||
if options != nil && options.After != nil {
|
||||
reqQP.Set("After", *options.After)
|
||||
}
|
||||
if options != nil && options.Select != nil {
|
||||
reqQP.Set("$Select", strings.Join(strings.Fields(strings.Trim(fmt.Sprint(options.Select), "[]")), ","))
|
||||
}
|
||||
req.Raw().URL.RawQuery = reqQP.Encode()
|
||||
if client.syncToken != nil {
|
||||
req.Raw().Header.Set("Sync-Token", *client.syncToken)
|
||||
}
|
||||
if options != nil && options.AcceptDatetime != nil {
|
||||
req.Raw().Header.Set("Accept-Datetime", *options.AcceptDatetime)
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// checkRevisionsHandleResponse handles the CheckRevisions response.
|
||||
func (client *AzureAppConfigurationClient) checkRevisionsHandleResponse(resp *http.Response) (AzureAppConfigurationClientCheckRevisionsResponse, error) {
|
||||
result := AzureAppConfigurationClientCheckRevisionsResponse{RawResponse: resp}
|
||||
if val := resp.Header.Get("Sync-Token"); val != "" {
|
||||
result.SyncToken = &val
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// DeleteKeyValue - Deletes a key-value.
|
||||
// If the operation fails it returns an *azcore.ResponseError type.
|
||||
// key - The key of the key-value to delete.
|
||||
// options - AzureAppConfigurationClientDeleteKeyValueOptions contains the optional parameters for the AzureAppConfigurationClient.DeleteKeyValue
|
||||
// method.
|
||||
func (client *AzureAppConfigurationClient) DeleteKeyValue(ctx context.Context, key string, options *AzureAppConfigurationClientDeleteKeyValueOptions) (AzureAppConfigurationClientDeleteKeyValueResponse, error) {
|
||||
req, err := client.deleteKeyValueCreateRequest(ctx, key, options)
|
||||
if err != nil {
|
||||
return AzureAppConfigurationClientDeleteKeyValueResponse{}, err
|
||||
}
|
||||
resp, err := client.pl.Do(req)
|
||||
if err != nil {
|
||||
return AzureAppConfigurationClientDeleteKeyValueResponse{}, err
|
||||
}
|
||||
if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) {
|
||||
return AzureAppConfigurationClientDeleteKeyValueResponse{}, runtime.NewResponseError(resp)
|
||||
}
|
||||
return client.deleteKeyValueHandleResponse(resp)
|
||||
}
|
||||
|
||||
// deleteKeyValueCreateRequest creates the DeleteKeyValue request.
|
||||
func (client *AzureAppConfigurationClient) deleteKeyValueCreateRequest(ctx context.Context, key string, options *AzureAppConfigurationClientDeleteKeyValueOptions) (*policy.Request, error) {
|
||||
urlPath := "/kv/{key}"
|
||||
if key == "" {
|
||||
return nil, errors.New("parameter key cannot be empty")
|
||||
}
|
||||
urlPath = strings.ReplaceAll(urlPath, "{key}", url.PathEscape(key))
|
||||
req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.endpoint, urlPath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reqQP := req.Raw().URL.Query()
|
||||
if options != nil && options.Label != nil {
|
||||
reqQP.Set("label", *options.Label)
|
||||
}
|
||||
reqQP.Set("api-version", "1.0")
|
||||
req.Raw().URL.RawQuery = reqQP.Encode()
|
||||
if client.syncToken != nil {
|
||||
req.Raw().Header.Set("Sync-Token", *client.syncToken)
|
||||
}
|
||||
if options != nil && options.IfMatch != nil {
|
||||
req.Raw().Header.Set("If-Match", *options.IfMatch)
|
||||
}
|
||||
req.Raw().Header.Set("Accept", "application/vnd.microsoft.appconfig.kv+json, application/json, application/problem+json")
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// deleteKeyValueHandleResponse handles the DeleteKeyValue response.
|
||||
func (client *AzureAppConfigurationClient) deleteKeyValueHandleResponse(resp *http.Response) (AzureAppConfigurationClientDeleteKeyValueResponse, error) {
|
||||
result := AzureAppConfigurationClientDeleteKeyValueResponse{RawResponse: resp}
|
||||
if val := resp.Header.Get("Sync-Token"); val != "" {
|
||||
result.SyncToken = &val
|
||||
}
|
||||
if val := resp.Header.Get("ETag"); val != "" {
|
||||
result.ETag = &val
|
||||
}
|
||||
if err := runtime.UnmarshalAsJSON(resp, &result.KeyValue); err != nil {
|
||||
return AzureAppConfigurationClientDeleteKeyValueResponse{}, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// DeleteLock - Unlocks a key-value.
|
||||
// If the operation fails it returns an *azcore.ResponseError type.
|
||||
// key - The key of the key-value to unlock.
|
||||
// options - AzureAppConfigurationClientDeleteLockOptions contains the optional parameters for the AzureAppConfigurationClient.DeleteLock
|
||||
// method.
|
||||
func (client *AzureAppConfigurationClient) DeleteLock(ctx context.Context, key string, options *AzureAppConfigurationClientDeleteLockOptions) (AzureAppConfigurationClientDeleteLockResponse, error) {
|
||||
req, err := client.deleteLockCreateRequest(ctx, key, options)
|
||||
if err != nil {
|
||||
return AzureAppConfigurationClientDeleteLockResponse{}, err
|
||||
}
|
||||
resp, err := client.pl.Do(req)
|
||||
if err != nil {
|
||||
return AzureAppConfigurationClientDeleteLockResponse{}, err
|
||||
}
|
||||
if !runtime.HasStatusCode(resp, http.StatusOK) {
|
||||
return AzureAppConfigurationClientDeleteLockResponse{}, runtime.NewResponseError(resp)
|
||||
}
|
||||
return client.deleteLockHandleResponse(resp)
|
||||
}
|
||||
|
||||
// deleteLockCreateRequest creates the DeleteLock request.
|
||||
func (client *AzureAppConfigurationClient) deleteLockCreateRequest(ctx context.Context, key string, options *AzureAppConfigurationClientDeleteLockOptions) (*policy.Request, error) {
|
||||
urlPath := "/locks/{key}"
|
||||
if key == "" {
|
||||
return nil, errors.New("parameter key cannot be empty")
|
||||
}
|
||||
urlPath = strings.ReplaceAll(urlPath, "{key}", url.PathEscape(key))
|
||||
req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.endpoint, urlPath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reqQP := req.Raw().URL.Query()
|
||||
if options != nil && options.Label != nil {
|
||||
reqQP.Set("label", *options.Label)
|
||||
}
|
||||
reqQP.Set("api-version", "1.0")
|
||||
req.Raw().URL.RawQuery = reqQP.Encode()
|
||||
if client.syncToken != nil {
|
||||
req.Raw().Header.Set("Sync-Token", *client.syncToken)
|
||||
}
|
||||
if options != nil && options.IfMatch != nil {
|
||||
req.Raw().Header.Set("If-Match", *options.IfMatch)
|
||||
}
|
||||
if options != nil && options.IfNoneMatch != nil {
|
||||
req.Raw().Header.Set("If-None-Match", *options.IfNoneMatch)
|
||||
}
|
||||
req.Raw().Header.Set("Accept", "application/vnd.microsoft.appconfig.kv+json, application/json, application/problem+json")
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// deleteLockHandleResponse handles the DeleteLock response.
|
||||
func (client *AzureAppConfigurationClient) deleteLockHandleResponse(resp *http.Response) (AzureAppConfigurationClientDeleteLockResponse, error) {
|
||||
result := AzureAppConfigurationClientDeleteLockResponse{RawResponse: resp}
|
||||
if val := resp.Header.Get("Sync-Token"); val != "" {
|
||||
result.SyncToken = &val
|
||||
}
|
||||
if val := resp.Header.Get("ETag"); val != "" {
|
||||
result.ETag = &val
|
||||
}
|
||||
if err := runtime.UnmarshalAsJSON(resp, &result.KeyValue); err != nil {
|
||||
return AzureAppConfigurationClientDeleteLockResponse{}, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetKeyValue - Gets a single key-value.
|
||||
// If the operation fails it returns an *azcore.ResponseError type.
|
||||
// key - The key of the key-value to retrieve.
|
||||
// options - AzureAppConfigurationClientGetKeyValueOptions contains the optional parameters for the AzureAppConfigurationClient.GetKeyValue
|
||||
// method.
|
||||
func (client *AzureAppConfigurationClient) GetKeyValue(ctx context.Context, key string, options *AzureAppConfigurationClientGetKeyValueOptions) (AzureAppConfigurationClientGetKeyValueResponse, error) {
|
||||
req, err := client.getKeyValueCreateRequest(ctx, key, options)
|
||||
if err != nil {
|
||||
return AzureAppConfigurationClientGetKeyValueResponse{}, err
|
||||
}
|
||||
resp, err := client.pl.Do(req)
|
||||
if err != nil {
|
||||
return AzureAppConfigurationClientGetKeyValueResponse{}, err
|
||||
}
|
||||
if !runtime.HasStatusCode(resp, http.StatusOK) {
|
||||
return AzureAppConfigurationClientGetKeyValueResponse{}, runtime.NewResponseError(resp)
|
||||
}
|
||||
return client.getKeyValueHandleResponse(resp)
|
||||
}
|
||||
|
||||
// getKeyValueCreateRequest creates the GetKeyValue request.
|
||||
func (client *AzureAppConfigurationClient) getKeyValueCreateRequest(ctx context.Context, key string, options *AzureAppConfigurationClientGetKeyValueOptions) (*policy.Request, error) {
|
||||
urlPath := "/kv/{key}"
|
||||
if key == "" {
|
||||
return nil, errors.New("parameter key cannot be empty")
|
||||
}
|
||||
urlPath = strings.ReplaceAll(urlPath, "{key}", url.PathEscape(key))
|
||||
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.endpoint, urlPath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reqQP := req.Raw().URL.Query()
|
||||
if options != nil && options.Label != nil {
|
||||
reqQP.Set("label", *options.Label)
|
||||
}
|
||||
reqQP.Set("api-version", "1.0")
|
||||
if options != nil && options.Select != nil {
|
||||
reqQP.Set("$Select", strings.Join(strings.Fields(strings.Trim(fmt.Sprint(options.Select), "[]")), ","))
|
||||
}
|
||||
req.Raw().URL.RawQuery = reqQP.Encode()
|
||||
if client.syncToken != nil {
|
||||
req.Raw().Header.Set("Sync-Token", *client.syncToken)
|
||||
}
|
||||
if options != nil && options.AcceptDatetime != nil {
|
||||
req.Raw().Header.Set("Accept-Datetime", *options.AcceptDatetime)
|
||||
}
|
||||
if options != nil && options.IfMatch != nil {
|
||||
req.Raw().Header.Set("If-Match", *options.IfMatch)
|
||||
}
|
||||
if options != nil && options.IfNoneMatch != nil {
|
||||
req.Raw().Header.Set("If-None-Match", *options.IfNoneMatch)
|
||||
}
|
||||
req.Raw().Header.Set("Accept", "application/vnd.microsoft.appconfig.kv+json, application/json, application/problem+json")
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// getKeyValueHandleResponse handles the GetKeyValue response.
|
||||
func (client *AzureAppConfigurationClient) getKeyValueHandleResponse(resp *http.Response) (AzureAppConfigurationClientGetKeyValueResponse, error) {
|
||||
result := AzureAppConfigurationClientGetKeyValueResponse{RawResponse: resp}
|
||||
if val := resp.Header.Get("Sync-Token"); val != "" {
|
||||
result.SyncToken = &val
|
||||
}
|
||||
if val := resp.Header.Get("ETag"); val != "" {
|
||||
result.ETag = &val
|
||||
}
|
||||
if val := resp.Header.Get("Last-Modified"); val != "" {
|
||||
result.LastModified = &val
|
||||
}
|
||||
if err := runtime.UnmarshalAsJSON(resp, &result.KeyValue); err != nil {
|
||||
return AzureAppConfigurationClientGetKeyValueResponse{}, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetKeyValues - Gets a list of key-values.
|
||||
// If the operation fails it returns an *azcore.ResponseError type.
|
||||
// options - AzureAppConfigurationClientGetKeyValuesOptions contains the optional parameters for the AzureAppConfigurationClient.GetKeyValues
|
||||
// method.
|
||||
func (client *AzureAppConfigurationClient) GetKeyValues(options *AzureAppConfigurationClientGetKeyValuesOptions) *AzureAppConfigurationClientGetKeyValuesPager {
|
||||
return &AzureAppConfigurationClientGetKeyValuesPager{
|
||||
client: client,
|
||||
requester: func(ctx context.Context) (*policy.Request, error) {
|
||||
return client.getKeyValuesCreateRequest(ctx, options)
|
||||
},
|
||||
advancer: func(ctx context.Context, resp AzureAppConfigurationClientGetKeyValuesResponse) (*policy.Request, error) {
|
||||
return runtime.NewRequest(ctx, http.MethodGet, *resp.KeyValueListResult.NextLink)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// getKeyValuesCreateRequest creates the GetKeyValues request.
|
||||
func (client *AzureAppConfigurationClient) getKeyValuesCreateRequest(ctx context.Context, options *AzureAppConfigurationClientGetKeyValuesOptions) (*policy.Request, error) {
|
||||
urlPath := "/kv"
|
||||
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.endpoint, urlPath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reqQP := req.Raw().URL.Query()
|
||||
if options != nil && options.Key != nil {
|
||||
reqQP.Set("key", *options.Key)
|
||||
}
|
||||
if options != nil && options.Label != nil {
|
||||
reqQP.Set("label", *options.Label)
|
||||
}
|
||||
reqQP.Set("api-version", "1.0")
|
||||
if options != nil && options.After != nil {
|
||||
reqQP.Set("After", *options.After)
|
||||
}
|
||||
if options != nil && options.Select != nil {
|
||||
reqQP.Set("$Select", strings.Join(strings.Fields(strings.Trim(fmt.Sprint(options.Select), "[]")), ","))
|
||||
}
|
||||
req.Raw().URL.RawQuery = reqQP.Encode()
|
||||
if client.syncToken != nil {
|
||||
req.Raw().Header.Set("Sync-Token", *client.syncToken)
|
||||
}
|
||||
if options != nil && options.AcceptDatetime != nil {
|
||||
req.Raw().Header.Set("Accept-Datetime", *options.AcceptDatetime)
|
||||
}
|
||||
req.Raw().Header.Set("Accept", "application/vnd.microsoft.appconfig.kvset+json, application/json, application/problem+json")
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// getKeyValuesHandleResponse handles the GetKeyValues response.
|
||||
func (client *AzureAppConfigurationClient) getKeyValuesHandleResponse(resp *http.Response) (AzureAppConfigurationClientGetKeyValuesResponse, error) {
|
||||
result := AzureAppConfigurationClientGetKeyValuesResponse{RawResponse: resp}
|
||||
if val := resp.Header.Get("Sync-Token"); val != "" {
|
||||
result.SyncToken = &val
|
||||
}
|
||||
if err := runtime.UnmarshalAsJSON(resp, &result.KeyValueListResult); err != nil {
|
||||
return AzureAppConfigurationClientGetKeyValuesResponse{}, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetKeys - Gets a list of keys.
|
||||
// If the operation fails it returns an *azcore.ResponseError type.
|
||||
// options - AzureAppConfigurationClientGetKeysOptions contains the optional parameters for the AzureAppConfigurationClient.GetKeys
|
||||
// method.
|
||||
func (client *AzureAppConfigurationClient) GetKeys(options *AzureAppConfigurationClientGetKeysOptions) *AzureAppConfigurationClientGetKeysPager {
|
||||
return &AzureAppConfigurationClientGetKeysPager{
|
||||
client: client,
|
||||
requester: func(ctx context.Context) (*policy.Request, error) {
|
||||
return client.getKeysCreateRequest(ctx, options)
|
||||
},
|
||||
advancer: func(ctx context.Context, resp AzureAppConfigurationClientGetKeysResponse) (*policy.Request, error) {
|
||||
return runtime.NewRequest(ctx, http.MethodGet, *resp.KeyListResult.NextLink)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// getKeysCreateRequest creates the GetKeys request.
|
||||
func (client *AzureAppConfigurationClient) getKeysCreateRequest(ctx context.Context, options *AzureAppConfigurationClientGetKeysOptions) (*policy.Request, error) {
|
||||
urlPath := "/keys"
|
||||
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.endpoint, urlPath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reqQP := req.Raw().URL.Query()
|
||||
if options != nil && options.Name != nil {
|
||||
reqQP.Set("name", *options.Name)
|
||||
}
|
||||
reqQP.Set("api-version", "1.0")
|
||||
if options != nil && options.After != nil {
|
||||
reqQP.Set("After", *options.After)
|
||||
}
|
||||
req.Raw().URL.RawQuery = reqQP.Encode()
|
||||
if client.syncToken != nil {
|
||||
req.Raw().Header.Set("Sync-Token", *client.syncToken)
|
||||
}
|
||||
if options != nil && options.AcceptDatetime != nil {
|
||||
req.Raw().Header.Set("Accept-Datetime", *options.AcceptDatetime)
|
||||
}
|
||||
req.Raw().Header.Set("Accept", "application/vnd.microsoft.appconfig.keyset+json, application/json, application/problem+json")
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// getKeysHandleResponse handles the GetKeys response.
|
||||
func (client *AzureAppConfigurationClient) getKeysHandleResponse(resp *http.Response) (AzureAppConfigurationClientGetKeysResponse, error) {
|
||||
result := AzureAppConfigurationClientGetKeysResponse{RawResponse: resp}
|
||||
if val := resp.Header.Get("Sync-Token"); val != "" {
|
||||
result.SyncToken = &val
|
||||
}
|
||||
if err := runtime.UnmarshalAsJSON(resp, &result.KeyListResult); err != nil {
|
||||
return AzureAppConfigurationClientGetKeysResponse{}, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetLabels - Gets a list of labels.
|
||||
// If the operation fails it returns an *azcore.ResponseError type.
|
||||
// options - AzureAppConfigurationClientGetLabelsOptions contains the optional parameters for the AzureAppConfigurationClient.GetLabels
|
||||
// method.
|
||||
func (client *AzureAppConfigurationClient) GetLabels(options *AzureAppConfigurationClientGetLabelsOptions) *AzureAppConfigurationClientGetLabelsPager {
|
||||
return &AzureAppConfigurationClientGetLabelsPager{
|
||||
client: client,
|
||||
requester: func(ctx context.Context) (*policy.Request, error) {
|
||||
return client.getLabelsCreateRequest(ctx, options)
|
||||
},
|
||||
advancer: func(ctx context.Context, resp AzureAppConfigurationClientGetLabelsResponse) (*policy.Request, error) {
|
||||
return runtime.NewRequest(ctx, http.MethodGet, *resp.LabelListResult.NextLink)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// getLabelsCreateRequest creates the GetLabels request.
|
||||
func (client *AzureAppConfigurationClient) getLabelsCreateRequest(ctx context.Context, options *AzureAppConfigurationClientGetLabelsOptions) (*policy.Request, error) {
|
||||
urlPath := "/labels"
|
||||
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.endpoint, urlPath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reqQP := req.Raw().URL.Query()
|
||||
if options != nil && options.Name != nil {
|
||||
reqQP.Set("name", *options.Name)
|
||||
}
|
||||
reqQP.Set("api-version", "1.0")
|
||||
if options != nil && options.After != nil {
|
||||
reqQP.Set("After", *options.After)
|
||||
}
|
||||
if options != nil && options.Select != nil {
|
||||
reqQP.Set("$Select", strings.Join(strings.Fields(strings.Trim(fmt.Sprint(options.Select), "[]")), ","))
|
||||
}
|
||||
req.Raw().URL.RawQuery = reqQP.Encode()
|
||||
if client.syncToken != nil {
|
||||
req.Raw().Header.Set("Sync-Token", *client.syncToken)
|
||||
}
|
||||
if options != nil && options.AcceptDatetime != nil {
|
||||
req.Raw().Header.Set("Accept-Datetime", *options.AcceptDatetime)
|
||||
}
|
||||
req.Raw().Header.Set("Accept", "application/vnd.microsoft.appconfig.labelset+json, application/json, application/problem+json")
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// getLabelsHandleResponse handles the GetLabels response.
|
||||
func (client *AzureAppConfigurationClient) getLabelsHandleResponse(resp *http.Response) (AzureAppConfigurationClientGetLabelsResponse, error) {
|
||||
result := AzureAppConfigurationClientGetLabelsResponse{RawResponse: resp}
|
||||
if val := resp.Header.Get("Sync-Token"); val != "" {
|
||||
result.SyncToken = &val
|
||||
}
|
||||
if err := runtime.UnmarshalAsJSON(resp, &result.LabelListResult); err != nil {
|
||||
return AzureAppConfigurationClientGetLabelsResponse{}, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetRevisions - Gets a list of key-value revisions.
|
||||
// If the operation fails it returns an *azcore.ResponseError type.
|
||||
// options - AzureAppConfigurationClientGetRevisionsOptions contains the optional parameters for the AzureAppConfigurationClient.GetRevisions
|
||||
// method.
|
||||
func (client *AzureAppConfigurationClient) GetRevisions(options *AzureAppConfigurationClientGetRevisionsOptions) *AzureAppConfigurationClientGetRevisionsPager {
|
||||
return &AzureAppConfigurationClientGetRevisionsPager{
|
||||
client: client,
|
||||
requester: func(ctx context.Context) (*policy.Request, error) {
|
||||
return client.getRevisionsCreateRequest(ctx, options)
|
||||
},
|
||||
advancer: func(ctx context.Context, resp AzureAppConfigurationClientGetRevisionsResponse) (*policy.Request, error) {
|
||||
return runtime.NewRequest(ctx, http.MethodGet, *resp.KeyValueListResult.NextLink)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// getRevisionsCreateRequest creates the GetRevisions request.
|
||||
func (client *AzureAppConfigurationClient) getRevisionsCreateRequest(ctx context.Context, options *AzureAppConfigurationClientGetRevisionsOptions) (*policy.Request, error) {
|
||||
urlPath := "/revisions"
|
||||
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.endpoint, urlPath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reqQP := req.Raw().URL.Query()
|
||||
if options != nil && options.Key != nil {
|
||||
reqQP.Set("key", *options.Key)
|
||||
}
|
||||
if options != nil && options.Label != nil {
|
||||
reqQP.Set("label", *options.Label)
|
||||
}
|
||||
reqQP.Set("api-version", "1.0")
|
||||
if options != nil && options.After != nil {
|
||||
reqQP.Set("After", *options.After)
|
||||
}
|
||||
if options != nil && options.Select != nil {
|
||||
reqQP.Set("$Select", strings.Join(strings.Fields(strings.Trim(fmt.Sprint(options.Select), "[]")), ","))
|
||||
}
|
||||
req.Raw().URL.RawQuery = reqQP.Encode()
|
||||
if client.syncToken != nil {
|
||||
req.Raw().Header.Set("Sync-Token", *client.syncToken)
|
||||
}
|
||||
if options != nil && options.AcceptDatetime != nil {
|
||||
req.Raw().Header.Set("Accept-Datetime", *options.AcceptDatetime)
|
||||
}
|
||||
req.Raw().Header.Set("Accept", "application/vnd.microsoft.appconfig.kvset+json, application/json, application/problem+json")
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// getRevisionsHandleResponse handles the GetRevisions response.
|
||||
func (client *AzureAppConfigurationClient) getRevisionsHandleResponse(resp *http.Response) (AzureAppConfigurationClientGetRevisionsResponse, error) {
|
||||
result := AzureAppConfigurationClientGetRevisionsResponse{RawResponse: resp}
|
||||
if val := resp.Header.Get("Sync-Token"); val != "" {
|
||||
result.SyncToken = &val
|
||||
}
|
||||
if err := runtime.UnmarshalAsJSON(resp, &result.KeyValueListResult); err != nil {
|
||||
return AzureAppConfigurationClientGetRevisionsResponse{}, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// PutKeyValue - Creates a key-value.
|
||||
// If the operation fails it returns an *azcore.ResponseError type.
|
||||
// key - The key of the key-value to create.
|
||||
// options - AzureAppConfigurationClientPutKeyValueOptions contains the optional parameters for the AzureAppConfigurationClient.PutKeyValue
|
||||
// method.
|
||||
func (client *AzureAppConfigurationClient) PutKeyValue(ctx context.Context, key string, options *AzureAppConfigurationClientPutKeyValueOptions) (AzureAppConfigurationClientPutKeyValueResponse, error) {
|
||||
req, err := client.putKeyValueCreateRequest(ctx, key, options)
|
||||
if err != nil {
|
||||
return AzureAppConfigurationClientPutKeyValueResponse{}, err
|
||||
}
|
||||
resp, err := client.pl.Do(req)
|
||||
if err != nil {
|
||||
return AzureAppConfigurationClientPutKeyValueResponse{}, err
|
||||
}
|
||||
if !runtime.HasStatusCode(resp, http.StatusOK) {
|
||||
return AzureAppConfigurationClientPutKeyValueResponse{}, runtime.NewResponseError(resp)
|
||||
}
|
||||
return client.putKeyValueHandleResponse(resp)
|
||||
}
|
||||
|
||||
// putKeyValueCreateRequest creates the PutKeyValue request.
|
||||
func (client *AzureAppConfigurationClient) putKeyValueCreateRequest(ctx context.Context, key string, options *AzureAppConfigurationClientPutKeyValueOptions) (*policy.Request, error) {
|
||||
urlPath := "/kv/{key}"
|
||||
if key == "" {
|
||||
return nil, errors.New("parameter key cannot be empty")
|
||||
}
|
||||
urlPath = strings.ReplaceAll(urlPath, "{key}", url.PathEscape(key))
|
||||
req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.endpoint, urlPath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reqQP := req.Raw().URL.Query()
|
||||
if options != nil && options.Label != nil {
|
||||
reqQP.Set("label", *options.Label)
|
||||
}
|
||||
reqQP.Set("api-version", "1.0")
|
||||
req.Raw().URL.RawQuery = reqQP.Encode()
|
||||
if client.syncToken != nil {
|
||||
req.Raw().Header.Set("Sync-Token", *client.syncToken)
|
||||
}
|
||||
if options != nil && options.IfMatch != nil {
|
||||
req.Raw().Header.Set("If-Match", *options.IfMatch)
|
||||
}
|
||||
if options != nil && options.IfNoneMatch != nil {
|
||||
req.Raw().Header.Set("If-None-Match", *options.IfNoneMatch)
|
||||
}
|
||||
req.Raw().Header.Set("Accept", "application/vnd.microsoft.appconfig.kv+json, application/json, application/problem+json")
|
||||
if options != nil && options.Entity != nil {
|
||||
return req, runtime.MarshalAsJSON(req, *options.Entity)
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// putKeyValueHandleResponse handles the PutKeyValue response.
|
||||
func (client *AzureAppConfigurationClient) putKeyValueHandleResponse(resp *http.Response) (AzureAppConfigurationClientPutKeyValueResponse, error) {
|
||||
result := AzureAppConfigurationClientPutKeyValueResponse{RawResponse: resp}
|
||||
if val := resp.Header.Get("Sync-Token"); val != "" {
|
||||
result.SyncToken = &val
|
||||
}
|
||||
if val := resp.Header.Get("ETag"); val != "" {
|
||||
result.ETag = &val
|
||||
}
|
||||
if err := runtime.UnmarshalAsJSON(resp, &result.KeyValue); err != nil {
|
||||
return AzureAppConfigurationClientPutKeyValueResponse{}, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// PutLock - Locks a key-value.
|
||||
// If the operation fails it returns an *azcore.ResponseError type.
|
||||
// key - The key of the key-value to lock.
|
||||
// options - AzureAppConfigurationClientPutLockOptions contains the optional parameters for the AzureAppConfigurationClient.PutLock
|
||||
// method.
|
||||
func (client *AzureAppConfigurationClient) PutLock(ctx context.Context, key string, options *AzureAppConfigurationClientPutLockOptions) (AzureAppConfigurationClientPutLockResponse, error) {
|
||||
req, err := client.putLockCreateRequest(ctx, key, options)
|
||||
if err != nil {
|
||||
return AzureAppConfigurationClientPutLockResponse{}, err
|
||||
}
|
||||
resp, err := client.pl.Do(req)
|
||||
if err != nil {
|
||||
return AzureAppConfigurationClientPutLockResponse{}, err
|
||||
}
|
||||
if !runtime.HasStatusCode(resp, http.StatusOK) {
|
||||
return AzureAppConfigurationClientPutLockResponse{}, runtime.NewResponseError(resp)
|
||||
}
|
||||
return client.putLockHandleResponse(resp)
|
||||
}
|
||||
|
||||
// putLockCreateRequest creates the PutLock request.
|
||||
func (client *AzureAppConfigurationClient) putLockCreateRequest(ctx context.Context, key string, options *AzureAppConfigurationClientPutLockOptions) (*policy.Request, error) {
|
||||
urlPath := "/locks/{key}"
|
||||
if key == "" {
|
||||
return nil, errors.New("parameter key cannot be empty")
|
||||
}
|
||||
urlPath = strings.ReplaceAll(urlPath, "{key}", url.PathEscape(key))
|
||||
req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.endpoint, urlPath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reqQP := req.Raw().URL.Query()
|
||||
if options != nil && options.Label != nil {
|
||||
reqQP.Set("label", *options.Label)
|
||||
}
|
||||
reqQP.Set("api-version", "1.0")
|
||||
req.Raw().URL.RawQuery = reqQP.Encode()
|
||||
if client.syncToken != nil {
|
||||
req.Raw().Header.Set("Sync-Token", *client.syncToken)
|
||||
}
|
||||
if options != nil && options.IfMatch != nil {
|
||||
req.Raw().Header.Set("If-Match", *options.IfMatch)
|
||||
}
|
||||
if options != nil && options.IfNoneMatch != nil {
|
||||
req.Raw().Header.Set("If-None-Match", *options.IfNoneMatch)
|
||||
}
|
||||
req.Raw().Header.Set("Accept", "application/vnd.microsoft.appconfig.kv+json, application/json, application/problem+json")
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// putLockHandleResponse handles the PutLock response.
|
||||
func (client *AzureAppConfigurationClient) putLockHandleResponse(resp *http.Response) (AzureAppConfigurationClientPutLockResponse, error) {
|
||||
result := AzureAppConfigurationClientPutLockResponse{RawResponse: resp}
|
||||
if val := resp.Header.Get("Sync-Token"); val != "" {
|
||||
result.SyncToken = &val
|
||||
}
|
||||
if val := resp.Header.Get("ETag"); val != "" {
|
||||
result.ETag = &val
|
||||
}
|
||||
if err := runtime.UnmarshalAsJSON(resp, &result.KeyValue); err != nil {
|
||||
return AzureAppConfigurationClientPutLockResponse{}, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
|
@ -0,0 +1,242 @@
|
|||
//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 generated
|
||||
|
||||
const (
|
||||
ModuleName = "azappconfiguration"
|
||||
ModuleVersion = "v0.1.0"
|
||||
)
|
||||
|
||||
type Enum6 string
|
||||
|
||||
const (
|
||||
Enum6ContentType Enum6 = "content_type"
|
||||
Enum6Etag Enum6 = "etag"
|
||||
Enum6Key Enum6 = "key"
|
||||
Enum6Label Enum6 = "label"
|
||||
Enum6LastModified Enum6 = "last_modified"
|
||||
Enum6Locked Enum6 = "locked"
|
||||
Enum6Tags Enum6 = "tags"
|
||||
Enum6Value Enum6 = "value"
|
||||
)
|
||||
|
||||
// PossibleEnum6Values returns the possible values for the Enum6 const type.
|
||||
func PossibleEnum6Values() []Enum6 {
|
||||
return []Enum6{
|
||||
Enum6ContentType,
|
||||
Enum6Etag,
|
||||
Enum6Key,
|
||||
Enum6Label,
|
||||
Enum6LastModified,
|
||||
Enum6Locked,
|
||||
Enum6Tags,
|
||||
Enum6Value,
|
||||
}
|
||||
}
|
||||
|
||||
// ToPtr returns a *Enum6 pointing to the current value.
|
||||
func (c Enum6) ToPtr() *Enum6 {
|
||||
return &c
|
||||
}
|
||||
|
||||
type Enum7 string
|
||||
|
||||
const (
|
||||
Enum7ContentType Enum7 = "content_type"
|
||||
Enum7Etag Enum7 = "etag"
|
||||
Enum7Key Enum7 = "key"
|
||||
Enum7Label Enum7 = "label"
|
||||
Enum7LastModified Enum7 = "last_modified"
|
||||
Enum7Locked Enum7 = "locked"
|
||||
Enum7Tags Enum7 = "tags"
|
||||
Enum7Value Enum7 = "value"
|
||||
)
|
||||
|
||||
// PossibleEnum7Values returns the possible values for the Enum7 const type.
|
||||
func PossibleEnum7Values() []Enum7 {
|
||||
return []Enum7{
|
||||
Enum7ContentType,
|
||||
Enum7Etag,
|
||||
Enum7Key,
|
||||
Enum7Label,
|
||||
Enum7LastModified,
|
||||
Enum7Locked,
|
||||
Enum7Tags,
|
||||
Enum7Value,
|
||||
}
|
||||
}
|
||||
|
||||
// ToPtr returns a *Enum7 pointing to the current value.
|
||||
func (c Enum7) ToPtr() *Enum7 {
|
||||
return &c
|
||||
}
|
||||
|
||||
type Get5ItemsItem string
|
||||
|
||||
const (
|
||||
Get5ItemsItemName Get5ItemsItem = "name"
|
||||
)
|
||||
|
||||
// PossibleGet5ItemsItemValues returns the possible values for the Get5ItemsItem const type.
|
||||
func PossibleGet5ItemsItemValues() []Get5ItemsItem {
|
||||
return []Get5ItemsItem{
|
||||
Get5ItemsItemName,
|
||||
}
|
||||
}
|
||||
|
||||
// ToPtr returns a *Get5ItemsItem pointing to the current value.
|
||||
func (c Get5ItemsItem) ToPtr() *Get5ItemsItem {
|
||||
return &c
|
||||
}
|
||||
|
||||
type Get6ItemsItem string
|
||||
|
||||
const (
|
||||
Get6ItemsItemContentType Get6ItemsItem = "content_type"
|
||||
Get6ItemsItemEtag Get6ItemsItem = "etag"
|
||||
Get6ItemsItemKey Get6ItemsItem = "key"
|
||||
Get6ItemsItemLabel Get6ItemsItem = "label"
|
||||
Get6ItemsItemLastModified Get6ItemsItem = "last_modified"
|
||||
Get6ItemsItemLocked Get6ItemsItem = "locked"
|
||||
Get6ItemsItemTags Get6ItemsItem = "tags"
|
||||
Get6ItemsItemValue Get6ItemsItem = "value"
|
||||
)
|
||||
|
||||
// PossibleGet6ItemsItemValues returns the possible values for the Get6ItemsItem const type.
|
||||
func PossibleGet6ItemsItemValues() []Get6ItemsItem {
|
||||
return []Get6ItemsItem{
|
||||
Get6ItemsItemContentType,
|
||||
Get6ItemsItemEtag,
|
||||
Get6ItemsItemKey,
|
||||
Get6ItemsItemLabel,
|
||||
Get6ItemsItemLastModified,
|
||||
Get6ItemsItemLocked,
|
||||
Get6ItemsItemTags,
|
||||
Get6ItemsItemValue,
|
||||
}
|
||||
}
|
||||
|
||||
// ToPtr returns a *Get6ItemsItem pointing to the current value.
|
||||
func (c Get6ItemsItem) ToPtr() *Get6ItemsItem {
|
||||
return &c
|
||||
}
|
||||
|
||||
type Get7ItemsItem string
|
||||
|
||||
const (
|
||||
Get7ItemsItemContentType Get7ItemsItem = "content_type"
|
||||
Get7ItemsItemEtag Get7ItemsItem = "etag"
|
||||
Get7ItemsItemKey Get7ItemsItem = "key"
|
||||
Get7ItemsItemLabel Get7ItemsItem = "label"
|
||||
Get7ItemsItemLastModified Get7ItemsItem = "last_modified"
|
||||
Get7ItemsItemLocked Get7ItemsItem = "locked"
|
||||
Get7ItemsItemTags Get7ItemsItem = "tags"
|
||||
Get7ItemsItemValue Get7ItemsItem = "value"
|
||||
)
|
||||
|
||||
// PossibleGet7ItemsItemValues returns the possible values for the Get7ItemsItem const type.
|
||||
func PossibleGet7ItemsItemValues() []Get7ItemsItem {
|
||||
return []Get7ItemsItem{
|
||||
Get7ItemsItemContentType,
|
||||
Get7ItemsItemEtag,
|
||||
Get7ItemsItemKey,
|
||||
Get7ItemsItemLabel,
|
||||
Get7ItemsItemLastModified,
|
||||
Get7ItemsItemLocked,
|
||||
Get7ItemsItemTags,
|
||||
Get7ItemsItemValue,
|
||||
}
|
||||
}
|
||||
|
||||
// ToPtr returns a *Get7ItemsItem pointing to the current value.
|
||||
func (c Get7ItemsItem) ToPtr() *Get7ItemsItem {
|
||||
return &c
|
||||
}
|
||||
|
||||
type Head5ItemsItem string
|
||||
|
||||
const (
|
||||
Head5ItemsItemName Head5ItemsItem = "name"
|
||||
)
|
||||
|
||||
// PossibleHead5ItemsItemValues returns the possible values for the Head5ItemsItem const type.
|
||||
func PossibleHead5ItemsItemValues() []Head5ItemsItem {
|
||||
return []Head5ItemsItem{
|
||||
Head5ItemsItemName,
|
||||
}
|
||||
}
|
||||
|
||||
// ToPtr returns a *Head5ItemsItem pointing to the current value.
|
||||
func (c Head5ItemsItem) ToPtr() *Head5ItemsItem {
|
||||
return &c
|
||||
}
|
||||
|
||||
type Head6ItemsItem string
|
||||
|
||||
const (
|
||||
Head6ItemsItemContentType Head6ItemsItem = "content_type"
|
||||
Head6ItemsItemEtag Head6ItemsItem = "etag"
|
||||
Head6ItemsItemKey Head6ItemsItem = "key"
|
||||
Head6ItemsItemLabel Head6ItemsItem = "label"
|
||||
Head6ItemsItemLastModified Head6ItemsItem = "last_modified"
|
||||
Head6ItemsItemLocked Head6ItemsItem = "locked"
|
||||
Head6ItemsItemTags Head6ItemsItem = "tags"
|
||||
Head6ItemsItemValue Head6ItemsItem = "value"
|
||||
)
|
||||
|
||||
// PossibleHead6ItemsItemValues returns the possible values for the Head6ItemsItem const type.
|
||||
func PossibleHead6ItemsItemValues() []Head6ItemsItem {
|
||||
return []Head6ItemsItem{
|
||||
Head6ItemsItemContentType,
|
||||
Head6ItemsItemEtag,
|
||||
Head6ItemsItemKey,
|
||||
Head6ItemsItemLabel,
|
||||
Head6ItemsItemLastModified,
|
||||
Head6ItemsItemLocked,
|
||||
Head6ItemsItemTags,
|
||||
Head6ItemsItemValue,
|
||||
}
|
||||
}
|
||||
|
||||
// ToPtr returns a *Head6ItemsItem pointing to the current value.
|
||||
func (c Head6ItemsItem) ToPtr() *Head6ItemsItem {
|
||||
return &c
|
||||
}
|
||||
|
||||
type Head7ItemsItem string
|
||||
|
||||
const (
|
||||
Head7ItemsItemContentType Head7ItemsItem = "content_type"
|
||||
Head7ItemsItemEtag Head7ItemsItem = "etag"
|
||||
Head7ItemsItemKey Head7ItemsItem = "key"
|
||||
Head7ItemsItemLabel Head7ItemsItem = "label"
|
||||
Head7ItemsItemLastModified Head7ItemsItem = "last_modified"
|
||||
Head7ItemsItemLocked Head7ItemsItem = "locked"
|
||||
Head7ItemsItemTags Head7ItemsItem = "tags"
|
||||
Head7ItemsItemValue Head7ItemsItem = "value"
|
||||
)
|
||||
|
||||
// PossibleHead7ItemsItemValues returns the possible values for the Head7ItemsItem const type.
|
||||
func PossibleHead7ItemsItemValues() []Head7ItemsItem {
|
||||
return []Head7ItemsItem{
|
||||
Head7ItemsItemContentType,
|
||||
Head7ItemsItemEtag,
|
||||
Head7ItemsItemKey,
|
||||
Head7ItemsItemLabel,
|
||||
Head7ItemsItemLastModified,
|
||||
Head7ItemsItemLocked,
|
||||
Head7ItemsItemTags,
|
||||
Head7ItemsItemValue,
|
||||
}
|
||||
}
|
||||
|
||||
// ToPtr returns a *Head7ItemsItem pointing to the current value.
|
||||
func (c Head7ItemsItem) ToPtr() *Head7ItemsItem {
|
||||
return &c
|
||||
}
|
|
@ -0,0 +1,363 @@
|
|||
//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 generated
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
|
||||
)
|
||||
|
||||
// AzureAppConfigurationClientCheckKeyValueOptions contains the optional parameters for the AzureAppConfigurationClient.CheckKeyValue
|
||||
// method.
|
||||
type AzureAppConfigurationClientCheckKeyValueOptions struct {
|
||||
// Requests the server to respond with the state of the resource at the specified time.
|
||||
AcceptDatetime *string
|
||||
// Used to perform an operation only if the targeted resource's etag matches the value provided.
|
||||
IfMatch *string
|
||||
// Used to perform an operation only if the targeted resource's etag does not match the value provided.
|
||||
IfNoneMatch *string
|
||||
// The label of the key-value to retrieve.
|
||||
Label *string
|
||||
// Used to select what fields are present in the returned resource(s).
|
||||
Select []Head7ItemsItem
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientCheckKeyValuesOptions contains the optional parameters for the AzureAppConfigurationClient.CheckKeyValues
|
||||
// method.
|
||||
type AzureAppConfigurationClientCheckKeyValuesOptions struct {
|
||||
// Requests the server to respond with the state of the resource at the specified time.
|
||||
AcceptDatetime *string
|
||||
// Instructs the server to return elements that appear after the element referred to by the specified token.
|
||||
After *string
|
||||
// A filter used to match keys.
|
||||
Key *string
|
||||
// A filter used to match labels
|
||||
Label *string
|
||||
// Used to select what fields are present in the returned resource(s).
|
||||
Select []Head6ItemsItem
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientCheckKeysOptions contains the optional parameters for the AzureAppConfigurationClient.CheckKeys
|
||||
// method.
|
||||
type AzureAppConfigurationClientCheckKeysOptions struct {
|
||||
// Requests the server to respond with the state of the resource at the specified time.
|
||||
AcceptDatetime *string
|
||||
// Instructs the server to return elements that appear after the element referred to by the specified token.
|
||||
After *string
|
||||
// A filter for the name of the returned keys.
|
||||
Name *string
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientCheckLabelsOptions contains the optional parameters for the AzureAppConfigurationClient.CheckLabels
|
||||
// method.
|
||||
type AzureAppConfigurationClientCheckLabelsOptions struct {
|
||||
// Requests the server to respond with the state of the resource at the specified time.
|
||||
AcceptDatetime *string
|
||||
// Instructs the server to return elements that appear after the element referred to by the specified token.
|
||||
After *string
|
||||
// A filter for the name of the returned labels.
|
||||
Name *string
|
||||
// Used to select what fields are present in the returned resource(s).
|
||||
Select []Head5ItemsItem
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientCheckRevisionsOptions contains the optional parameters for the AzureAppConfigurationClient.CheckRevisions
|
||||
// method.
|
||||
type AzureAppConfigurationClientCheckRevisionsOptions struct {
|
||||
// Requests the server to respond with the state of the resource at the specified time.
|
||||
AcceptDatetime *string
|
||||
// Instructs the server to return elements that appear after the element referred to by the specified token.
|
||||
After *string
|
||||
// A filter used to match keys.
|
||||
Key *string
|
||||
// A filter used to match labels
|
||||
Label *string
|
||||
// Used to select what fields are present in the returned resource(s).
|
||||
Select []Enum7
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientDeleteKeyValueOptions contains the optional parameters for the AzureAppConfigurationClient.DeleteKeyValue
|
||||
// method.
|
||||
type AzureAppConfigurationClientDeleteKeyValueOptions struct {
|
||||
// Used to perform an operation only if the targeted resource's etag matches the value provided.
|
||||
IfMatch *string
|
||||
// The label of the key-value to delete.
|
||||
Label *string
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientDeleteLockOptions contains the optional parameters for the AzureAppConfigurationClient.DeleteLock
|
||||
// method.
|
||||
type AzureAppConfigurationClientDeleteLockOptions struct {
|
||||
// Used to perform an operation only if the targeted resource's etag matches the value provided.
|
||||
IfMatch *string
|
||||
// Used to perform an operation only if the targeted resource's etag does not match the value provided.
|
||||
IfNoneMatch *string
|
||||
// The label, if any, of the key-value to unlock.
|
||||
Label *string
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientGetKeyValueOptions contains the optional parameters for the AzureAppConfigurationClient.GetKeyValue
|
||||
// method.
|
||||
type AzureAppConfigurationClientGetKeyValueOptions struct {
|
||||
// Requests the server to respond with the state of the resource at the specified time.
|
||||
AcceptDatetime *string
|
||||
// Used to perform an operation only if the targeted resource's etag matches the value provided.
|
||||
IfMatch *string
|
||||
// Used to perform an operation only if the targeted resource's etag does not match the value provided.
|
||||
IfNoneMatch *string
|
||||
// The label of the key-value to retrieve.
|
||||
Label *string
|
||||
// Used to select what fields are present in the returned resource(s).
|
||||
Select []Get7ItemsItem
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientGetKeyValuesOptions contains the optional parameters for the AzureAppConfigurationClient.GetKeyValues
|
||||
// method.
|
||||
type AzureAppConfigurationClientGetKeyValuesOptions struct {
|
||||
// Requests the server to respond with the state of the resource at the specified time.
|
||||
AcceptDatetime *string
|
||||
// Instructs the server to return elements that appear after the element referred to by the specified token.
|
||||
After *string
|
||||
// A filter used to match keys.
|
||||
Key *string
|
||||
// A filter used to match labels
|
||||
Label *string
|
||||
// Used to select what fields are present in the returned resource(s).
|
||||
Select []Get6ItemsItem
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientGetKeysOptions contains the optional parameters for the AzureAppConfigurationClient.GetKeys
|
||||
// method.
|
||||
type AzureAppConfigurationClientGetKeysOptions struct {
|
||||
// Requests the server to respond with the state of the resource at the specified time.
|
||||
AcceptDatetime *string
|
||||
// Instructs the server to return elements that appear after the element referred to by the specified token.
|
||||
After *string
|
||||
// A filter for the name of the returned keys.
|
||||
Name *string
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientGetLabelsOptions contains the optional parameters for the AzureAppConfigurationClient.GetLabels
|
||||
// method.
|
||||
type AzureAppConfigurationClientGetLabelsOptions struct {
|
||||
// Requests the server to respond with the state of the resource at the specified time.
|
||||
AcceptDatetime *string
|
||||
// Instructs the server to return elements that appear after the element referred to by the specified token.
|
||||
After *string
|
||||
// A filter for the name of the returned labels.
|
||||
Name *string
|
||||
// Used to select what fields are present in the returned resource(s).
|
||||
Select []Get5ItemsItem
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientGetRevisionsOptions contains the optional parameters for the AzureAppConfigurationClient.GetRevisions
|
||||
// method.
|
||||
type AzureAppConfigurationClientGetRevisionsOptions struct {
|
||||
// Requests the server to respond with the state of the resource at the specified time.
|
||||
AcceptDatetime *string
|
||||
// Instructs the server to return elements that appear after the element referred to by the specified token.
|
||||
After *string
|
||||
// A filter used to match keys.
|
||||
Key *string
|
||||
// A filter used to match labels
|
||||
Label *string
|
||||
// Used to select what fields are present in the returned resource(s).
|
||||
Select []Enum6
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientPutKeyValueOptions contains the optional parameters for the AzureAppConfigurationClient.PutKeyValue
|
||||
// method.
|
||||
type AzureAppConfigurationClientPutKeyValueOptions struct {
|
||||
// The key-value to create.
|
||||
Entity *KeyValue
|
||||
// Used to perform an operation only if the targeted resource's etag matches the value provided.
|
||||
IfMatch *string
|
||||
// Used to perform an operation only if the targeted resource's etag does not match the value provided.
|
||||
IfNoneMatch *string
|
||||
// The label of the key-value to create.
|
||||
Label *string
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientPutLockOptions contains the optional parameters for the AzureAppConfigurationClient.PutLock
|
||||
// method.
|
||||
type AzureAppConfigurationClientPutLockOptions struct {
|
||||
// Used to perform an operation only if the targeted resource's etag matches the value provided.
|
||||
IfMatch *string
|
||||
// Used to perform an operation only if the targeted resource's etag does not match the value provided.
|
||||
IfNoneMatch *string
|
||||
// The label, if any, of the key-value to lock.
|
||||
Label *string
|
||||
}
|
||||
|
||||
// Error - Azure App Configuration error object.
|
||||
type Error struct {
|
||||
// A detailed description of the error.
|
||||
Detail *string `json:"detail,omitempty"`
|
||||
|
||||
// The name of the parameter that resulted in the error.
|
||||
Name *string `json:"name,omitempty"`
|
||||
|
||||
// The HTTP status code that the error maps to.
|
||||
Status *int32 `json:"status,omitempty"`
|
||||
|
||||
// A brief summary of the error.
|
||||
Title *string `json:"title,omitempty"`
|
||||
|
||||
// The type of the error.
|
||||
Type *string `json:"type,omitempty"`
|
||||
}
|
||||
|
||||
type Key struct {
|
||||
// READ-ONLY
|
||||
Name *string `json:"name,omitempty" azure:"ro"`
|
||||
}
|
||||
|
||||
// KeyListResult - The result of a list request.
|
||||
type KeyListResult struct {
|
||||
// The collection value.
|
||||
Items []*Key `json:"items,omitempty"`
|
||||
|
||||
// The URI that can be used to request the next set of paged results.
|
||||
NextLink *string `json:"@nextLink,omitempty"`
|
||||
}
|
||||
|
||||
// MarshalJSON implements the json.Marshaller interface for type KeyListResult.
|
||||
func (k KeyListResult) MarshalJSON() ([]byte, error) {
|
||||
objectMap := make(map[string]interface{})
|
||||
populate(objectMap, "items", k.Items)
|
||||
populate(objectMap, "@nextLink", k.NextLink)
|
||||
return json.Marshal(objectMap)
|
||||
}
|
||||
|
||||
type KeyValue struct {
|
||||
ContentType *string `json:"content_type,omitempty"`
|
||||
Etag *string `json:"etag,omitempty"`
|
||||
Key *string `json:"key,omitempty"`
|
||||
Label *string `json:"label,omitempty"`
|
||||
LastModified *time.Time `json:"last_modified,omitempty"`
|
||||
Locked *bool `json:"locked,omitempty"`
|
||||
|
||||
// Dictionary of
|
||||
Tags map[string]*string `json:"tags,omitempty"`
|
||||
Value *string `json:"value,omitempty"`
|
||||
}
|
||||
|
||||
// MarshalJSON implements the json.Marshaller interface for type KeyValue.
|
||||
func (k KeyValue) MarshalJSON() ([]byte, error) {
|
||||
objectMap := make(map[string]interface{})
|
||||
populate(objectMap, "content_type", k.ContentType)
|
||||
populate(objectMap, "etag", k.Etag)
|
||||
populate(objectMap, "key", k.Key)
|
||||
populate(objectMap, "label", k.Label)
|
||||
populateTimeRFC3339(objectMap, "last_modified", k.LastModified)
|
||||
populate(objectMap, "locked", k.Locked)
|
||||
populate(objectMap, "tags", k.Tags)
|
||||
populate(objectMap, "value", k.Value)
|
||||
return json.Marshal(objectMap)
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the json.Unmarshaller interface for type KeyValue.
|
||||
func (k *KeyValue) 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 "content_type":
|
||||
err = unpopulate(val, &k.ContentType)
|
||||
delete(rawMsg, key)
|
||||
case "etag":
|
||||
err = unpopulate(val, &k.Etag)
|
||||
delete(rawMsg, key)
|
||||
case "key":
|
||||
err = unpopulate(val, &k.Key)
|
||||
delete(rawMsg, key)
|
||||
case "label":
|
||||
err = unpopulate(val, &k.Label)
|
||||
delete(rawMsg, key)
|
||||
case "last_modified":
|
||||
err = unpopulateTimeRFC3339(val, &k.LastModified)
|
||||
delete(rawMsg, key)
|
||||
case "locked":
|
||||
err = unpopulate(val, &k.Locked)
|
||||
delete(rawMsg, key)
|
||||
case "tags":
|
||||
err = unpopulate(val, &k.Tags)
|
||||
delete(rawMsg, key)
|
||||
case "value":
|
||||
err = unpopulate(val, &k.Value)
|
||||
delete(rawMsg, key)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// KeyValueListResult - The result of a list request.
|
||||
type KeyValueListResult struct {
|
||||
// The collection value.
|
||||
Items []*KeyValue `json:"items,omitempty"`
|
||||
|
||||
// The URI that can be used to request the next set of paged results.
|
||||
NextLink *string `json:"@nextLink,omitempty"`
|
||||
}
|
||||
|
||||
// MarshalJSON implements the json.Marshaller interface for type KeyValueListResult.
|
||||
func (k KeyValueListResult) MarshalJSON() ([]byte, error) {
|
||||
objectMap := make(map[string]interface{})
|
||||
populate(objectMap, "items", k.Items)
|
||||
populate(objectMap, "@nextLink", k.NextLink)
|
||||
return json.Marshal(objectMap)
|
||||
}
|
||||
|
||||
type Label struct {
|
||||
// READ-ONLY
|
||||
Name *string `json:"name,omitempty" azure:"ro"`
|
||||
}
|
||||
|
||||
// LabelListResult - The result of a list request.
|
||||
type LabelListResult struct {
|
||||
// The collection value.
|
||||
Items []*Label `json:"items,omitempty"`
|
||||
|
||||
// The URI that can be used to request the next set of paged results.
|
||||
NextLink *string `json:"@nextLink,omitempty"`
|
||||
}
|
||||
|
||||
// MarshalJSON implements the json.Marshaller interface for type LabelListResult.
|
||||
func (l LabelListResult) MarshalJSON() ([]byte, error) {
|
||||
objectMap := make(map[string]interface{})
|
||||
populate(objectMap, "items", l.Items)
|
||||
populate(objectMap, "@nextLink", l.NextLink)
|
||||
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)
|
||||
}
|
|
@ -0,0 +1,234 @@
|
|||
//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 generated
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
|
||||
)
|
||||
|
||||
// AzureAppConfigurationClientGetKeyValuesPager provides operations for iterating over paged responses.
|
||||
type AzureAppConfigurationClientGetKeyValuesPager struct {
|
||||
client *AzureAppConfigurationClient
|
||||
current AzureAppConfigurationClientGetKeyValuesResponse
|
||||
err error
|
||||
requester func(context.Context) (*policy.Request, error)
|
||||
advancer func(context.Context, AzureAppConfigurationClientGetKeyValuesResponse) (*policy.Request, error)
|
||||
}
|
||||
|
||||
// Err returns the last error encountered while paging.
|
||||
func (p *AzureAppConfigurationClientGetKeyValuesPager) 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 *AzureAppConfigurationClientGetKeyValuesPager) NextPage(ctx context.Context) bool {
|
||||
var req *policy.Request
|
||||
var err error
|
||||
if !reflect.ValueOf(p.current).IsZero() {
|
||||
if p.current.KeyValueListResult.NextLink == nil || len(*p.current.KeyValueListResult.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 = runtime.NewResponseError(resp)
|
||||
return false
|
||||
}
|
||||
result, err := p.client.getKeyValuesHandleResponse(resp)
|
||||
if err != nil {
|
||||
p.err = err
|
||||
return false
|
||||
}
|
||||
p.current = result
|
||||
return true
|
||||
}
|
||||
|
||||
// PageResponse returns the current AzureAppConfigurationClientGetKeyValuesResponse page.
|
||||
func (p *AzureAppConfigurationClientGetKeyValuesPager) PageResponse() AzureAppConfigurationClientGetKeyValuesResponse {
|
||||
return p.current
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientGetKeysPager provides operations for iterating over paged responses.
|
||||
type AzureAppConfigurationClientGetKeysPager struct {
|
||||
client *AzureAppConfigurationClient
|
||||
current AzureAppConfigurationClientGetKeysResponse
|
||||
err error
|
||||
requester func(context.Context) (*policy.Request, error)
|
||||
advancer func(context.Context, AzureAppConfigurationClientGetKeysResponse) (*policy.Request, error)
|
||||
}
|
||||
|
||||
// Err returns the last error encountered while paging.
|
||||
func (p *AzureAppConfigurationClientGetKeysPager) 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 *AzureAppConfigurationClientGetKeysPager) NextPage(ctx context.Context) bool {
|
||||
var req *policy.Request
|
||||
var err error
|
||||
if !reflect.ValueOf(p.current).IsZero() {
|
||||
if p.current.KeyListResult.NextLink == nil || len(*p.current.KeyListResult.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 = runtime.NewResponseError(resp)
|
||||
return false
|
||||
}
|
||||
result, err := p.client.getKeysHandleResponse(resp)
|
||||
if err != nil {
|
||||
p.err = err
|
||||
return false
|
||||
}
|
||||
p.current = result
|
||||
return true
|
||||
}
|
||||
|
||||
// PageResponse returns the current AzureAppConfigurationClientGetKeysResponse page.
|
||||
func (p *AzureAppConfigurationClientGetKeysPager) PageResponse() AzureAppConfigurationClientGetKeysResponse {
|
||||
return p.current
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientGetLabelsPager provides operations for iterating over paged responses.
|
||||
type AzureAppConfigurationClientGetLabelsPager struct {
|
||||
client *AzureAppConfigurationClient
|
||||
current AzureAppConfigurationClientGetLabelsResponse
|
||||
err error
|
||||
requester func(context.Context) (*policy.Request, error)
|
||||
advancer func(context.Context, AzureAppConfigurationClientGetLabelsResponse) (*policy.Request, error)
|
||||
}
|
||||
|
||||
// Err returns the last error encountered while paging.
|
||||
func (p *AzureAppConfigurationClientGetLabelsPager) 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 *AzureAppConfigurationClientGetLabelsPager) NextPage(ctx context.Context) bool {
|
||||
var req *policy.Request
|
||||
var err error
|
||||
if !reflect.ValueOf(p.current).IsZero() {
|
||||
if p.current.LabelListResult.NextLink == nil || len(*p.current.LabelListResult.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 = runtime.NewResponseError(resp)
|
||||
return false
|
||||
}
|
||||
result, err := p.client.getLabelsHandleResponse(resp)
|
||||
if err != nil {
|
||||
p.err = err
|
||||
return false
|
||||
}
|
||||
p.current = result
|
||||
return true
|
||||
}
|
||||
|
||||
// PageResponse returns the current AzureAppConfigurationClientGetLabelsResponse page.
|
||||
func (p *AzureAppConfigurationClientGetLabelsPager) PageResponse() AzureAppConfigurationClientGetLabelsResponse {
|
||||
return p.current
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientGetRevisionsPager provides operations for iterating over paged responses.
|
||||
type AzureAppConfigurationClientGetRevisionsPager struct {
|
||||
client *AzureAppConfigurationClient
|
||||
current AzureAppConfigurationClientGetRevisionsResponse
|
||||
err error
|
||||
requester func(context.Context) (*policy.Request, error)
|
||||
advancer func(context.Context, AzureAppConfigurationClientGetRevisionsResponse) (*policy.Request, error)
|
||||
}
|
||||
|
||||
// Err returns the last error encountered while paging.
|
||||
func (p *AzureAppConfigurationClientGetRevisionsPager) 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 *AzureAppConfigurationClientGetRevisionsPager) NextPage(ctx context.Context) bool {
|
||||
var req *policy.Request
|
||||
var err error
|
||||
if !reflect.ValueOf(p.current).IsZero() {
|
||||
if p.current.KeyValueListResult.NextLink == nil || len(*p.current.KeyValueListResult.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 = runtime.NewResponseError(resp)
|
||||
return false
|
||||
}
|
||||
result, err := p.client.getRevisionsHandleResponse(resp)
|
||||
if err != nil {
|
||||
p.err = err
|
||||
return false
|
||||
}
|
||||
p.current = result
|
||||
return true
|
||||
}
|
||||
|
||||
// PageResponse returns the current AzureAppConfigurationClientGetRevisionsResponse page.
|
||||
func (p *AzureAppConfigurationClientGetRevisionsPager) PageResponse() AzureAppConfigurationClientGetRevisionsResponse {
|
||||
return p.current
|
||||
}
|
|
@ -0,0 +1,226 @@
|
|||
//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 generated
|
||||
|
||||
import "net/http"
|
||||
|
||||
// AzureAppConfigurationClientCheckKeyValueResponse contains the response from method AzureAppConfigurationClient.CheckKeyValue.
|
||||
type AzureAppConfigurationClientCheckKeyValueResponse struct {
|
||||
AzureAppConfigurationClientCheckKeyValueResult
|
||||
// RawResponse contains the underlying HTTP response.
|
||||
RawResponse *http.Response
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientCheckKeyValueResult contains the result from method AzureAppConfigurationClient.CheckKeyValue.
|
||||
type AzureAppConfigurationClientCheckKeyValueResult struct {
|
||||
// ETag contains the information returned from the ETag header response.
|
||||
ETag *string
|
||||
|
||||
// LastModified contains the information returned from the Last-Modified header response.
|
||||
LastModified *string
|
||||
|
||||
// SyncToken contains the information returned from the Sync-Token header response.
|
||||
SyncToken *string
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientCheckKeyValuesResponse contains the response from method AzureAppConfigurationClient.CheckKeyValues.
|
||||
type AzureAppConfigurationClientCheckKeyValuesResponse struct {
|
||||
AzureAppConfigurationClientCheckKeyValuesResult
|
||||
// RawResponse contains the underlying HTTP response.
|
||||
RawResponse *http.Response
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientCheckKeyValuesResult contains the result from method AzureAppConfigurationClient.CheckKeyValues.
|
||||
type AzureAppConfigurationClientCheckKeyValuesResult struct {
|
||||
// SyncToken contains the information returned from the Sync-Token header response.
|
||||
SyncToken *string
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientCheckKeysResponse contains the response from method AzureAppConfigurationClient.CheckKeys.
|
||||
type AzureAppConfigurationClientCheckKeysResponse struct {
|
||||
AzureAppConfigurationClientCheckKeysResult
|
||||
// RawResponse contains the underlying HTTP response.
|
||||
RawResponse *http.Response
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientCheckKeysResult contains the result from method AzureAppConfigurationClient.CheckKeys.
|
||||
type AzureAppConfigurationClientCheckKeysResult struct {
|
||||
// SyncToken contains the information returned from the Sync-Token header response.
|
||||
SyncToken *string
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientCheckLabelsResponse contains the response from method AzureAppConfigurationClient.CheckLabels.
|
||||
type AzureAppConfigurationClientCheckLabelsResponse struct {
|
||||
AzureAppConfigurationClientCheckLabelsResult
|
||||
// RawResponse contains the underlying HTTP response.
|
||||
RawResponse *http.Response
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientCheckLabelsResult contains the result from method AzureAppConfigurationClient.CheckLabels.
|
||||
type AzureAppConfigurationClientCheckLabelsResult struct {
|
||||
// SyncToken contains the information returned from the Sync-Token header response.
|
||||
SyncToken *string
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientCheckRevisionsResponse contains the response from method AzureAppConfigurationClient.CheckRevisions.
|
||||
type AzureAppConfigurationClientCheckRevisionsResponse struct {
|
||||
AzureAppConfigurationClientCheckRevisionsResult
|
||||
// RawResponse contains the underlying HTTP response.
|
||||
RawResponse *http.Response
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientCheckRevisionsResult contains the result from method AzureAppConfigurationClient.CheckRevisions.
|
||||
type AzureAppConfigurationClientCheckRevisionsResult struct {
|
||||
// SyncToken contains the information returned from the Sync-Token header response.
|
||||
SyncToken *string
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientDeleteKeyValueResponse contains the response from method AzureAppConfigurationClient.DeleteKeyValue.
|
||||
type AzureAppConfigurationClientDeleteKeyValueResponse struct {
|
||||
AzureAppConfigurationClientDeleteKeyValueResult
|
||||
// RawResponse contains the underlying HTTP response.
|
||||
RawResponse *http.Response
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientDeleteKeyValueResult contains the result from method AzureAppConfigurationClient.DeleteKeyValue.
|
||||
type AzureAppConfigurationClientDeleteKeyValueResult struct {
|
||||
KeyValue
|
||||
// ETag contains the information returned from the ETag header response.
|
||||
ETag *string
|
||||
|
||||
// SyncToken contains the information returned from the Sync-Token header response.
|
||||
SyncToken *string
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientDeleteLockResponse contains the response from method AzureAppConfigurationClient.DeleteLock.
|
||||
type AzureAppConfigurationClientDeleteLockResponse struct {
|
||||
AzureAppConfigurationClientDeleteLockResult
|
||||
// RawResponse contains the underlying HTTP response.
|
||||
RawResponse *http.Response
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientDeleteLockResult contains the result from method AzureAppConfigurationClient.DeleteLock.
|
||||
type AzureAppConfigurationClientDeleteLockResult struct {
|
||||
KeyValue
|
||||
// ETag contains the information returned from the ETag header response.
|
||||
ETag *string
|
||||
|
||||
// SyncToken contains the information returned from the Sync-Token header response.
|
||||
SyncToken *string
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientGetKeyValueResponse contains the response from method AzureAppConfigurationClient.GetKeyValue.
|
||||
type AzureAppConfigurationClientGetKeyValueResponse struct {
|
||||
AzureAppConfigurationClientGetKeyValueResult
|
||||
// RawResponse contains the underlying HTTP response.
|
||||
RawResponse *http.Response
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientGetKeyValueResult contains the result from method AzureAppConfigurationClient.GetKeyValue.
|
||||
type AzureAppConfigurationClientGetKeyValueResult struct {
|
||||
KeyValue
|
||||
// ETag contains the information returned from the ETag header response.
|
||||
ETag *string
|
||||
|
||||
// LastModified contains the information returned from the Last-Modified header response.
|
||||
LastModified *string
|
||||
|
||||
// SyncToken contains the information returned from the Sync-Token header response.
|
||||
SyncToken *string
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientGetKeyValuesResponse contains the response from method AzureAppConfigurationClient.GetKeyValues.
|
||||
type AzureAppConfigurationClientGetKeyValuesResponse struct {
|
||||
AzureAppConfigurationClientGetKeyValuesResult
|
||||
// RawResponse contains the underlying HTTP response.
|
||||
RawResponse *http.Response
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientGetKeyValuesResult contains the result from method AzureAppConfigurationClient.GetKeyValues.
|
||||
type AzureAppConfigurationClientGetKeyValuesResult struct {
|
||||
KeyValueListResult
|
||||
// SyncToken contains the information returned from the Sync-Token header response.
|
||||
SyncToken *string
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientGetKeysResponse contains the response from method AzureAppConfigurationClient.GetKeys.
|
||||
type AzureAppConfigurationClientGetKeysResponse struct {
|
||||
AzureAppConfigurationClientGetKeysResult
|
||||
// RawResponse contains the underlying HTTP response.
|
||||
RawResponse *http.Response
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientGetKeysResult contains the result from method AzureAppConfigurationClient.GetKeys.
|
||||
type AzureAppConfigurationClientGetKeysResult struct {
|
||||
KeyListResult
|
||||
// SyncToken contains the information returned from the Sync-Token header response.
|
||||
SyncToken *string
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientGetLabelsResponse contains the response from method AzureAppConfigurationClient.GetLabels.
|
||||
type AzureAppConfigurationClientGetLabelsResponse struct {
|
||||
AzureAppConfigurationClientGetLabelsResult
|
||||
// RawResponse contains the underlying HTTP response.
|
||||
RawResponse *http.Response
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientGetLabelsResult contains the result from method AzureAppConfigurationClient.GetLabels.
|
||||
type AzureAppConfigurationClientGetLabelsResult struct {
|
||||
LabelListResult
|
||||
// SyncToken contains the information returned from the Sync-Token header response.
|
||||
SyncToken *string
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientGetRevisionsResponse contains the response from method AzureAppConfigurationClient.GetRevisions.
|
||||
type AzureAppConfigurationClientGetRevisionsResponse struct {
|
||||
AzureAppConfigurationClientGetRevisionsResult
|
||||
// RawResponse contains the underlying HTTP response.
|
||||
RawResponse *http.Response
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientGetRevisionsResult contains the result from method AzureAppConfigurationClient.GetRevisions.
|
||||
type AzureAppConfigurationClientGetRevisionsResult struct {
|
||||
KeyValueListResult
|
||||
// SyncToken contains the information returned from the Sync-Token header response.
|
||||
SyncToken *string
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientPutKeyValueResponse contains the response from method AzureAppConfigurationClient.PutKeyValue.
|
||||
type AzureAppConfigurationClientPutKeyValueResponse struct {
|
||||
AzureAppConfigurationClientPutKeyValueResult
|
||||
// RawResponse contains the underlying HTTP response.
|
||||
RawResponse *http.Response
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientPutKeyValueResult contains the result from method AzureAppConfigurationClient.PutKeyValue.
|
||||
type AzureAppConfigurationClientPutKeyValueResult struct {
|
||||
KeyValue
|
||||
// ETag contains the information returned from the ETag header response.
|
||||
ETag *string
|
||||
|
||||
// SyncToken contains the information returned from the Sync-Token header response.
|
||||
SyncToken *string
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientPutLockResponse contains the response from method AzureAppConfigurationClient.PutLock.
|
||||
type AzureAppConfigurationClientPutLockResponse struct {
|
||||
AzureAppConfigurationClientPutLockResult
|
||||
// RawResponse contains the underlying HTTP response.
|
||||
RawResponse *http.Response
|
||||
}
|
||||
|
||||
// AzureAppConfigurationClientPutLockResult contains the result from method AzureAppConfigurationClient.PutLock.
|
||||
type AzureAppConfigurationClientPutLockResult struct {
|
||||
KeyValue
|
||||
// ETag contains the information returned from the ETag header response.
|
||||
ETag *string
|
||||
|
||||
// SyncToken contains the information returned from the Sync-Token header response.
|
||||
SyncToken *string
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
//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 generated
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
|
@ -0,0 +1,155 @@
|
|||
//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.
|
||||
|
||||
package azappconfig
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
|
||||
)
|
||||
|
||||
type hmacAuthenticationPolicy struct {
|
||||
credential string
|
||||
secret []byte
|
||||
}
|
||||
|
||||
func newHmacAuthenticationPolicy(credential string, secret []byte) *hmacAuthenticationPolicy {
|
||||
return &hmacAuthenticationPolicy{
|
||||
credential: credential,
|
||||
secret: secret,
|
||||
}
|
||||
}
|
||||
|
||||
func (policy *hmacAuthenticationPolicy) Do(request *policy.Request) (*http.Response, error) {
|
||||
req := request.Raw()
|
||||
id := policy.credential
|
||||
key := policy.secret
|
||||
|
||||
method := req.Method
|
||||
host := req.URL.Host
|
||||
pathAndQuery := req.URL.Path
|
||||
if req.URL.RawQuery != "" {
|
||||
pathAndQuery = pathAndQuery + "?" + req.URL.RawQuery
|
||||
}
|
||||
|
||||
var content []byte
|
||||
if req.Body != nil {
|
||||
var err error
|
||||
if content, err = ioutil.ReadAll(req.Body); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
req.Body = ioutil.NopCloser(bytes.NewBuffer(content))
|
||||
|
||||
timestamp := time.Now().UTC().Format(http.TimeFormat)
|
||||
contentHash := getContentHashBase64(content)
|
||||
stringToSign := fmt.Sprintf("%s\n%s\n%s;%s;%s", strings.ToUpper(method), pathAndQuery, timestamp, host, contentHash)
|
||||
signature := getHmac(stringToSign, key)
|
||||
|
||||
req.Header.Set("x-ms-content-sha256", contentHash)
|
||||
req.Header.Set("x-ms-date", timestamp)
|
||||
req.Header.Set("Authorization", "HMAC-SHA256 Credential="+id+", SignedHeaders=x-ms-date;host;x-ms-content-sha256, Signature="+signature)
|
||||
|
||||
return request.Next()
|
||||
}
|
||||
|
||||
func signRequest(id string, secret string, req *http.Request) error {
|
||||
method := req.Method
|
||||
host := req.URL.Host
|
||||
pathAndQuery := req.URL.Path
|
||||
if req.URL.RawQuery != "" {
|
||||
pathAndQuery = pathAndQuery + "?" + req.URL.RawQuery
|
||||
}
|
||||
|
||||
content, err := ioutil.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Body = ioutil.NopCloser(bytes.NewBuffer(content))
|
||||
|
||||
key, err := base64.StdEncoding.DecodeString(secret)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
timestamp := time.Now().UTC().Format(http.TimeFormat)
|
||||
contentHash := getContentHashBase64(content)
|
||||
stringToSign := fmt.Sprintf("%s\n%s\n%s;%s;%s", strings.ToUpper(method), pathAndQuery, timestamp, host, contentHash)
|
||||
signature := getHmac(stringToSign, key)
|
||||
|
||||
req.Header.Set("x-ms-content-sha256", contentHash)
|
||||
req.Header.Set("x-ms-date", timestamp)
|
||||
req.Header.Set("Authorization", "HMAC-SHA256 Credential="+id+", SignedHeaders=x-ms-date;host;x-ms-content-sha256, Signature="+signature)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getContentHashBase64(content []byte) string {
|
||||
hasher := sha256.New()
|
||||
hasher.Write(content)
|
||||
return base64.StdEncoding.EncodeToString(hasher.Sum(nil))
|
||||
}
|
||||
|
||||
func getHmac(content string, key []byte) string {
|
||||
hmac := hmac.New(sha256.New, key)
|
||||
hmac.Write([]byte(content))
|
||||
return base64.StdEncoding.EncodeToString(hmac.Sum(nil))
|
||||
}
|
||||
|
||||
func parseConnectionString(connectionString string) (endpoint string, credential string, secret []byte, err error) {
|
||||
const connectionStringEndpointPrefix = "Endpoint="
|
||||
const connectionStringCredentialPrefix = "Id="
|
||||
const connectionStringSecretPrefix = "Secret="
|
||||
|
||||
var er error = errors.New("error parsing connection string")
|
||||
var ept *string
|
||||
var cred *string
|
||||
var sec *[]byte
|
||||
for _, seg := range strings.Split(connectionString, ";") {
|
||||
if strings.HasPrefix(seg, connectionStringEndpointPrefix) {
|
||||
if ept != nil {
|
||||
return "", "", []byte{}, er
|
||||
}
|
||||
|
||||
ep := strings.TrimPrefix(seg, connectionStringEndpointPrefix)
|
||||
ept = &ep
|
||||
} else if strings.HasPrefix(seg, connectionStringCredentialPrefix) {
|
||||
if cred != nil {
|
||||
return "", "", []byte{}, er
|
||||
}
|
||||
|
||||
c := strings.TrimPrefix(seg, connectionStringCredentialPrefix)
|
||||
cred = &c
|
||||
} else if strings.HasPrefix(seg, connectionStringSecretPrefix) {
|
||||
if sec != nil {
|
||||
return "", "", []byte{}, er
|
||||
}
|
||||
|
||||
s, e := base64.StdEncoding.DecodeString(strings.TrimPrefix(seg, connectionStringSecretPrefix))
|
||||
if e != nil {
|
||||
return "", "", []byte{}, e
|
||||
}
|
||||
|
||||
sec = &s
|
||||
}
|
||||
}
|
||||
|
||||
if ept == nil || cred == nil || sec == nil {
|
||||
return "", "", []byte{}, er
|
||||
}
|
||||
|
||||
return *ept, *cred, *sec, nil
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
//go:build go1.16
|
||||
// +build go1.16
|
||||
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
package azappconfig
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestHmacAuthParseConnectionString(t *testing.T) {
|
||||
ep, id, sc, err := parseConnectionString("Endpoint=xX;Id=yY;Secret=ZmZm")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "xX", ep)
|
||||
require.Equal(t, "yY", id)
|
||||
|
||||
require.Len(t, sc, 3)
|
||||
require.Equal(t, byte('f'), sc[0])
|
||||
require.Equal(t, byte('f'), sc[1])
|
||||
require.Equal(t, byte('f'), sc[2])
|
||||
}
|
||||
|
||||
func TestHmacAuthParseConnectionStringMixedOrder(t *testing.T) {
|
||||
ep, id, sc, err := parseConnectionString("Id=yY;Secret=ZmZm;Endpoint=xX")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "xX", ep)
|
||||
require.Equal(t, "yY", id)
|
||||
|
||||
require.Len(t, sc, 3)
|
||||
require.Equal(t, byte('f'), sc[0])
|
||||
require.Equal(t, byte('f'), sc[1])
|
||||
require.Equal(t, byte('f'), sc[2])
|
||||
}
|
||||
|
||||
func TestHmacAuthParseConnectionStringExtraProperties(t *testing.T) {
|
||||
ep, id, sc, err := parseConnectionString("A=aA;Endpoint=xX;B=bB;Id=yY;C=cC;Secret=ZmZm;D=dD;")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "xX", ep)
|
||||
require.Equal(t, "yY", id)
|
||||
|
||||
require.Len(t, sc, 3)
|
||||
require.Equal(t, byte('f'), sc[0])
|
||||
require.Equal(t, byte('f'), sc[1])
|
||||
require.Equal(t, byte('f'), sc[2])
|
||||
}
|
||||
|
||||
func TestHmacAuthParseConnectionStringMissingEndoint(t *testing.T) {
|
||||
_, _, _, err := parseConnectionString("Id=yY;Secret=ZmZm")
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestHmacAuthParseConnectionStringMissingId(t *testing.T) {
|
||||
_, _, _, err := parseConnectionString("Endpoint=xX;Secret=ZmZm")
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestHmacAuthParseConnectionStringMissingSecret(t *testing.T) {
|
||||
_, _, _, err := parseConnectionString("Endpoint=xX;Id=yY")
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestHmacAuthParseConnectionStringDuplicateEndoint(t *testing.T) {
|
||||
_, _, _, err := parseConnectionString("Endpoint=xX;Endpoint=xX;Id=yY;Secret=ZmZm")
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestHmacAuthParseConnectionStringDuplicateId(t *testing.T) {
|
||||
_, _, _, err := parseConnectionString("Endpoint=xX;Id=yY;Id=yY;Secret=ZmZm")
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestHmacAuthParseConnectionStringDuplicateSecret(t *testing.T) {
|
||||
_, _, _, err := parseConnectionString("Endpoint=xX;Id=yY;Secret=ZmZm;Secret=zZ")
|
||||
require.Error(t, err)
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
//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.
|
||||
|
||||
package azappconfig
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
|
||||
)
|
||||
|
||||
type syncToken struct {
|
||||
id string
|
||||
value string
|
||||
seqNo int64
|
||||
}
|
||||
|
||||
type syncTokenPolicy struct {
|
||||
syncTokens map[string]syncToken
|
||||
}
|
||||
|
||||
func newSyncTokenPolicy() *syncTokenPolicy {
|
||||
return &syncTokenPolicy{}
|
||||
}
|
||||
|
||||
func parseToken(tok string) (syncToken, error) {
|
||||
if tok == "" {
|
||||
return syncToken{}, errors.New("empty token")
|
||||
}
|
||||
|
||||
id := ""
|
||||
val := ""
|
||||
var seq int64
|
||||
|
||||
for _, kv := range strings.Split(tok, ";") {
|
||||
if kv == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
eq := strings.Index(kv, "=")
|
||||
if eq == -1 || eq == len(kv)-1 {
|
||||
continue
|
||||
}
|
||||
|
||||
n := strings.TrimSpace(kv[:eq])
|
||||
v := kv[eq+1:]
|
||||
|
||||
if n == "sn" {
|
||||
sn, err := strconv.ParseInt(v, 0, 64)
|
||||
if err != nil {
|
||||
return syncToken{}, err
|
||||
}
|
||||
seq = sn
|
||||
} else {
|
||||
id = n
|
||||
val = v
|
||||
}
|
||||
}
|
||||
|
||||
if id != "" && val != "" {
|
||||
return syncToken{
|
||||
id: id,
|
||||
value: val,
|
||||
seqNo: seq,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return syncToken{}, errors.New("didn't parse all the required parts")
|
||||
}
|
||||
|
||||
func (policy *syncTokenPolicy) addToken(tok string) {
|
||||
for _, t := range strings.Split(tok, ",") {
|
||||
if st, err := parseToken(t); err == nil {
|
||||
if existing := policy.syncTokens[st.id]; existing.seqNo < st.seqNo {
|
||||
policy.syncTokens[st.id] = st
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (policy *syncTokenPolicy) Do(req *policy.Request) (*http.Response, error) {
|
||||
const syncTokenHeaderName = "Sync-Token"
|
||||
var tokens []string
|
||||
for _, st := range policy.syncTokens {
|
||||
tokens = append(tokens, st.id)
|
||||
}
|
||||
|
||||
req.Raw().Header[syncTokenHeaderName] = tokens
|
||||
|
||||
resp, err := req.Next()
|
||||
|
||||
if err != nil {
|
||||
for _, st := range resp.Header[syncTokenHeaderName] {
|
||||
policy.addToken(st)
|
||||
}
|
||||
}
|
||||
|
||||
return resp, err
|
||||
}
|
|
@ -0,0 +1,173 @@
|
|||
//go:build go1.16
|
||||
// +build go1.16
|
||||
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
package azappconfig
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSyncTokenParseTokenEmpty(t *testing.T) {
|
||||
_, err := parseToken("")
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestSyncTokenParseTokenWithoutSeqNo(t *testing.T) {
|
||||
tok1, err1 := parseToken("n=v")
|
||||
require.NoError(t, err1)
|
||||
require.NotEmpty(t, tok1)
|
||||
require.Equal(t, "n", tok1.id)
|
||||
require.Equal(t, "v", tok1.value)
|
||||
require.Empty(t, tok1.seqNo)
|
||||
|
||||
tok2, err2 := parseToken("n=v;")
|
||||
require.NoError(t, err2)
|
||||
require.NotEmpty(t, tok2)
|
||||
require.Equal(t, "n", tok2.id)
|
||||
require.Equal(t, "v", tok2.value)
|
||||
require.Empty(t, tok2.seqNo)
|
||||
}
|
||||
|
||||
func TestSyncTokenParseTokenWithSeqNo(t *testing.T) {
|
||||
tok1, err1 := parseToken("n=v;sn=1")
|
||||
require.NoError(t, err1)
|
||||
require.NotEmpty(t, tok1)
|
||||
require.Equal(t, "n", tok1.id)
|
||||
require.Equal(t, "v", tok1.value)
|
||||
require.Equal(t, int64(1), tok1.seqNo)
|
||||
|
||||
tok2, err2 := parseToken("n=v;sn=1;")
|
||||
require.NoError(t, err2)
|
||||
require.NotEmpty(t, tok2)
|
||||
require.Equal(t, "n", tok2.id)
|
||||
require.Equal(t, "v", tok2.value)
|
||||
require.Equal(t, int64(1), tok2.seqNo)
|
||||
}
|
||||
|
||||
func TestSyncTokenParseTokenWithSeqNoMax(t *testing.T) {
|
||||
tok1, err1 := parseToken("n=v;sn=9223372036854775807")
|
||||
require.NoError(t, err1)
|
||||
require.NotEmpty(t, tok1)
|
||||
require.Equal(t, "n", tok1.id)
|
||||
require.Equal(t, "v", tok1.value)
|
||||
require.Equal(t, int64(9223372036854775807), tok1.seqNo)
|
||||
|
||||
tok2, err2 := parseToken("n=v;sn=9223372036854775807;")
|
||||
require.NoError(t, err2)
|
||||
require.NotEmpty(t, tok2)
|
||||
require.Equal(t, "n", tok2.id)
|
||||
require.Equal(t, "v", tok2.value)
|
||||
require.Equal(t, int64(9223372036854775807), tok2.seqNo)
|
||||
}
|
||||
|
||||
func TestSyncTokenParseTokenWithSeqNoParseError(t *testing.T) {
|
||||
_, err1 := parseToken("n=v;sn=x")
|
||||
require.Error(t, err1)
|
||||
|
||||
_, err2 := parseToken("n=v;sn=x;")
|
||||
require.Error(t, err2)
|
||||
}
|
||||
|
||||
func TestSyncTokenParseTokenWithoutIdValue(t *testing.T) {
|
||||
_, err1 := parseToken("n=")
|
||||
require.Error(t, err1)
|
||||
|
||||
_, err2 := parseToken("n=;")
|
||||
require.Error(t, err2)
|
||||
|
||||
_, err3 := parseToken("n=;sn=1")
|
||||
require.Error(t, err3)
|
||||
|
||||
_, err4 := parseToken("n=;sn=1;")
|
||||
require.Error(t, err4)
|
||||
|
||||
_, err5 := parseToken(";")
|
||||
require.Error(t, err5)
|
||||
|
||||
_, err6 := parseToken("sn=1")
|
||||
require.Error(t, err6)
|
||||
|
||||
_, err7 := parseToken("sn=1;")
|
||||
require.Error(t, err7)
|
||||
}
|
||||
|
||||
func TestSyncTokenParseTokenNameTrim(t *testing.T) {
|
||||
tok1, err1 := parseToken(" n =v")
|
||||
require.NoError(t, err1)
|
||||
require.NotEmpty(t, tok1)
|
||||
require.Equal(t, "n", tok1.id)
|
||||
require.Equal(t, "v", tok1.value)
|
||||
require.Empty(t, tok1.seqNo)
|
||||
|
||||
tok2, err2 := parseToken(" n =v;")
|
||||
require.NoError(t, err2)
|
||||
require.NotEmpty(t, tok2)
|
||||
require.Equal(t, "n", tok2.id)
|
||||
require.Equal(t, "v", tok2.value)
|
||||
require.Empty(t, tok2.seqNo)
|
||||
|
||||
tok3, err3 := parseToken(" n =v; sn =1")
|
||||
require.NoError(t, err3)
|
||||
require.NotEmpty(t, tok3)
|
||||
require.Equal(t, "n", tok3.id)
|
||||
require.Equal(t, "v", tok3.value)
|
||||
require.Equal(t, int64(1), tok3.seqNo)
|
||||
|
||||
tok4, err4 := parseToken(" n =v; sn =1;")
|
||||
require.NoError(t, err4)
|
||||
require.NotEmpty(t, tok4)
|
||||
require.Equal(t, "n", tok4.id)
|
||||
require.Equal(t, "v", tok4.value)
|
||||
require.Equal(t, int64(1), tok4.seqNo)
|
||||
}
|
||||
|
||||
func TestSyncTokenParseTokenWithSeqNoReverseOrder(t *testing.T) {
|
||||
tok1, err1 := parseToken("sn=1;n=v")
|
||||
require.NoError(t, err1)
|
||||
require.NotEmpty(t, tok1)
|
||||
require.Equal(t, "n", tok1.id)
|
||||
require.Equal(t, "v", tok1.value)
|
||||
require.Equal(t, int64(1), tok1.seqNo)
|
||||
|
||||
tok2, err2 := parseToken("sn=1;n=v;")
|
||||
require.NoError(t, err2)
|
||||
require.NotEmpty(t, tok2)
|
||||
require.Equal(t, "n", tok2.id)
|
||||
require.Equal(t, "v", tok2.value)
|
||||
require.Equal(t, int64(1), tok2.seqNo)
|
||||
}
|
||||
|
||||
func TestSyncTokenParseTokenValueContainingEqualSigns(t *testing.T) {
|
||||
tok1, err1 := parseToken("jtqGc1I4=MDoyOA==")
|
||||
require.NoError(t, err1)
|
||||
require.NotEmpty(t, tok1)
|
||||
require.Equal(t, "jtqGc1I4", tok1.id)
|
||||
require.Equal(t, "MDoyOA==", tok1.value)
|
||||
require.Empty(t, tok1.seqNo)
|
||||
|
||||
tok2, err2 := parseToken("jtqGc1I4=MDoyOA==;")
|
||||
require.NoError(t, err2)
|
||||
require.NotEmpty(t, tok2)
|
||||
require.Equal(t, "jtqGc1I4", tok2.id)
|
||||
require.Equal(t, "MDoyOA==", tok2.value)
|
||||
require.Empty(t, tok2.seqNo)
|
||||
|
||||
tok3, err3 := parseToken("jtqGc1I4=MDoyOA==;sn=28")
|
||||
require.NoError(t, err3)
|
||||
require.NotEmpty(t, tok3)
|
||||
require.Equal(t, "jtqGc1I4", tok3.id)
|
||||
require.Equal(t, "MDoyOA==", tok3.value)
|
||||
require.Equal(t, int64(28), tok3.seqNo)
|
||||
|
||||
tok4, err4 := parseToken("jtqGc1I4=MDoyOA==;sn=28;")
|
||||
require.NoError(t, err4)
|
||||
require.NotEmpty(t, tok4)
|
||||
require.Equal(t, "jtqGc1I4", tok4.id)
|
||||
require.Equal(t, "MDoyOA==", tok4.value)
|
||||
require.Equal(t, int64(28), tok4.seqNo)
|
||||
}
|
|
@ -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.
|
||||
|
||||
package azappconfig
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/appconfiguration/azappconfig/internal/generated"
|
||||
)
|
||||
|
||||
// Setting is a setting, defined by a unique combination of a Key and Label.
|
||||
type Setting struct {
|
||||
// The primary identifier of the configuration setting.
|
||||
// A Key is used together with a Label to uniquely identify a configuration setting.
|
||||
Key *string
|
||||
|
||||
// The configuration setting's value.
|
||||
Value *string
|
||||
|
||||
// A value used to group configuration settings.
|
||||
// A Label is used together with a Key to uniquely identify a configuration setting.
|
||||
Label *string
|
||||
|
||||
// The content type of the configuration setting's value.
|
||||
// Providing a proper content-type can enable transformations of values when they are retrieved by applications.
|
||||
ContentType *string
|
||||
|
||||
// An ETag indicating the state of a configuration setting within a configuration store.
|
||||
ETag *azcore.ETag
|
||||
|
||||
// A dictionary of tags used to assign additional properties to a configuration setting.
|
||||
// These can be used to indicate how a configuration setting may be applied.
|
||||
Tags map[string]string
|
||||
|
||||
// The last time a modifying operation was performed on the given configuration setting.
|
||||
LastModified *time.Time
|
||||
|
||||
// A value indicating whether the configuration setting is read only.
|
||||
// A read only configuration setting may not be modified until it is made writable.
|
||||
IsReadOnly *bool
|
||||
}
|
||||
|
||||
func settingFromGenerated(kv generated.KeyValue) Setting {
|
||||
var tags map[string]string
|
||||
for k, v := range kv.Tags {
|
||||
if v != nil {
|
||||
tags[k] = *v
|
||||
}
|
||||
}
|
||||
|
||||
return Setting{
|
||||
Key: kv.Key,
|
||||
Value: kv.Value,
|
||||
Label: kv.Label,
|
||||
ContentType: kv.ContentType,
|
||||
ETag: (*azcore.ETag)(kv.Etag),
|
||||
Tags: tags,
|
||||
LastModified: kv.LastModified,
|
||||
IsReadOnly: kv.Locked,
|
||||
}
|
||||
}
|
||||
|
||||
func (cs Setting) toGenerated() *generated.KeyValue {
|
||||
var tags map[string]*string
|
||||
for k, v := range cs.Tags {
|
||||
tags[k] = &v
|
||||
}
|
||||
|
||||
return &generated.KeyValue{
|
||||
ContentType: cs.ContentType,
|
||||
Etag: (*string)(cs.ETag),
|
||||
Key: cs.Key,
|
||||
Label: cs.Label,
|
||||
LastModified: cs.LastModified,
|
||||
Locked: cs.IsReadOnly,
|
||||
Tags: tags,
|
||||
Value: cs.Value,
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
|
||||
package azappconfig
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/appconfiguration/azappconfig/internal/generated"
|
||||
)
|
||||
|
||||
// Fields to retrieve from a configuration setting.
|
||||
type SettingFields string
|
||||
|
||||
const (
|
||||
// The primary identifier of a configuration setting.
|
||||
SettingFieldsKey = SettingFields(generated.Enum6Key)
|
||||
|
||||
// A label used to group configuration settings.
|
||||
SettingFieldsLabel = SettingFields(generated.Enum6Label)
|
||||
|
||||
// The value of the configuration setting.
|
||||
SettingFieldsValue = SettingFields(generated.Enum6Value)
|
||||
|
||||
// The content type of the configuration setting's value.
|
||||
SettingFieldsContentType = SettingFields(generated.Enum6ContentType)
|
||||
|
||||
// An ETag indicating the version of a configuration setting within a configuration store.
|
||||
SettingFieldsETag = SettingFields(generated.Enum6Etag)
|
||||
|
||||
// The last time a modifying operation was performed on the given configuration setting.
|
||||
SettingFieldsLastModified = SettingFields(generated.Enum6LastModified)
|
||||
|
||||
// A value indicating whether the configuration setting is read-only.
|
||||
SettingFieldsIsReadOnly = SettingFields(generated.Enum6Locked)
|
||||
|
||||
// A list of tags that can help identify what a configuration setting may be applicable for.
|
||||
SettingFieldsTags = SettingFields(generated.Enum6Tags)
|
||||
)
|
||||
|
||||
// SettingSelector is a set of options that allows selecting a filtered set of configuration setting entities
|
||||
// from the configuration store, and optionally allows indicating which fields of each setting to retrieve.
|
||||
type SettingSelector struct {
|
||||
// Key filter that will be used to select a set of configuration setting entities.
|
||||
KeyFilter *string
|
||||
|
||||
// Label filter that will be used to select a set of configuration setting entities.
|
||||
LabelFilter *string
|
||||
|
||||
// Indicates the point in time in the revision history of the selected configuration setting entities to retrieve.
|
||||
// If set, all properties of the configuration setting entities in the returned group will be exactly what they were at this time.
|
||||
AcceptDateTime *time.Time
|
||||
|
||||
// The fields of the configuration setting to retrieve for each setting in the retrieved group.
|
||||
Fields []SettingFields
|
||||
}
|
||||
|
||||
func AllSettingFields() []SettingFields {
|
||||
return []SettingFields{
|
||||
SettingFieldsKey,
|
||||
SettingFieldsLabel,
|
||||
SettingFieldsValue,
|
||||
SettingFieldsContentType,
|
||||
SettingFieldsETag,
|
||||
SettingFieldsLastModified,
|
||||
SettingFieldsIsReadOnly,
|
||||
SettingFieldsTags,
|
||||
}
|
||||
}
|
||||
|
||||
func (sc SettingSelector) toGenerated() *generated.AzureAppConfigurationClientGetRevisionsOptions {
|
||||
var dt *string
|
||||
if sc.AcceptDateTime != nil {
|
||||
str := sc.AcceptDateTime.Format(timeFormat)
|
||||
dt = &str
|
||||
}
|
||||
|
||||
sf := make([]generated.Enum6, len(sc.Fields))
|
||||
for i := range sc.Fields {
|
||||
sf[i] = (generated.Enum6)(sc.Fields[i])
|
||||
}
|
||||
|
||||
return &generated.AzureAppConfigurationClientGetRevisionsOptions{
|
||||
After: dt,
|
||||
Key: sc.KeyFilter,
|
||||
Label: sc.LabelFilter,
|
||||
Select: sf,
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче