diff --git a/profiles/preview/iotcentral/mgmt/iotcentral/models.go b/profiles/preview/iotcentral/mgmt/iotcentral/models.go index 28af2c30b087..9d96c9420892 100644 --- a/profiles/preview/iotcentral/mgmt/iotcentral/models.go +++ b/profiles/preview/iotcentral/mgmt/iotcentral/models.go @@ -28,13 +28,6 @@ const ( ) type BaseClient = original.BaseClient -type AppNameUnavailabilityReason = original.AppNameUnavailabilityReason - -const ( - AlreadyExists AppNameUnavailabilityReason = original.AlreadyExists - Invalid AppNameUnavailabilityReason = original.Invalid -) - type AppSku = original.AppSku const ( @@ -43,10 +36,10 @@ const ( ) type App = original.App +type AppAvailabilityInfo = original.AppAvailabilityInfo type AppListResult = original.AppListResult type AppListResultIterator = original.AppListResultIterator type AppListResultPage = original.AppListResultPage -type AppNameAvailabilityInfo = original.AppNameAvailabilityInfo type AppPatch = original.AppPatch type AppProperties = original.AppProperties type AppsCreateOrUpdateFuture = original.AppsCreateOrUpdateFuture @@ -54,6 +47,7 @@ type AppsDeleteFuture = original.AppsDeleteFuture type AppSkuInfo = original.AppSkuInfo type AppsUpdateFuture = original.AppsUpdateFuture type ErrorDetails = original.ErrorDetails +type ErrorResponseBody = original.ErrorResponseBody type Operation = original.Operation type OperationDisplay = original.OperationDisplay type OperationInputs = original.OperationInputs @@ -75,9 +69,6 @@ func New(subscriptionID string) BaseClient { func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient { return original.NewWithBaseURI(baseURI, subscriptionID) } -func PossibleAppNameUnavailabilityReasonValues() []AppNameUnavailabilityReason { - return original.PossibleAppNameUnavailabilityReasonValues() -} func PossibleAppSkuValues() []AppSku { return original.PossibleAppSkuValues() } diff --git a/services/iotcentral/mgmt/2018-09-01/iotcentral/apps.go b/services/iotcentral/mgmt/2018-09-01/iotcentral/apps.go index 145629c38132..31bceeece96d 100644 --- a/services/iotcentral/mgmt/2018-09-01/iotcentral/apps.go +++ b/services/iotcentral/mgmt/2018-09-01/iotcentral/apps.go @@ -44,10 +44,11 @@ func NewAppsClientWithBaseURI(baseURI string, subscriptionID string) AppsClient // Parameters: // operationInputs - set the name parameter in the OperationInputs structure to the name of the IoT Central // application to check. -func (client AppsClient) CheckNameAvailability(ctx context.Context, operationInputs OperationInputs) (result AppNameAvailabilityInfo, err error) { +func (client AppsClient) CheckNameAvailability(ctx context.Context, operationInputs OperationInputs) (result AppAvailabilityInfo, err error) { if err := validation.Validate([]validation.Validation{ {TargetValue: operationInputs, - Constraints: []validation.Constraint{{Target: "operationInputs.Name", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + Constraints: []validation.Constraint{{Target: "operationInputs.Name", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "operationInputs.Name", Name: validation.Pattern, Rule: `^[a-z0-9-]{1,63}$`, Chain: nil}}}}}}); err != nil { return result, validation.NewError("iotcentral.AppsClient", "CheckNameAvailability", err.Error()) } @@ -102,7 +103,81 @@ func (client AppsClient) CheckNameAvailabilitySender(req *http.Request) (*http.R // CheckNameAvailabilityResponder handles the response to the CheckNameAvailability request. The method always // closes the http.Response Body. -func (client AppsClient) CheckNameAvailabilityResponder(resp *http.Response) (result AppNameAvailabilityInfo, err error) { +func (client AppsClient) CheckNameAvailabilityResponder(resp *http.Response) (result AppAvailabilityInfo, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// CheckSubdomainAvailability check if an IoT Central application subdomain is available. +// Parameters: +// operationInputs - set the name parameter in the OperationInputs structure to the subdomain of the IoT +// Central application to check. +func (client AppsClient) CheckSubdomainAvailability(ctx context.Context, operationInputs OperationInputs) (result AppAvailabilityInfo, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: operationInputs, + Constraints: []validation.Constraint{{Target: "operationInputs.Name", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "operationInputs.Name", Name: validation.Pattern, Rule: `^[a-z0-9-]{1,63}$`, Chain: nil}}}}}}); err != nil { + return result, validation.NewError("iotcentral.AppsClient", "CheckSubdomainAvailability", err.Error()) + } + + req, err := client.CheckSubdomainAvailabilityPreparer(ctx, operationInputs) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.AppsClient", "CheckSubdomainAvailability", nil, "Failure preparing request") + return + } + + resp, err := client.CheckSubdomainAvailabilitySender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.AppsClient", "CheckSubdomainAvailability", resp, "Failure sending request") + return + } + + result, err = client.CheckSubdomainAvailabilityResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.AppsClient", "CheckSubdomainAvailability", resp, "Failure responding to request") + } + + return +} + +// CheckSubdomainAvailabilityPreparer prepares the CheckSubdomainAvailability request. +func (client AppsClient) CheckSubdomainAvailabilityPreparer(ctx context.Context, operationInputs OperationInputs) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2018-09-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.IoTCentral/checkSubdomainAvailability", pathParameters), + autorest.WithJSON(operationInputs), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CheckSubdomainAvailabilitySender sends the CheckSubdomainAvailability request. The method will close the +// http.Response Body if it receives an error. +func (client AppsClient) CheckSubdomainAvailabilitySender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// CheckSubdomainAvailabilityResponder handles the response to the CheckSubdomainAvailability request. The method always +// closes the http.Response Body. +func (client AppsClient) CheckSubdomainAvailabilityResponder(resp *http.Response) (result AppAvailabilityInfo, err error) { err = autorest.Respond( resp, client.ByInspecting(), @@ -180,10 +255,6 @@ func (client AppsClient) CreateOrUpdateSender(req *http.Request) (future AppsCre if err != nil { return } - err = autorest.Respond(resp, azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted)) - if err != nil { - return - } future.Future, err = azure.NewFutureFromResponse(resp) return } @@ -251,10 +322,6 @@ func (client AppsClient) DeleteSender(req *http.Request) (future AppsDeleteFutur if err != nil { return } - err = autorest.Respond(resp, azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent)) - if err != nil { - return - } future.Future, err = azure.NewFutureFromResponse(resp) return } @@ -574,10 +641,6 @@ func (client AppsClient) UpdateSender(req *http.Request) (future AppsUpdateFutur if err != nil { return } - err = autorest.Respond(resp, azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted)) - if err != nil { - return - } future.Future, err = azure.NewFutureFromResponse(resp) return } diff --git a/services/iotcentral/mgmt/2018-09-01/iotcentral/models.go b/services/iotcentral/mgmt/2018-09-01/iotcentral/models.go index d7c15bb53d97..03d7bed3057d 100644 --- a/services/iotcentral/mgmt/2018-09-01/iotcentral/models.go +++ b/services/iotcentral/mgmt/2018-09-01/iotcentral/models.go @@ -25,21 +25,6 @@ import ( "net/http" ) -// AppNameUnavailabilityReason enumerates the values for app name unavailability reason. -type AppNameUnavailabilityReason string - -const ( - // AlreadyExists ... - AlreadyExists AppNameUnavailabilityReason = "AlreadyExists" - // Invalid ... - Invalid AppNameUnavailabilityReason = "Invalid" -) - -// PossibleAppNameUnavailabilityReasonValues returns an array of possible values for the AppNameUnavailabilityReason const type. -func PossibleAppNameUnavailabilityReasonValues() []AppNameUnavailabilityReason { - return []AppNameUnavailabilityReason{AlreadyExists, Invalid} -} - // AppSku enumerates the values for app sku. type AppSku string @@ -179,6 +164,18 @@ func (a *App) UnmarshalJSON(body []byte) error { return nil } +// AppAvailabilityInfo the properties indicating whether a given IoT Central application name or subdomain is +// available. +type AppAvailabilityInfo struct { + autorest.Response `json:"-"` + // NameAvailable - The value which indicates whether the provided name is available. + NameAvailable *bool `json:"nameAvailable,omitempty"` + // Reason - The reason for unavailability. + Reason *string `json:"reason,omitempty"` + // Message - The detailed reason message. + Message *string `json:"message,omitempty"` +} + // AppListResult a list of IoT Central Applications with a next link. type AppListResult struct { autorest.Response `json:"-"` @@ -281,17 +278,6 @@ func (page AppListResultPage) Values() []App { return *page.alr.Value } -// AppNameAvailabilityInfo the properties indicating whether a given IoT Central application name is available. -type AppNameAvailabilityInfo struct { - autorest.Response `json:"-"` - // NameAvailable - The value which indicates whether the provided name is available. - NameAvailable *bool `json:"nameAvailable,omitempty"` - // Reason - The reason for unavailability. Possible values include: 'Invalid', 'AlreadyExists' - Reason AppNameUnavailabilityReason `json:"reason,omitempty"` - // Message - The detailed reason message. - Message *string `json:"message,omitempty"` -} - // AppPatch the description of the IoT Central application. type AppPatch struct { // Tags - Instance tags @@ -443,12 +429,52 @@ func (future *AppsUpdateFuture) Result(client AppsClient) (a App, err error) { // ErrorDetails error details. type ErrorDetails struct { + *ErrorResponseBody `json:"error,omitempty"` +} + +// MarshalJSON is the custom marshaler for ErrorDetails. +func (ed ErrorDetails) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if ed.ErrorResponseBody != nil { + objectMap["error"] = ed.ErrorResponseBody + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for ErrorDetails struct. +func (ed *ErrorDetails) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "error": + if v != nil { + var errorResponseBody ErrorResponseBody + err = json.Unmarshal(*v, &errorResponseBody) + if err != nil { + return err + } + ed.ErrorResponseBody = &errorResponseBody + } + } + } + + return nil +} + +// ErrorResponseBody details of error response. +type ErrorResponseBody struct { // Code - The error code. Code *string `json:"code,omitempty"` // Message - The error message. Message *string `json:"message,omitempty"` // Target - The target of the particular error. Target *string `json:"target,omitempty"` + // Details - A list of additional details about the error. + Details *[]ErrorResponseBody `json:"details,omitempty"` } // Operation ioT Central REST API operation @@ -475,6 +501,8 @@ type OperationDisplay struct { type OperationInputs struct { // Name - The name of the IoT Central application instance to check. Name *string `json:"name,omitempty"` + // Type - The type of the IoT Central resource to query. + Type *string `json:"type,omitempty"` } // OperationListResult a list of IoT Central operations. It contains a list of operations and a URL link to get the