/// <summary> /// Determines the API version. /// </summary> /// <param name="resourceId">The resource Id.</param> /// <param name="pre">When specified, indicates if pre-release API versions should be considered.</param> protected Task <string> DetermineApiVersion(string resourceId, bool?pre = null) { return(string.IsNullOrWhiteSpace(this.ApiVersion) ? ApiVersionHelper.DetermineApiVersion( profile: this.Profile, resourceId: resourceId, cancellationToken: this.CancellationToken.Value, pre: pre ?? this.Pre) : Task.FromResult(this.ApiVersion)); }
/// <summary> /// Determines the API version. /// </summary> /// <param name="resourceId">The resource Id.</param> /// <param name="pre">When specified, indicates if pre-release API versions should be considered.</param> protected Task <string> DetermineApiVersion(string resourceId, bool?pre = null) { return(string.IsNullOrWhiteSpace(this.ApiVersion) ? ApiVersionHelper.DetermineApiVersion( context: DefaultContext, resourceId: resourceId, cancellationToken: this.CancellationToken.Value, pre: pre ?? this.Pre, cmdletHeaderValues: this.GetCmdletHeaders()) : Task.FromResult(this.ApiVersion)); }
/// <summary> /// Populates the permissions on the resource. /// </summary> /// <param name="resource">The resource.</param> private async Task PopulatePermissions(PSObject resource) { try { var resourceId = resource.Properties["ResourceId"].Value.ToString(); var resourceCollectionId = resourceId + ResourceIdUtility .GetResourceCollectionId( subscriptionId: null, resourceGroupName: null, resourceType: null, extensionResourceType: "Microsoft.Authorization/permissions"); var apiVersion = await ApiVersionHelper .DetermineApiVersion( profile : this.Profile, providerNamespace : "Microsoft.Authorization", resourceType : "permissions", cancellationToken : this.CancellationToken.Value, pre : this.Pre) .ConfigureAwait(continueOnCapturedContext: false); var permissions = PaginatedResponseHelper.Enumerate( getFirstPage: () => this.GetPermissions(permissionCheckId: resourceCollectionId, apiVersion: apiVersion), getNextPage: nextLink => this.GetNextLink <Permission>(nextLink), cancellationToken: this.CancellationToken); resource.Properties.Add(new PSNoteProperty("Permissions", permissions)); } catch (Exception ex) { if (ex.IsFatal()) { throw; } ex = (ex is AggregateException) ? (ex as AggregateException).Flatten() : ex; this.errors.Add(new ErrorRecord(ex, "ErrorExpandingPermissions", ErrorCategory.CloseError, resource)); } }
/// <summary> /// Populates the properties of a single resource. /// </summary> /// <param name="resource">The resource.</param> private async Task <Resource <JToken> > GetPopulatedResource(Resource <JToken> resource) { try { var apiVersion = await ApiVersionHelper .DetermineApiVersion( profile : this.Profile, resourceId : resource.Id, cancellationToken : this.CancellationToken.Value, pre : this.Pre) .ConfigureAwait(continueOnCapturedContext: false); return(await this .GetResourcesClient() .GetResource <Resource <JToken> >( resourceId: resource.Id, apiVersion: apiVersion, cancellationToken: this.CancellationToken.Value) .ConfigureAwait(continueOnCapturedContext: false)); } catch (Exception ex) { if (ex.IsFatal()) { throw; } ex = (ex is AggregateException) ? (ex as AggregateException).Flatten() : ex; this.errors.Add(new ErrorRecord(ex, "ErrorExpandingProperties", ErrorCategory.CloseError, resource)); } return(resource); }