diff --git a/profiles/latest/iotcentral/mgmt/iotcentral/models.go b/profiles/latest/iotcentral/mgmt/iotcentral/models.go index ccc401836fbe..7d03f897bccd 100644 --- a/profiles/latest/iotcentral/mgmt/iotcentral/models.go +++ b/profiles/latest/iotcentral/mgmt/iotcentral/models.go @@ -44,6 +44,10 @@ type AppListResultPage = original.AppListResultPage type AppPatch = original.AppPatch type AppProperties = original.AppProperties type AppSkuInfo = original.AppSkuInfo +type AppTemplate = original.AppTemplate +type AppTemplatesResult = original.AppTemplatesResult +type AppTemplatesResultIterator = original.AppTemplatesResultIterator +type AppTemplatesResultPage = original.AppTemplatesResultPage type AppsClient = original.AppsClient type AppsCreateOrUpdateFuture = original.AppsCreateOrUpdateFuture type AppsDeleteFuture = original.AppsDeleteFuture @@ -69,6 +73,12 @@ func NewAppListResultIterator(page AppListResultPage) AppListResultIterator { func NewAppListResultPage(getNextPage func(context.Context, AppListResult) (AppListResult, error)) AppListResultPage { return original.NewAppListResultPage(getNextPage) } +func NewAppTemplatesResultIterator(page AppTemplatesResultPage) AppTemplatesResultIterator { + return original.NewAppTemplatesResultIterator(page) +} +func NewAppTemplatesResultPage(getNextPage func(context.Context, AppTemplatesResult) (AppTemplatesResult, error)) AppTemplatesResultPage { + return original.NewAppTemplatesResultPage(getNextPage) +} func NewAppsClient(subscriptionID string) AppsClient { return original.NewAppsClient(subscriptionID) } diff --git a/profiles/preview/iotcentral/mgmt/iotcentral/models.go b/profiles/preview/iotcentral/mgmt/iotcentral/models.go index dc7f6a5b83a0..820d6b91ec50 100644 --- a/profiles/preview/iotcentral/mgmt/iotcentral/models.go +++ b/profiles/preview/iotcentral/mgmt/iotcentral/models.go @@ -44,6 +44,10 @@ type AppListResultPage = original.AppListResultPage type AppPatch = original.AppPatch type AppProperties = original.AppProperties type AppSkuInfo = original.AppSkuInfo +type AppTemplate = original.AppTemplate +type AppTemplatesResult = original.AppTemplatesResult +type AppTemplatesResultIterator = original.AppTemplatesResultIterator +type AppTemplatesResultPage = original.AppTemplatesResultPage type AppsClient = original.AppsClient type AppsCreateOrUpdateFuture = original.AppsCreateOrUpdateFuture type AppsDeleteFuture = original.AppsDeleteFuture @@ -69,6 +73,12 @@ func NewAppListResultIterator(page AppListResultPage) AppListResultIterator { func NewAppListResultPage(getNextPage func(context.Context, AppListResult) (AppListResult, error)) AppListResultPage { return original.NewAppListResultPage(getNextPage) } +func NewAppTemplatesResultIterator(page AppTemplatesResultPage) AppTemplatesResultIterator { + return original.NewAppTemplatesResultIterator(page) +} +func NewAppTemplatesResultPage(getNextPage func(context.Context, AppTemplatesResult) (AppTemplatesResult, error)) AppTemplatesResultPage { + return original.NewAppTemplatesResultPage(getNextPage) +} func NewAppsClient(subscriptionID string) AppsClient { return original.NewAppsClient(subscriptionID) } diff --git a/services/iotcentral/mgmt/2018-09-01/iotcentral/apps.go b/services/iotcentral/mgmt/2018-09-01/iotcentral/apps.go index 4517bda1d98e..3717054ff4c3 100644 --- a/services/iotcentral/mgmt/2018-09-01/iotcentral/apps.go +++ b/services/iotcentral/mgmt/2018-09-01/iotcentral/apps.go @@ -679,6 +679,116 @@ func (client AppsClient) ListBySubscriptionComplete(ctx context.Context) (result return } +// ListTemplates get all available application templates. +func (client AppsClient) ListTemplates(ctx context.Context) (result AppTemplatesResultPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AppsClient.ListTemplates") + defer func() { + sc := -1 + if result.atr.Response.Response != nil { + sc = result.atr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listTemplatesNextResults + req, err := client.ListTemplatesPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.AppsClient", "ListTemplates", nil, "Failure preparing request") + return + } + + resp, err := client.ListTemplatesSender(req) + if err != nil { + result.atr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "iotcentral.AppsClient", "ListTemplates", resp, "Failure sending request") + return + } + + result.atr, err = client.ListTemplatesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.AppsClient", "ListTemplates", resp, "Failure responding to request") + } + + return +} + +// ListTemplatesPreparer prepares the ListTemplates request. +func (client AppsClient) ListTemplatesPreparer(ctx context.Context) (*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.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.IoTCentral/appTemplates", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListTemplatesSender sends the ListTemplates request. The method will close the +// http.Response Body if it receives an error. +func (client AppsClient) ListTemplatesSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ListTemplatesResponder handles the response to the ListTemplates request. The method always +// closes the http.Response Body. +func (client AppsClient) ListTemplatesResponder(resp *http.Response) (result AppTemplatesResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listTemplatesNextResults retrieves the next set of results, if any. +func (client AppsClient) listTemplatesNextResults(ctx context.Context, lastResults AppTemplatesResult) (result AppTemplatesResult, err error) { + req, err := lastResults.appTemplatesResultPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "iotcentral.AppsClient", "listTemplatesNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListTemplatesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "iotcentral.AppsClient", "listTemplatesNextResults", resp, "Failure sending next results request") + } + result, err = client.ListTemplatesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "iotcentral.AppsClient", "listTemplatesNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListTemplatesComplete enumerates all values, automatically crossing page boundaries as required. +func (client AppsClient) ListTemplatesComplete(ctx context.Context) (result AppTemplatesResultIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AppsClient.ListTemplates") + 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.ListTemplates(ctx) + return +} + // Update update the metadata of an IoT Central application. // Parameters: // resourceGroupName - the name of the resource group that contains the IoT Central application. diff --git a/services/iotcentral/mgmt/2018-09-01/iotcentral/iotcentralapi/interfaces.go b/services/iotcentral/mgmt/2018-09-01/iotcentral/iotcentralapi/interfaces.go index f3ddd2a6d182..e29f9e512546 100644 --- a/services/iotcentral/mgmt/2018-09-01/iotcentral/iotcentralapi/interfaces.go +++ b/services/iotcentral/mgmt/2018-09-01/iotcentral/iotcentralapi/interfaces.go @@ -31,6 +31,7 @@ type AppsClientAPI interface { Get(ctx context.Context, resourceGroupName string, resourceName string) (result iotcentral.App, err error) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result iotcentral.AppListResultPage, err error) ListBySubscription(ctx context.Context) (result iotcentral.AppListResultPage, err error) + ListTemplates(ctx context.Context) (result iotcentral.AppTemplatesResultPage, err error) Update(ctx context.Context, resourceGroupName string, resourceName string, appPatch iotcentral.AppPatch) (result iotcentral.AppsUpdateFuture, err error) } diff --git a/services/iotcentral/mgmt/2018-09-01/iotcentral/models.go b/services/iotcentral/mgmt/2018-09-01/iotcentral/models.go index b0590b8d152c..0b7bf42aceee 100644 --- a/services/iotcentral/mgmt/2018-09-01/iotcentral/models.go +++ b/services/iotcentral/mgmt/2018-09-01/iotcentral/models.go @@ -477,8 +477,171 @@ func (future *AppsUpdateFuture) Result(client AppsClient) (a App, err error) { return } +// AppTemplate ioT Central Application Template. +type AppTemplate struct { + // ManifestID - The ID of the template. + ManifestID *string `json:"manifestId,omitempty"` + // ManifestVersion - The version of the template. + ManifestVersion *string `json:"manifestVersion,omitempty"` + // AppTemplateName - The name of the template. + AppTemplateName *string `json:"appTemplateName,omitempty"` + // Title - The title of the template. + Title *string `json:"title,omitempty"` + // Order - The order of the template in the templates list. + Order *float64 `json:"order,omitempty"` + // Description - The description of the template. + Description *string `json:"description,omitempty"` +} + +// AppTemplatesResult a list of IoT Central Application Templates with a next link. +type AppTemplatesResult struct { + autorest.Response `json:"-"` + // NextLink - The link used to get the next page of IoT Central application templates. + NextLink *string `json:"nextLink,omitempty"` + // Value - A list of IoT Central Application Templates. + Value *[]AppTemplate `json:"value,omitempty"` +} + +// AppTemplatesResultIterator provides access to a complete listing of AppTemplate values. +type AppTemplatesResultIterator struct { + i int + page AppTemplatesResultPage +} + +// 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 *AppTemplatesResultIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AppTemplatesResultIterator.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 *AppTemplatesResultIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter AppTemplatesResultIterator) 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 AppTemplatesResultIterator) Response() AppTemplatesResult { + 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 AppTemplatesResultIterator) Value() AppTemplate { + if !iter.page.NotDone() { + return AppTemplate{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the AppTemplatesResultIterator type. +func NewAppTemplatesResultIterator(page AppTemplatesResultPage) AppTemplatesResultIterator { + return AppTemplatesResultIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (atr AppTemplatesResult) IsEmpty() bool { + return atr.Value == nil || len(*atr.Value) == 0 +} + +// appTemplatesResultPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (atr AppTemplatesResult) appTemplatesResultPreparer(ctx context.Context) (*http.Request, error) { + if atr.NextLink == nil || len(to.String(atr.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(atr.NextLink))) +} + +// AppTemplatesResultPage contains a page of AppTemplate values. +type AppTemplatesResultPage struct { + fn func(context.Context, AppTemplatesResult) (AppTemplatesResult, error) + atr AppTemplatesResult +} + +// 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 *AppTemplatesResultPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AppTemplatesResultPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + next, err := page.fn(ctx, page.atr) + if err != nil { + return err + } + page.atr = next + 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 *AppTemplatesResultPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page AppTemplatesResultPage) NotDone() bool { + return !page.atr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page AppTemplatesResultPage) Response() AppTemplatesResult { + return page.atr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page AppTemplatesResultPage) Values() []AppTemplate { + if page.atr.IsEmpty() { + return nil + } + return *page.atr.Value +} + +// Creates a new instance of the AppTemplatesResultPage type. +func NewAppTemplatesResultPage(getNextPage func(context.Context, AppTemplatesResult) (AppTemplatesResult, error)) AppTemplatesResultPage { + return AppTemplatesResultPage{fn: getNextPage} +} + // ErrorDetails error details. type ErrorDetails struct { + // ErrorResponseBody - Error response body. *ErrorResponseBody `json:"error,omitempty"` }