1package subscription 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// 6// Code generated by Microsoft (R) AutoRest Code Generator. 7// Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9import ( 10 "context" 11 "encoding/json" 12 "github.com/Azure/go-autorest/autorest" 13 "github.com/Azure/go-autorest/autorest/azure" 14 "github.com/Azure/go-autorest/autorest/to" 15 "github.com/Azure/go-autorest/tracing" 16 "net/http" 17) 18 19// The package's fully qualified name. 20const fqdn = "github.com/Azure/azure-sdk-for-go/services/preview/subscription/mgmt/2018-03-01-preview/subscription" 21 22// AdPrincipal active Directory Principal who’ll get owner access on the new subscription. 23type AdPrincipal struct { 24 // ObjectID - Object id of the Principal 25 ObjectID *string `json:"objectId,omitempty"` 26} 27 28// CreationParameters subscription Creation Parameters required to create a new Azure subscription. 29type CreationParameters struct { 30 // DisplayName - The display name of the subscription. 31 DisplayName *string `json:"displayName,omitempty"` 32 // Owners - The list of principals that should be granted Owner access on the subscription. Principals should be of type User, Service Principal or Security Group. 33 Owners *[]AdPrincipal `json:"owners,omitempty"` 34 // OfferType - The offer type of the subscription. For example, MS-AZR-0017P (EnterpriseAgreement) and MS-AZR-0148P (EnterpriseAgreement devTest) are available. Only valid when creating a subscription in a enrollment account scope. Possible values include: 'MSAZR0017P', 'MSAZR0148P' 35 OfferType OfferType `json:"offerType,omitempty"` 36 // AdditionalParameters - Additional, untyped parameters to support custom subscription creation scenarios. 37 AdditionalParameters map[string]interface{} `json:"additionalParameters"` 38} 39 40// MarshalJSON is the custom marshaler for CreationParameters. 41func (cp CreationParameters) MarshalJSON() ([]byte, error) { 42 objectMap := make(map[string]interface{}) 43 if cp.DisplayName != nil { 44 objectMap["displayName"] = cp.DisplayName 45 } 46 if cp.Owners != nil { 47 objectMap["owners"] = cp.Owners 48 } 49 if cp.OfferType != "" { 50 objectMap["offerType"] = cp.OfferType 51 } 52 if cp.AdditionalParameters != nil { 53 objectMap["additionalParameters"] = cp.AdditionalParameters 54 } 55 return json.Marshal(objectMap) 56} 57 58// CreationResult the created subscription object. 59type CreationResult struct { 60 autorest.Response `json:"-"` 61 // SubscriptionLink - The link to the new subscription. Use this link to check the status of subscription creation operation. 62 SubscriptionLink *string `json:"subscriptionLink,omitempty"` 63} 64 65// ErrorResponse describes the format of Error response. 66type ErrorResponse struct { 67 // Code - Error code 68 Code *string `json:"code,omitempty"` 69 // Message - Error message indicating why the operation failed. 70 Message *string `json:"message,omitempty"` 71} 72 73// FactoryCreateSubscriptionInEnrollmentAccountFuture an abstraction for monitoring and retrieving the 74// results of a long-running operation. 75type FactoryCreateSubscriptionInEnrollmentAccountFuture struct { 76 azure.FutureAPI 77 // Result returns the result of the asynchronous operation. 78 // If the operation has not completed it will return an error. 79 Result func(FactoryClient) (CreationResult, error) 80} 81 82// UnmarshalJSON is the custom unmarshaller for CreateFuture. 83func (future *FactoryCreateSubscriptionInEnrollmentAccountFuture) UnmarshalJSON(body []byte) error { 84 var azFuture azure.Future 85 if err := json.Unmarshal(body, &azFuture); err != nil { 86 return err 87 } 88 future.FutureAPI = &azFuture 89 future.Result = future.result 90 return nil 91} 92 93// result is the default implementation for FactoryCreateSubscriptionInEnrollmentAccountFuture.Result. 94func (future *FactoryCreateSubscriptionInEnrollmentAccountFuture) result(client FactoryClient) (cr CreationResult, err error) { 95 var done bool 96 done, err = future.DoneWithContext(context.Background(), client) 97 if err != nil { 98 err = autorest.NewErrorWithError(err, "subscription.FactoryCreateSubscriptionInEnrollmentAccountFuture", "Result", future.Response(), "Polling failure") 99 return 100 } 101 if !done { 102 cr.Response.Response = future.Response() 103 err = azure.NewAsyncOpIncompleteError("subscription.FactoryCreateSubscriptionInEnrollmentAccountFuture") 104 return 105 } 106 sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 107 if cr.Response.Response, err = future.GetResult(sender); err == nil && cr.Response.Response.StatusCode != http.StatusNoContent { 108 cr, err = client.CreateSubscriptionInEnrollmentAccountResponder(cr.Response.Response) 109 if err != nil { 110 err = autorest.NewErrorWithError(err, "subscription.FactoryCreateSubscriptionInEnrollmentAccountFuture", "Result", cr.Response.Response, "Failure responding to request") 111 } 112 } 113 return 114} 115 116// ListResult subscription list operation response. 117type ListResult struct { 118 autorest.Response `json:"-"` 119 // Value - An array of subscriptions. 120 Value *[]Model `json:"value,omitempty"` 121 // NextLink - The URL to get the next set of results. 122 NextLink *string `json:"nextLink,omitempty"` 123} 124 125// ListResultIterator provides access to a complete listing of Model values. 126type ListResultIterator struct { 127 i int 128 page ListResultPage 129} 130 131// NextWithContext advances to the next value. If there was an error making 132// the request the iterator does not advance and the error is returned. 133func (iter *ListResultIterator) NextWithContext(ctx context.Context) (err error) { 134 if tracing.IsEnabled() { 135 ctx = tracing.StartSpan(ctx, fqdn+"/ListResultIterator.NextWithContext") 136 defer func() { 137 sc := -1 138 if iter.Response().Response.Response != nil { 139 sc = iter.Response().Response.Response.StatusCode 140 } 141 tracing.EndSpan(ctx, sc, err) 142 }() 143 } 144 iter.i++ 145 if iter.i < len(iter.page.Values()) { 146 return nil 147 } 148 err = iter.page.NextWithContext(ctx) 149 if err != nil { 150 iter.i-- 151 return err 152 } 153 iter.i = 0 154 return nil 155} 156 157// Next advances to the next value. If there was an error making 158// the request the iterator does not advance and the error is returned. 159// Deprecated: Use NextWithContext() instead. 160func (iter *ListResultIterator) Next() error { 161 return iter.NextWithContext(context.Background()) 162} 163 164// NotDone returns true if the enumeration should be started or is not yet complete. 165func (iter ListResultIterator) NotDone() bool { 166 return iter.page.NotDone() && iter.i < len(iter.page.Values()) 167} 168 169// Response returns the raw server response from the last page request. 170func (iter ListResultIterator) Response() ListResult { 171 return iter.page.Response() 172} 173 174// Value returns the current value or a zero-initialized value if the 175// iterator has advanced beyond the end of the collection. 176func (iter ListResultIterator) Value() Model { 177 if !iter.page.NotDone() { 178 return Model{} 179 } 180 return iter.page.Values()[iter.i] 181} 182 183// Creates a new instance of the ListResultIterator type. 184func NewListResultIterator(page ListResultPage) ListResultIterator { 185 return ListResultIterator{page: page} 186} 187 188// IsEmpty returns true if the ListResult contains no values. 189func (lr ListResult) IsEmpty() bool { 190 return lr.Value == nil || len(*lr.Value) == 0 191} 192 193// hasNextLink returns true if the NextLink is not empty. 194func (lr ListResult) hasNextLink() bool { 195 return lr.NextLink != nil && len(*lr.NextLink) != 0 196} 197 198// listResultPreparer prepares a request to retrieve the next set of results. 199// It returns nil if no more results exist. 200func (lr ListResult) listResultPreparer(ctx context.Context) (*http.Request, error) { 201 if !lr.hasNextLink() { 202 return nil, nil 203 } 204 return autorest.Prepare((&http.Request{}).WithContext(ctx), 205 autorest.AsJSON(), 206 autorest.AsGet(), 207 autorest.WithBaseURL(to.String(lr.NextLink))) 208} 209 210// ListResultPage contains a page of Model values. 211type ListResultPage struct { 212 fn func(context.Context, ListResult) (ListResult, error) 213 lr ListResult 214} 215 216// NextWithContext advances to the next page of values. If there was an error making 217// the request the page does not advance and the error is returned. 218func (page *ListResultPage) NextWithContext(ctx context.Context) (err error) { 219 if tracing.IsEnabled() { 220 ctx = tracing.StartSpan(ctx, fqdn+"/ListResultPage.NextWithContext") 221 defer func() { 222 sc := -1 223 if page.Response().Response.Response != nil { 224 sc = page.Response().Response.Response.StatusCode 225 } 226 tracing.EndSpan(ctx, sc, err) 227 }() 228 } 229 for { 230 next, err := page.fn(ctx, page.lr) 231 if err != nil { 232 return err 233 } 234 page.lr = next 235 if !next.hasNextLink() || !next.IsEmpty() { 236 break 237 } 238 } 239 return nil 240} 241 242// Next advances to the next page of values. If there was an error making 243// the request the page does not advance and the error is returned. 244// Deprecated: Use NextWithContext() instead. 245func (page *ListResultPage) Next() error { 246 return page.NextWithContext(context.Background()) 247} 248 249// NotDone returns true if the page enumeration should be started or is not yet complete. 250func (page ListResultPage) NotDone() bool { 251 return !page.lr.IsEmpty() 252} 253 254// Response returns the raw server response from the last page request. 255func (page ListResultPage) Response() ListResult { 256 return page.lr 257} 258 259// Values returns the slice of values for the current page or nil if there are no values. 260func (page ListResultPage) Values() []Model { 261 if page.lr.IsEmpty() { 262 return nil 263 } 264 return *page.lr.Value 265} 266 267// Creates a new instance of the ListResultPage type. 268func NewListResultPage(cur ListResult, getNextPage func(context.Context, ListResult) (ListResult, error)) ListResultPage { 269 return ListResultPage{ 270 fn: getNextPage, 271 lr: cur, 272 } 273} 274 275// Location location information. 276type Location struct { 277 // ID - READ-ONLY; The fully qualified ID of the location. For example, /subscriptions/00000000-0000-0000-0000-000000000000/locations/westus. 278 ID *string `json:"id,omitempty"` 279 // SubscriptionID - READ-ONLY; The subscription ID. 280 SubscriptionID *string `json:"subscriptionId,omitempty"` 281 // Name - READ-ONLY; The location name. 282 Name *string `json:"name,omitempty"` 283 // DisplayName - READ-ONLY; The display name of the location. 284 DisplayName *string `json:"displayName,omitempty"` 285 // Latitude - READ-ONLY; The latitude of the location. 286 Latitude *string `json:"latitude,omitempty"` 287 // Longitude - READ-ONLY; The longitude of the location. 288 Longitude *string `json:"longitude,omitempty"` 289} 290 291// MarshalJSON is the custom marshaler for Location. 292func (l Location) MarshalJSON() ([]byte, error) { 293 objectMap := make(map[string]interface{}) 294 return json.Marshal(objectMap) 295} 296 297// LocationListResult location list operation response. 298type LocationListResult struct { 299 autorest.Response `json:"-"` 300 // Value - An array of locations. 301 Value *[]Location `json:"value,omitempty"` 302} 303 304// Model subscription information. 305type Model struct { 306 autorest.Response `json:"-"` 307 // ID - READ-ONLY; The fully qualified ID for the subscription. For example, /subscriptions/00000000-0000-0000-0000-000000000000. 308 ID *string `json:"id,omitempty"` 309 // SubscriptionID - READ-ONLY; The subscription ID. 310 SubscriptionID *string `json:"subscriptionId,omitempty"` 311 // DisplayName - READ-ONLY; The subscription display name. 312 DisplayName *string `json:"displayName,omitempty"` 313 // State - READ-ONLY; The subscription state. Possible values are Enabled, Warned, PastDue, Disabled, and Deleted. Possible values include: 'Enabled', 'Warned', 'PastDue', 'Disabled', 'Deleted' 314 State State `json:"state,omitempty"` 315 // SubscriptionPolicies - The subscription policies. 316 SubscriptionPolicies *Policies `json:"subscriptionPolicies,omitempty"` 317 // AuthorizationSource - The authorization source of the request. Valid values are one or more combinations of Legacy, RoleBased, Bypassed, Direct and Management. For example, 'Legacy, RoleBased'. 318 AuthorizationSource *string `json:"authorizationSource,omitempty"` 319} 320 321// MarshalJSON is the custom marshaler for Model. 322func (mVar Model) MarshalJSON() ([]byte, error) { 323 objectMap := make(map[string]interface{}) 324 if mVar.SubscriptionPolicies != nil { 325 objectMap["subscriptionPolicies"] = mVar.SubscriptionPolicies 326 } 327 if mVar.AuthorizationSource != nil { 328 objectMap["authorizationSource"] = mVar.AuthorizationSource 329 } 330 return json.Marshal(objectMap) 331} 332 333// Operation status of the subscription POST operation. 334type Operation struct { 335 // ID - READ-ONLY; The operation Id. 336 ID *string `json:"id,omitempty"` 337 // Status - Status of the pending subscription 338 Status *string `json:"status,omitempty"` 339 // StatusDetail - Status Detail of the pending subscription 340 StatusDetail *string `json:"statusDetail,omitempty"` 341} 342 343// MarshalJSON is the custom marshaler for Operation. 344func (o Operation) MarshalJSON() ([]byte, error) { 345 objectMap := make(map[string]interface{}) 346 if o.Status != nil { 347 objectMap["status"] = o.Status 348 } 349 if o.StatusDetail != nil { 350 objectMap["statusDetail"] = o.StatusDetail 351 } 352 return json.Marshal(objectMap) 353} 354 355// OperationListResult a list of pending subscription operations. 356type OperationListResult struct { 357 autorest.Response `json:"-"` 358 // Value - A list of pending SubscriptionOperations 359 Value *[]Operation `json:"value,omitempty"` 360} 361 362// Policies subscription policies. 363type Policies struct { 364 // LocationPlacementID - READ-ONLY; The subscription location placement ID. The ID indicates which regions are visible for a subscription. For example, a subscription with a location placement Id of Public_2014-09-01 has access to Azure public regions. 365 LocationPlacementID *string `json:"locationPlacementId,omitempty"` 366 // QuotaID - READ-ONLY; The subscription quota ID. 367 QuotaID *string `json:"quotaId,omitempty"` 368 // SpendingLimit - READ-ONLY; The subscription spending limit. Possible values include: 'On', 'Off', 'CurrentPeriodOff' 369 SpendingLimit SpendingLimit `json:"spendingLimit,omitempty"` 370} 371 372// MarshalJSON is the custom marshaler for Policies. 373func (p Policies) MarshalJSON() ([]byte, error) { 374 objectMap := make(map[string]interface{}) 375 return json.Marshal(objectMap) 376} 377 378// TenantIDDescription tenant Id information. 379type TenantIDDescription struct { 380 // ID - READ-ONLY; The fully qualified ID of the tenant. For example, /tenants/00000000-0000-0000-0000-000000000000. 381 ID *string `json:"id,omitempty"` 382 // TenantID - READ-ONLY; The tenant ID. For example, 00000000-0000-0000-0000-000000000000. 383 TenantID *string `json:"tenantId,omitempty"` 384} 385 386// MarshalJSON is the custom marshaler for TenantIDDescription. 387func (tid TenantIDDescription) MarshalJSON() ([]byte, error) { 388 objectMap := make(map[string]interface{}) 389 return json.Marshal(objectMap) 390} 391 392// TenantListResult tenant Ids information. 393type TenantListResult struct { 394 autorest.Response `json:"-"` 395 // Value - An array of tenants. 396 Value *[]TenantIDDescription `json:"value,omitempty"` 397 // NextLink - The URL to use for getting the next set of results. 398 NextLink *string `json:"nextLink,omitempty"` 399} 400 401// TenantListResultIterator provides access to a complete listing of TenantIDDescription values. 402type TenantListResultIterator struct { 403 i int 404 page TenantListResultPage 405} 406 407// NextWithContext advances to the next value. If there was an error making 408// the request the iterator does not advance and the error is returned. 409func (iter *TenantListResultIterator) NextWithContext(ctx context.Context) (err error) { 410 if tracing.IsEnabled() { 411 ctx = tracing.StartSpan(ctx, fqdn+"/TenantListResultIterator.NextWithContext") 412 defer func() { 413 sc := -1 414 if iter.Response().Response.Response != nil { 415 sc = iter.Response().Response.Response.StatusCode 416 } 417 tracing.EndSpan(ctx, sc, err) 418 }() 419 } 420 iter.i++ 421 if iter.i < len(iter.page.Values()) { 422 return nil 423 } 424 err = iter.page.NextWithContext(ctx) 425 if err != nil { 426 iter.i-- 427 return err 428 } 429 iter.i = 0 430 return nil 431} 432 433// Next advances to the next value. If there was an error making 434// the request the iterator does not advance and the error is returned. 435// Deprecated: Use NextWithContext() instead. 436func (iter *TenantListResultIterator) Next() error { 437 return iter.NextWithContext(context.Background()) 438} 439 440// NotDone returns true if the enumeration should be started or is not yet complete. 441func (iter TenantListResultIterator) NotDone() bool { 442 return iter.page.NotDone() && iter.i < len(iter.page.Values()) 443} 444 445// Response returns the raw server response from the last page request. 446func (iter TenantListResultIterator) Response() TenantListResult { 447 return iter.page.Response() 448} 449 450// Value returns the current value or a zero-initialized value if the 451// iterator has advanced beyond the end of the collection. 452func (iter TenantListResultIterator) Value() TenantIDDescription { 453 if !iter.page.NotDone() { 454 return TenantIDDescription{} 455 } 456 return iter.page.Values()[iter.i] 457} 458 459// Creates a new instance of the TenantListResultIterator type. 460func NewTenantListResultIterator(page TenantListResultPage) TenantListResultIterator { 461 return TenantListResultIterator{page: page} 462} 463 464// IsEmpty returns true if the ListResult contains no values. 465func (tlr TenantListResult) IsEmpty() bool { 466 return tlr.Value == nil || len(*tlr.Value) == 0 467} 468 469// hasNextLink returns true if the NextLink is not empty. 470func (tlr TenantListResult) hasNextLink() bool { 471 return tlr.NextLink != nil && len(*tlr.NextLink) != 0 472} 473 474// tenantListResultPreparer prepares a request to retrieve the next set of results. 475// It returns nil if no more results exist. 476func (tlr TenantListResult) tenantListResultPreparer(ctx context.Context) (*http.Request, error) { 477 if !tlr.hasNextLink() { 478 return nil, nil 479 } 480 return autorest.Prepare((&http.Request{}).WithContext(ctx), 481 autorest.AsJSON(), 482 autorest.AsGet(), 483 autorest.WithBaseURL(to.String(tlr.NextLink))) 484} 485 486// TenantListResultPage contains a page of TenantIDDescription values. 487type TenantListResultPage struct { 488 fn func(context.Context, TenantListResult) (TenantListResult, error) 489 tlr TenantListResult 490} 491 492// NextWithContext advances to the next page of values. If there was an error making 493// the request the page does not advance and the error is returned. 494func (page *TenantListResultPage) NextWithContext(ctx context.Context) (err error) { 495 if tracing.IsEnabled() { 496 ctx = tracing.StartSpan(ctx, fqdn+"/TenantListResultPage.NextWithContext") 497 defer func() { 498 sc := -1 499 if page.Response().Response.Response != nil { 500 sc = page.Response().Response.Response.StatusCode 501 } 502 tracing.EndSpan(ctx, sc, err) 503 }() 504 } 505 for { 506 next, err := page.fn(ctx, page.tlr) 507 if err != nil { 508 return err 509 } 510 page.tlr = next 511 if !next.hasNextLink() || !next.IsEmpty() { 512 break 513 } 514 } 515 return nil 516} 517 518// Next advances to the next page of values. If there was an error making 519// the request the page does not advance and the error is returned. 520// Deprecated: Use NextWithContext() instead. 521func (page *TenantListResultPage) Next() error { 522 return page.NextWithContext(context.Background()) 523} 524 525// NotDone returns true if the page enumeration should be started or is not yet complete. 526func (page TenantListResultPage) NotDone() bool { 527 return !page.tlr.IsEmpty() 528} 529 530// Response returns the raw server response from the last page request. 531func (page TenantListResultPage) Response() TenantListResult { 532 return page.tlr 533} 534 535// Values returns the slice of values for the current page or nil if there are no values. 536func (page TenantListResultPage) Values() []TenantIDDescription { 537 if page.tlr.IsEmpty() { 538 return nil 539 } 540 return *page.tlr.Value 541} 542 543// Creates a new instance of the TenantListResultPage type. 544func NewTenantListResultPage(cur TenantListResult, getNextPage func(context.Context, TenantListResult) (TenantListResult, error)) TenantListResultPage { 545 return TenantListResultPage{ 546 fn: getNextPage, 547 tlr: cur, 548 } 549} 550