diff --git a/services/apimanagement/mgmt/2019-12-01/apimanagement/apimanagementapi/interfaces.go b/services/apimanagement/mgmt/2019-12-01/apimanagement/apimanagementapi/interfaces.go index 09967239af69..6f5801295cf9 100644 --- a/services/apimanagement/mgmt/2019-12-01/apimanagement/apimanagementapi/interfaces.go +++ b/services/apimanagement/mgmt/2019-12-01/apimanagement/apimanagementapi/interfaces.go @@ -281,6 +281,36 @@ type CertificateClientAPI interface { var _ CertificateClientAPI = (*apimanagement.CertificateClient)(nil) +// ContentTypeClientAPI contains the set of methods on the ContentTypeClient type. +type ContentTypeClientAPI interface { + CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string) (result apimanagement.ContentTypeContract, err error) + Delete(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string) (result autorest.Response, err error) + GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string) (result autorest.Response, err error) + ListByService(ctx context.Context, resourceGroupName string, serviceName string) (result apimanagement.ContentTypeCollectionPage, err error) + ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string) (result apimanagement.ContentTypeCollectionIterator, err error) +} + +var _ ContentTypeClientAPI = (*apimanagement.ContentTypeClient)(nil) + +// ContentTypesClientAPI contains the set of methods on the ContentTypesClient type. +type ContentTypesClientAPI interface { + Get(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string) (result apimanagement.ContentTypeContract, err error) +} + +var _ ContentTypesClientAPI = (*apimanagement.ContentTypesClient)(nil) + +// ContentItemClientAPI contains the set of methods on the ContentItemClient type. +type ContentItemClientAPI interface { + CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string, contentItemID string) (result apimanagement.ContentItemContract, err error) + Delete(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string, contentItemID string) (result autorest.Response, err error) + Get(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string, contentItemID string) (result apimanagement.ContentItemContract, err error) + GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string, contentItemID string) (result autorest.Response, err error) + ListByService(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string) (result apimanagement.ContentItemCollectionPage, err error) + ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string) (result apimanagement.ContentItemCollectionIterator, err error) +} + +var _ ContentItemClientAPI = (*apimanagement.ContentItemClient)(nil) + // OperationsClientAPI contains the set of methods on the OperationsClient type. type OperationsClientAPI interface { List(ctx context.Context) (result apimanagement.OperationListResultPage, err error) diff --git a/services/apimanagement/mgmt/2019-12-01/apimanagement/contentitem.go b/services/apimanagement/mgmt/2019-12-01/apimanagement/contentitem.go new file mode 100644 index 000000000000..a99768648b2e --- /dev/null +++ b/services/apimanagement/mgmt/2019-12-01/apimanagement/contentitem.go @@ -0,0 +1,542 @@ +package apimanagement + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// ContentItemClient is the apiManagement Client +type ContentItemClient struct { + BaseClient +} + +// NewContentItemClient creates an instance of the ContentItemClient client. +func NewContentItemClient(subscriptionID string) ContentItemClient { + return NewContentItemClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewContentItemClientWithBaseURI creates an instance of the ContentItemClient client using a custom endpoint. Use +// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewContentItemClientWithBaseURI(baseURI string, subscriptionID string) ContentItemClient { + return ContentItemClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate creates new content item +// Parameters: +// resourceGroupName - the name of the resource group. +// serviceName - the name of the API Management service. +// contentTypeID - content type identifier. +// contentItemID - content item identifier. +func (client ContentItemClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string, contentItemID string) (result ContentItemContract, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ContentItemClient.CreateOrUpdate") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: serviceName, + Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, + {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, + {TargetValue: contentTypeID, + Constraints: []validation.Constraint{{Target: "contentTypeID", Name: validation.MaxLength, Rule: 80, Chain: nil}, + {Target: "contentTypeID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: contentItemID, + Constraints: []validation.Constraint{{Target: "contentItemID", Name: validation.MaxLength, Rule: 80, Chain: nil}, + {Target: "contentItemID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("apimanagement.ContentItemClient", "CreateOrUpdate", err.Error()) + } + + req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, contentTypeID, contentItemID) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentItemClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "apimanagement.ContentItemClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentItemClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client ContentItemClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string, contentItemID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "contentItemId": autorest.Encode("path", contentItemID), + "contentTypeId": autorest.Encode("path", contentTypeID), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "serviceName": autorest.Encode("path", serviceName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2019-12-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/contentTypes/{contentTypeId}/contentItems/{contentItemId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client ContentItemClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client ContentItemClient) CreateOrUpdateResponder(resp *http.Response) (result ContentItemContract, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete removes specified content item. +// Parameters: +// resourceGroupName - the name of the resource group. +// serviceName - the name of the API Management service. +// contentTypeID - content type identifier. +// contentItemID - content item identifier. +func (client ContentItemClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string, contentItemID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ContentItemClient.Delete") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: serviceName, + Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, + {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, + {TargetValue: contentTypeID, + Constraints: []validation.Constraint{{Target: "contentTypeID", Name: validation.MaxLength, Rule: 80, Chain: nil}, + {Target: "contentTypeID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: contentItemID, + Constraints: []validation.Constraint{{Target: "contentItemID", Name: validation.MaxLength, Rule: 80, Chain: nil}, + {Target: "contentItemID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("apimanagement.ContentItemClient", "Delete", err.Error()) + } + + req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, contentTypeID, contentItemID) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentItemClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "apimanagement.ContentItemClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentItemClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client ContentItemClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string, contentItemID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "contentItemId": autorest.Encode("path", contentItemID), + "contentTypeId": autorest.Encode("path", contentTypeID), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "serviceName": autorest.Encode("path", serviceName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2019-12-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/contentTypes/{contentTypeId}/contentItems/{contentItemId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client ContentItemClient) DeleteSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client ContentItemClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get returns content item details +// Parameters: +// resourceGroupName - the name of the resource group. +// serviceName - the name of the API Management service. +// contentTypeID - content type identifier. +// contentItemID - content item identifier. +func (client ContentItemClient) Get(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string, contentItemID string) (result ContentItemContract, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ContentItemClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: serviceName, + Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, + {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, + {TargetValue: contentTypeID, + Constraints: []validation.Constraint{{Target: "contentTypeID", Name: validation.MaxLength, Rule: 80, Chain: nil}, + {Target: "contentTypeID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: contentItemID, + Constraints: []validation.Constraint{{Target: "contentItemID", Name: validation.MaxLength, Rule: 80, Chain: nil}, + {Target: "contentItemID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("apimanagement.ContentItemClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, contentTypeID, contentItemID) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentItemClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "apimanagement.ContentItemClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentItemClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client ContentItemClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string, contentItemID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "contentItemId": autorest.Encode("path", contentItemID), + "contentTypeId": autorest.Encode("path", contentTypeID), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "serviceName": autorest.Encode("path", serviceName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2019-12-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/contentTypes/{contentTypeId}/contentItems/{contentItemId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client ContentItemClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client ContentItemClient) GetResponder(resp *http.Response) (result ContentItemContract, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetEntityTag returns content item metadata +// Parameters: +// resourceGroupName - the name of the resource group. +// serviceName - the name of the API Management service. +// contentTypeID - content type identifier. +// contentItemID - content item identifier. +func (client ContentItemClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string, contentItemID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ContentItemClient.GetEntityTag") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: serviceName, + Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, + {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, + {TargetValue: contentTypeID, + Constraints: []validation.Constraint{{Target: "contentTypeID", Name: validation.MaxLength, Rule: 80, Chain: nil}, + {Target: "contentTypeID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: contentItemID, + Constraints: []validation.Constraint{{Target: "contentItemID", Name: validation.MaxLength, Rule: 80, Chain: nil}, + {Target: "contentItemID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("apimanagement.ContentItemClient", "GetEntityTag", err.Error()) + } + + req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, contentTypeID, contentItemID) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentItemClient", "GetEntityTag", nil, "Failure preparing request") + return + } + + resp, err := client.GetEntityTagSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "apimanagement.ContentItemClient", "GetEntityTag", resp, "Failure sending request") + return + } + + result, err = client.GetEntityTagResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentItemClient", "GetEntityTag", resp, "Failure responding to request") + } + + return +} + +// GetEntityTagPreparer prepares the GetEntityTag request. +func (client ContentItemClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string, contentItemID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "contentItemId": autorest.Encode("path", contentItemID), + "contentTypeId": autorest.Encode("path", contentTypeID), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "serviceName": autorest.Encode("path", serviceName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2019-12-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsHead(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/contentTypes/{contentTypeId}/contentItems/{contentItemId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetEntityTagSender sends the GetEntityTag request. The method will close the +// http.Response Body if it receives an error. +func (client ContentItemClient) GetEntityTagSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetEntityTagResponder handles the response to the GetEntityTag request. The method always +// closes the http.Response Body. +func (client ContentItemClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.Response = resp + return +} + +// ListByService returns list of content items +// Parameters: +// resourceGroupName - the name of the resource group. +// serviceName - the name of the API Management service. +// contentTypeID - content type identifier. +func (client ContentItemClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string) (result ContentItemCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ContentItemClient.ListByService") + defer func() { + sc := -1 + if result.cic.Response.Response != nil { + sc = result.cic.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: serviceName, + Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, + {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, + {TargetValue: contentTypeID, + Constraints: []validation.Constraint{{Target: "contentTypeID", Name: validation.MaxLength, Rule: 80, Chain: nil}, + {Target: "contentTypeID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("apimanagement.ContentItemClient", "ListByService", err.Error()) + } + + result.fn = client.listByServiceNextResults + req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, contentTypeID) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentItemClient", "ListByService", nil, "Failure preparing request") + return + } + + resp, err := client.ListByServiceSender(req) + if err != nil { + result.cic.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "apimanagement.ContentItemClient", "ListByService", resp, "Failure sending request") + return + } + + result.cic, err = client.ListByServiceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentItemClient", "ListByService", resp, "Failure responding to request") + } + if result.cic.hasNextLink() && result.cic.IsEmpty() { + err = result.NextWithContext(ctx) + } + + return +} + +// ListByServicePreparer prepares the ListByService request. +func (client ContentItemClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "contentTypeId": autorest.Encode("path", contentTypeID), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "serviceName": autorest.Encode("path", serviceName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2019-12-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/contentTypes/{contentTypeId}/contentItems", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByServiceSender sends the ListByService request. The method will close the +// http.Response Body if it receives an error. +func (client ContentItemClient) ListByServiceSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListByServiceResponder handles the response to the ListByService request. The method always +// closes the http.Response Body. +func (client ContentItemClient) ListByServiceResponder(resp *http.Response) (result ContentItemCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listByServiceNextResults retrieves the next set of results, if any. +func (client ContentItemClient) listByServiceNextResults(ctx context.Context, lastResults ContentItemCollection) (result ContentItemCollection, err error) { + req, err := lastResults.contentItemCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "apimanagement.ContentItemClient", "listByServiceNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListByServiceSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "apimanagement.ContentItemClient", "listByServiceNextResults", resp, "Failure sending next results request") + } + result, err = client.ListByServiceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentItemClient", "listByServiceNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required. +func (client ContentItemClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string) (result ContentItemCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ContentItemClient.ListByService") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, contentTypeID) + return +} diff --git a/services/apimanagement/mgmt/2019-12-01/apimanagement/contenttype.go b/services/apimanagement/mgmt/2019-12-01/apimanagement/contenttype.go new file mode 100644 index 000000000000..32b02d23e29f --- /dev/null +++ b/services/apimanagement/mgmt/2019-12-01/apimanagement/contenttype.go @@ -0,0 +1,429 @@ +package apimanagement + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// ContentTypeClient is the apiManagement Client +type ContentTypeClient struct { + BaseClient +} + +// NewContentTypeClient creates an instance of the ContentTypeClient client. +func NewContentTypeClient(subscriptionID string) ContentTypeClient { + return NewContentTypeClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewContentTypeClientWithBaseURI creates an instance of the ContentTypeClient client using a custom endpoint. Use +// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewContentTypeClientWithBaseURI(baseURI string, subscriptionID string) ContentTypeClient { + return ContentTypeClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate creates new content type +// Parameters: +// resourceGroupName - the name of the resource group. +// serviceName - the name of the API Management service. +// contentTypeID - content type identifier. +func (client ContentTypeClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string) (result ContentTypeContract, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ContentTypeClient.CreateOrUpdate") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: serviceName, + Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, + {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, + {TargetValue: contentTypeID, + Constraints: []validation.Constraint{{Target: "contentTypeID", Name: validation.MaxLength, Rule: 80, Chain: nil}, + {Target: "contentTypeID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("apimanagement.ContentTypeClient", "CreateOrUpdate", err.Error()) + } + + req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, contentTypeID) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentTypeClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "apimanagement.ContentTypeClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentTypeClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client ContentTypeClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "contentTypeId": autorest.Encode("path", contentTypeID), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "serviceName": autorest.Encode("path", serviceName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2019-12-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/contentTypes/{contentTypeId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client ContentTypeClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client ContentTypeClient) CreateOrUpdateResponder(resp *http.Response) (result ContentTypeContract, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete removes specified content type. +// Parameters: +// resourceGroupName - the name of the resource group. +// serviceName - the name of the API Management service. +// contentTypeID - content type identifier. +func (client ContentTypeClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ContentTypeClient.Delete") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: serviceName, + Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, + {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, + {TargetValue: contentTypeID, + Constraints: []validation.Constraint{{Target: "contentTypeID", Name: validation.MaxLength, Rule: 80, Chain: nil}, + {Target: "contentTypeID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("apimanagement.ContentTypeClient", "Delete", err.Error()) + } + + req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, contentTypeID) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentTypeClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "apimanagement.ContentTypeClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentTypeClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client ContentTypeClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "contentTypeId": autorest.Encode("path", contentTypeID), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "serviceName": autorest.Encode("path", serviceName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2019-12-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/contentTypes/{contentTypeId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client ContentTypeClient) DeleteSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client ContentTypeClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.Response = resp + return +} + +// GetEntityTag returns content type metadata +// Parameters: +// resourceGroupName - the name of the resource group. +// serviceName - the name of the API Management service. +// contentTypeID - content type identifier. +func (client ContentTypeClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ContentTypeClient.GetEntityTag") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: serviceName, + Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, + {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, + {TargetValue: contentTypeID, + Constraints: []validation.Constraint{{Target: "contentTypeID", Name: validation.MaxLength, Rule: 80, Chain: nil}, + {Target: "contentTypeID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("apimanagement.ContentTypeClient", "GetEntityTag", err.Error()) + } + + req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, contentTypeID) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentTypeClient", "GetEntityTag", nil, "Failure preparing request") + return + } + + resp, err := client.GetEntityTagSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "apimanagement.ContentTypeClient", "GetEntityTag", resp, "Failure sending request") + return + } + + result, err = client.GetEntityTagResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentTypeClient", "GetEntityTag", resp, "Failure responding to request") + } + + return +} + +// GetEntityTagPreparer prepares the GetEntityTag request. +func (client ContentTypeClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "contentTypeId": autorest.Encode("path", contentTypeID), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "serviceName": autorest.Encode("path", serviceName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2019-12-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsHead(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/contentTypes/{contentTypeId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetEntityTagSender sends the GetEntityTag request. The method will close the +// http.Response Body if it receives an error. +func (client ContentTypeClient) GetEntityTagSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetEntityTagResponder handles the response to the GetEntityTag request. The method always +// closes the http.Response Body. +func (client ContentTypeClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.Response = resp + return +} + +// ListByService returns list of content types +// Parameters: +// resourceGroupName - the name of the resource group. +// serviceName - the name of the API Management service. +func (client ContentTypeClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string) (result ContentTypeCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ContentTypeClient.ListByService") + defer func() { + sc := -1 + if result.ctc.Response.Response != nil { + sc = result.ctc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: serviceName, + Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, + {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("apimanagement.ContentTypeClient", "ListByService", err.Error()) + } + + result.fn = client.listByServiceNextResults + req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentTypeClient", "ListByService", nil, "Failure preparing request") + return + } + + resp, err := client.ListByServiceSender(req) + if err != nil { + result.ctc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "apimanagement.ContentTypeClient", "ListByService", resp, "Failure sending request") + return + } + + result.ctc, err = client.ListByServiceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentTypeClient", "ListByService", resp, "Failure responding to request") + } + if result.ctc.hasNextLink() && result.ctc.IsEmpty() { + err = result.NextWithContext(ctx) + } + + return +} + +// ListByServicePreparer prepares the ListByService request. +func (client ContentTypeClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "serviceName": autorest.Encode("path", serviceName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2019-12-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/contentTypes", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByServiceSender sends the ListByService request. The method will close the +// http.Response Body if it receives an error. +func (client ContentTypeClient) ListByServiceSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListByServiceResponder handles the response to the ListByService request. The method always +// closes the http.Response Body. +func (client ContentTypeClient) ListByServiceResponder(resp *http.Response) (result ContentTypeCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listByServiceNextResults retrieves the next set of results, if any. +func (client ContentTypeClient) listByServiceNextResults(ctx context.Context, lastResults ContentTypeCollection) (result ContentTypeCollection, err error) { + req, err := lastResults.contentTypeCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "apimanagement.ContentTypeClient", "listByServiceNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListByServiceSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "apimanagement.ContentTypeClient", "listByServiceNextResults", resp, "Failure sending next results request") + } + result, err = client.ListByServiceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentTypeClient", "listByServiceNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required. +func (client ContentTypeClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string) (result ContentTypeCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ContentTypeClient.ListByService") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListByService(ctx, resourceGroupName, serviceName) + return +} diff --git a/services/apimanagement/mgmt/2019-12-01/apimanagement/contenttypes.go b/services/apimanagement/mgmt/2019-12-01/apimanagement/contenttypes.go new file mode 100644 index 000000000000..3f200a572036 --- /dev/null +++ b/services/apimanagement/mgmt/2019-12-01/apimanagement/contenttypes.go @@ -0,0 +1,131 @@ +package apimanagement + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// ContentTypesClient is the apiManagement Client +type ContentTypesClient struct { + BaseClient +} + +// NewContentTypesClient creates an instance of the ContentTypesClient client. +func NewContentTypesClient(subscriptionID string) ContentTypesClient { + return NewContentTypesClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewContentTypesClientWithBaseURI creates an instance of the ContentTypesClient client using a custom endpoint. Use +// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewContentTypesClientWithBaseURI(baseURI string, subscriptionID string) ContentTypesClient { + return ContentTypesClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// Get gets API Management content type details +// Parameters: +// resourceGroupName - the name of the resource group. +// serviceName - the name of the API Management service. +// contentTypeID - content type identifier. +func (client ContentTypesClient) Get(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string) (result ContentTypeContract, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ContentTypesClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: serviceName, + Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, + {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, + {TargetValue: contentTypeID, + Constraints: []validation.Constraint{{Target: "contentTypeID", Name: validation.MaxLength, Rule: 80, Chain: nil}, + {Target: "contentTypeID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("apimanagement.ContentTypesClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, contentTypeID) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentTypesClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "apimanagement.ContentTypesClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "apimanagement.ContentTypesClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client ContentTypesClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, contentTypeID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "contentTypeId": autorest.Encode("path", contentTypeID), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "serviceName": autorest.Encode("path", serviceName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2019-12-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/contentTypes/{contentTypeId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client ContentTypesClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client ContentTypesClient) GetResponder(resp *http.Response) (result ContentTypeContract, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/apimanagement/mgmt/2019-12-01/apimanagement/models.go b/services/apimanagement/mgmt/2019-12-01/apimanagement/models.go index 0fe2907470db..f2dc35df44fc 100644 --- a/services/apimanagement/mgmt/2019-12-01/apimanagement/models.go +++ b/services/apimanagement/mgmt/2019-12-01/apimanagement/models.go @@ -3366,14 +3366,163 @@ type ConnectivityStatusContract struct { // ContentItemCollection paged list of content items. type ContentItemCollection struct { + autorest.Response `json:"-"` // Value - READ-ONLY; Collection of content items. Value *[]ContentItemContract `json:"value,omitempty"` // NextLink - READ-ONLY; Next page link, if any. NextLink *string `json:"nextLink,omitempty"` } +// ContentItemCollectionIterator provides access to a complete listing of ContentItemContract values. +type ContentItemCollectionIterator struct { + i int + page ContentItemCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *ContentItemCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ContentItemCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *ContentItemCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter ContentItemCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter ContentItemCollectionIterator) Response() ContentItemCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter ContentItemCollectionIterator) Value() ContentItemContract { + if !iter.page.NotDone() { + return ContentItemContract{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the ContentItemCollectionIterator type. +func NewContentItemCollectionIterator(page ContentItemCollectionPage) ContentItemCollectionIterator { + return ContentItemCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (cic ContentItemCollection) IsEmpty() bool { + return cic.Value == nil || len(*cic.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (cic ContentItemCollection) hasNextLink() bool { + return cic.NextLink != nil && len(*cic.NextLink) != 0 +} + +// contentItemCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (cic ContentItemCollection) contentItemCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !cic.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(cic.NextLink))) +} + +// ContentItemCollectionPage contains a page of ContentItemContract values. +type ContentItemCollectionPage struct { + fn func(context.Context, ContentItemCollection) (ContentItemCollection, error) + cic ContentItemCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *ContentItemCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ContentItemCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.cic) + if err != nil { + return err + } + page.cic = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *ContentItemCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page ContentItemCollectionPage) NotDone() bool { + return !page.cic.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page ContentItemCollectionPage) Response() ContentItemCollection { + return page.cic +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page ContentItemCollectionPage) Values() []ContentItemContract { + if page.cic.IsEmpty() { + return nil + } + return *page.cic.Value +} + +// Creates a new instance of the ContentItemCollectionPage type. +func NewContentItemCollectionPage(getNextPage func(context.Context, ContentItemCollection) (ContentItemCollection, error)) ContentItemCollectionPage { + return ContentItemCollectionPage{fn: getNextPage} +} + // ContentItemContract content type contract details. type ContentItemContract struct { + autorest.Response `json:"-"` // Properties - Properties of the content item. Properties map[string]interface{} `json:"properties"` // ID - READ-ONLY; Resource ID. @@ -3395,14 +3544,163 @@ func (cic ContentItemContract) MarshalJSON() ([]byte, error) { // ContentTypeCollection paged list of content types. type ContentTypeCollection struct { + autorest.Response `json:"-"` // Value - READ-ONLY; Collection of content types. Value *[]ContentTypeContract `json:"value,omitempty"` // NextLink - READ-ONLY; Next page link, if any. NextLink *string `json:"nextLink,omitempty"` } +// ContentTypeCollectionIterator provides access to a complete listing of ContentTypeContract values. +type ContentTypeCollectionIterator struct { + i int + page ContentTypeCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *ContentTypeCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ContentTypeCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *ContentTypeCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter ContentTypeCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter ContentTypeCollectionIterator) Response() ContentTypeCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter ContentTypeCollectionIterator) Value() ContentTypeContract { + if !iter.page.NotDone() { + return ContentTypeContract{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the ContentTypeCollectionIterator type. +func NewContentTypeCollectionIterator(page ContentTypeCollectionPage) ContentTypeCollectionIterator { + return ContentTypeCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (ctc ContentTypeCollection) IsEmpty() bool { + return ctc.Value == nil || len(*ctc.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (ctc ContentTypeCollection) hasNextLink() bool { + return ctc.NextLink != nil && len(*ctc.NextLink) != 0 +} + +// contentTypeCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (ctc ContentTypeCollection) contentTypeCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !ctc.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(ctc.NextLink))) +} + +// ContentTypeCollectionPage contains a page of ContentTypeContract values. +type ContentTypeCollectionPage struct { + fn func(context.Context, ContentTypeCollection) (ContentTypeCollection, error) + ctc ContentTypeCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *ContentTypeCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ContentTypeCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.ctc) + if err != nil { + return err + } + page.ctc = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *ContentTypeCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page ContentTypeCollectionPage) NotDone() bool { + return !page.ctc.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page ContentTypeCollectionPage) Response() ContentTypeCollection { + return page.ctc +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page ContentTypeCollectionPage) Values() []ContentTypeContract { + if page.ctc.IsEmpty() { + return nil + } + return *page.ctc.Value +} + +// Creates a new instance of the ContentTypeCollectionPage type. +func NewContentTypeCollectionPage(getNextPage func(context.Context, ContentTypeCollection) (ContentTypeCollection, error)) ContentTypeCollectionPage { + return ContentTypeCollectionPage{fn: getNextPage} +} + // ContentTypeContract content type contract details. type ContentTypeContract struct { + autorest.Response `json:"-"` // ContentTypeContractProperties - Properties of the content type. *ContentTypeContractProperties `json:"properties,omitempty"` // ID - READ-ONLY; Resource ID. @@ -8934,9 +9232,9 @@ type ProductContractProperties struct { Terms *string `json:"terms,omitempty"` // SubscriptionRequired - Whether a product subscription is required for accessing APIs included in this product. If true, the product is referred to as "protected" and a valid subscription key is required for a request to an API included in the product to succeed. If false, the product is referred to as "open" and requests to an API included in the product can be made without a subscription key. If property is omitted when creating a new product it's value is assumed to be true. SubscriptionRequired *bool `json:"subscriptionRequired,omitempty"` - // ApprovalRequired - whether subscription approval is required. If false, new subscriptions will be approved automatically enabling developers to call the product’s APIs immediately after subscribing. If true, administrators must manually approve the subscription before the developer can any of the product’s APIs. Can be present only if subscriptionRequired property is present and has a value of false. + // ApprovalRequired - whether subscription approval is required. If false, new subscriptions will be approved automatically enabling developers to call the product’s APIs immediately after subscribing. If true, administrators must manually approve the subscription before the developer can any of the product’s APIs. Can be present only if subscriptionRequired property is present and has a value of true. ApprovalRequired *bool `json:"approvalRequired,omitempty"` - // SubscriptionsLimit - Whether the number of subscriptions a user can have to this product at the same time. Set to null or omit to allow unlimited per user subscriptions. Can be present only if subscriptionRequired property is present and has a value of false. + // SubscriptionsLimit - Whether the number of subscriptions a user can have to this product at the same time. Set to null or omit to allow unlimited per user subscriptions. Can be present only if subscriptionRequired property is present and has a value of true. SubscriptionsLimit *int32 `json:"subscriptionsLimit,omitempty"` // State - whether product is published or not. Published products are discoverable by users of developer portal. Non published products are visible only to administrators. Default state of Product is notPublished. Possible values include: 'NotPublished', 'Published' State ProductState `json:"state,omitempty"` @@ -8950,9 +9248,9 @@ type ProductEntityBaseParameters struct { Terms *string `json:"terms,omitempty"` // SubscriptionRequired - Whether a product subscription is required for accessing APIs included in this product. If true, the product is referred to as "protected" and a valid subscription key is required for a request to an API included in the product to succeed. If false, the product is referred to as "open" and requests to an API included in the product can be made without a subscription key. If property is omitted when creating a new product it's value is assumed to be true. SubscriptionRequired *bool `json:"subscriptionRequired,omitempty"` - // ApprovalRequired - whether subscription approval is required. If false, new subscriptions will be approved automatically enabling developers to call the product’s APIs immediately after subscribing. If true, administrators must manually approve the subscription before the developer can any of the product’s APIs. Can be present only if subscriptionRequired property is present and has a value of false. + // ApprovalRequired - whether subscription approval is required. If false, new subscriptions will be approved automatically enabling developers to call the product’s APIs immediately after subscribing. If true, administrators must manually approve the subscription before the developer can any of the product’s APIs. Can be present only if subscriptionRequired property is present and has a value of true. ApprovalRequired *bool `json:"approvalRequired,omitempty"` - // SubscriptionsLimit - Whether the number of subscriptions a user can have to this product at the same time. Set to null or omit to allow unlimited per user subscriptions. Can be present only if subscriptionRequired property is present and has a value of false. + // SubscriptionsLimit - Whether the number of subscriptions a user can have to this product at the same time. Set to null or omit to allow unlimited per user subscriptions. Can be present only if subscriptionRequired property is present and has a value of true. SubscriptionsLimit *int32 `json:"subscriptionsLimit,omitempty"` // State - whether product is published or not. Published products are discoverable by users of developer portal. Non published products are visible only to administrators. Default state of Product is notPublished. Possible values include: 'NotPublished', 'Published' State ProductState `json:"state,omitempty"` @@ -8970,9 +9268,9 @@ type ProductTagResourceContractProperties struct { Terms *string `json:"terms,omitempty"` // SubscriptionRequired - Whether a product subscription is required for accessing APIs included in this product. If true, the product is referred to as "protected" and a valid subscription key is required for a request to an API included in the product to succeed. If false, the product is referred to as "open" and requests to an API included in the product can be made without a subscription key. If property is omitted when creating a new product it's value is assumed to be true. SubscriptionRequired *bool `json:"subscriptionRequired,omitempty"` - // ApprovalRequired - whether subscription approval is required. If false, new subscriptions will be approved automatically enabling developers to call the product’s APIs immediately after subscribing. If true, administrators must manually approve the subscription before the developer can any of the product’s APIs. Can be present only if subscriptionRequired property is present and has a value of false. + // ApprovalRequired - whether subscription approval is required. If false, new subscriptions will be approved automatically enabling developers to call the product’s APIs immediately after subscribing. If true, administrators must manually approve the subscription before the developer can any of the product’s APIs. Can be present only if subscriptionRequired property is present and has a value of true. ApprovalRequired *bool `json:"approvalRequired,omitempty"` - // SubscriptionsLimit - Whether the number of subscriptions a user can have to this product at the same time. Set to null or omit to allow unlimited per user subscriptions. Can be present only if subscriptionRequired property is present and has a value of false. + // SubscriptionsLimit - Whether the number of subscriptions a user can have to this product at the same time. Set to null or omit to allow unlimited per user subscriptions. Can be present only if subscriptionRequired property is present and has a value of true. SubscriptionsLimit *int32 `json:"subscriptionsLimit,omitempty"` // State - whether product is published or not. Published products are discoverable by users of developer portal. Non published products are visible only to administrators. Default state of Product is notPublished. Possible values include: 'NotPublished', 'Published' State ProductState `json:"state,omitempty"` @@ -9027,9 +9325,9 @@ type ProductUpdateProperties struct { Terms *string `json:"terms,omitempty"` // SubscriptionRequired - Whether a product subscription is required for accessing APIs included in this product. If true, the product is referred to as "protected" and a valid subscription key is required for a request to an API included in the product to succeed. If false, the product is referred to as "open" and requests to an API included in the product can be made without a subscription key. If property is omitted when creating a new product it's value is assumed to be true. SubscriptionRequired *bool `json:"subscriptionRequired,omitempty"` - // ApprovalRequired - whether subscription approval is required. If false, new subscriptions will be approved automatically enabling developers to call the product’s APIs immediately after subscribing. If true, administrators must manually approve the subscription before the developer can any of the product’s APIs. Can be present only if subscriptionRequired property is present and has a value of false. + // ApprovalRequired - whether subscription approval is required. If false, new subscriptions will be approved automatically enabling developers to call the product’s APIs immediately after subscribing. If true, administrators must manually approve the subscription before the developer can any of the product’s APIs. Can be present only if subscriptionRequired property is present and has a value of true. ApprovalRequired *bool `json:"approvalRequired,omitempty"` - // SubscriptionsLimit - Whether the number of subscriptions a user can have to this product at the same time. Set to null or omit to allow unlimited per user subscriptions. Can be present only if subscriptionRequired property is present and has a value of false. + // SubscriptionsLimit - Whether the number of subscriptions a user can have to this product at the same time. Set to null or omit to allow unlimited per user subscriptions. Can be present only if subscriptionRequired property is present and has a value of true. SubscriptionsLimit *int32 `json:"subscriptionsLimit,omitempty"` // State - whether product is published or not. Published products are discoverable by users of developer portal. Non published products are visible only to administrators. Default state of Product is notPublished. Possible values include: 'NotPublished', 'Published' State ProductState `json:"state,omitempty"`