public void Standalone() { Assert.Equal( "/subscriptions/fe9ce53f-277c-48bb-950d-265eba922b9d/resourcegroups/rg1" + "/providers/Microsoft.Compute/virtualMachines/n111", ResourceIdHelper.CreateForStandaloneVm("fe9ce53f-277c-48bb-950d-265eba922b9d", "rg1", "n111").Id); }
public async Task <IEnumerable <Channel> > ListChannelsByAccountAsync( string requestId, string subscriptionId, string resourceGroupName, string accountName) { var channelNames = new[] { "MockChannel1", "MockChannel2" }; return(await Task.FromResult(channelNames.Select(channelName => new Channel { Id = ResourceIdHelper.GetChannelId(subscriptionId, resourceGroupName, accountName, channelName), Name = channelName, Type = NameStore.FullyQualifiedChannelResourceType, Properties = new ChannelProperties { Credentials = new Dictionary <string, string> { { "appId", "<appId>" }, { "appKey", string.Empty } } } }))); }
public async Task <Account> GetAccountAsync( string requestId, string subscriptionId, string resourceGroupName, string accountName) { var tenant = await this.tenantCacheClient.GetTenantAsync( requestId, subscriptionId, resourceGroupName, accountName); return(new Account { Id = ResourceIdHelper.GetAccountId( tenant.SubscriptionId, tenant.ResourceGroupName, tenant.AccountName), Name = tenant.AccountName, Type = NameStore.FullyQualifiedAccountResourceType, Location = tenant.Location, SKU = SkuStore.GetSKU(tenant.SKU), Tags = tenant.Tags }); }
public void Vmss() { Assert.Equal( "/subscriptions/fe9ce53f-277c-48bb-950d-265eba922b9d/resourcegroups/rg2/providers" + "/Microsoft.Compute/virtualMachineScaleSets/agents/virtualMachines/15", ResourceIdHelper.CreateForVmssVm("fe9ce53f-277c-48bb-950d-265eba922b9d", "rg2", "agents", "15").Id); }
public async Task <IEnumerable <Channel> > ListChannelsByAccountAsync( string requestId, string subscriptionId, string resourceGroupName, string accountName) { var tenant = await this.tenantCacheClient.GetTenantAsync( requestId, subscriptionId, resourceGroupName, accountName); return(tenant.TenantDescription.ChannelSettings.Select(channel => new Channel { Id = ResourceIdHelper.GetChannelId( subscriptionId, resourceGroupName, accountName, channel.Name), Name = channel.Name, Type = NameStore.FullyQualifiedChannelResourceType, Properties = new ChannelProperties { ChannelType = channel.Type, ChannelFunctions = channel.Functions, Credentials = MaskCredentials(channel.Type, channel.Credentials) } })); }
public async Task <Account> UpdateAccountAsync( string requestId, string subscriptionId, string resourceGroupName, string accountName, AccountPatch accountPatch) { await this.ValidateSubscriptionRegistration(subscriptionId); var paramTenant = new Tenant { SubscriptionId = subscriptionId, ResourceGroupName = resourceGroupName, AccountName = accountName, Tags = accountPatch.Tags ?? new Dictionary <string, string>(), State = TenantState.Active }; var tenant = await this.tenantCacheClient.UpdateTenantAsync( requestId, paramTenant); return(await Task.FromResult(new Account { Id = ResourceIdHelper.GetAccountId( tenant.SubscriptionId, tenant.ResourceGroupName, tenant.AccountName), Name = tenant.AccountName, Type = NameStore.FullyQualifiedAccountResourceType, Location = tenant.Location, SKU = SkuStore.GetSKU(tenant.SKU), Tags = tenant.Tags })); }
public async Task <Account> GetAccountAsync( string requestId, string subscriptionId, string resourceGroupName, string accountName) { return(await Task.FromResult(new Account { Id = ResourceIdHelper.GetAccountId(subscriptionId, resourceGroupName, accountName), Name = accountName, Type = NameStore.FullyQualifiedAccountResourceType, Location = "China North", SKU = SkuStore.B1 })); }
public static Meter TryCreate(string[] line) { var meter = CsvFileHelper.DeserializeLine <Meter>(line); var resourceType = ResourceIdHelper.GetResourceType(meter.ResourceId); if (resourceType == null) { meter = null; } else { meter.ResourceType = resourceType; } return(meter); }
public async Task <Account> CreateOrUpdateAccountAsync( string requestId, string subscriptionId, string resourceGroupName, string accountName, Account account) { return(await Task.FromResult(new Account { Id = ResourceIdHelper.GetAccountId(subscriptionId, resourceGroupName, accountName), Name = accountName, Type = NameStore.FullyQualifiedAccountResourceType, Location = account.Location, SKU = account.SKU, Tags = account.Tags })); }
public async Task <Channel> CreateOrUpdateChannelAsync( string requestId, string subscriptionId, string resourceGroupName, string accountName, string channelName, Channel channel) { await this.ValidateSubscriptionRegistration(subscriptionId); string message; if (!ValidateChannelName(channelName, out message)) { throw new InvalidArgumentException($"Invalid account name: {message}"); } var updated = await this.tenantCacheClient.CreateOrUpdateChannelAsync( requestId, subscriptionId, resourceGroupName, accountName, channelName, channel.Properties.ChannelType, channel.Properties.ChannelFunctions?.ToArray(), channel.Properties.Credentials); return(new Channel { Id = ResourceIdHelper.GetChannelId( subscriptionId, resourceGroupName, accountName, updated.Name), Name = updated.Name, Type = NameStore.FullyQualifiedChannelResourceType, Properties = new ChannelProperties { ChannelType = updated.Type, ChannelFunctions = updated.Functions, Credentials = MaskCredentials(updated.Type, updated.Credentials) } }); }
public async Task <IEnumerable <Account> > ListAccountsByResourceGroupAsync( string requestId, string subscriptionId, string resourceGroupName) { var accountNames = new[] { "MockAccount1", "MockAccount2" }; return(await Task.FromResult(accountNames.Select(accountName => new Account { Id = ResourceIdHelper.GetAccountId(subscriptionId, resourceGroupName, accountName), Name = accountName, Type = NameStore.FullyQualifiedAccountResourceType, Location = "China North", SKU = SkuStore.B1 }))); }
public async Task <IEnumerable <Account> > ListAccountsAsync( string requestId, string subscriptionId) { var tenants = await this.tenantCacheClient.ListTenantsAsync( requestId, subscriptionId); return(tenants.Select(tenant => new Account { Id = ResourceIdHelper.GetAccountId( tenant.SubscriptionId, tenant.ResourceGroupName, tenant.AccountName), Name = tenant.AccountName, Type = NameStore.FullyQualifiedAccountResourceType, Location = tenant.Location, SKU = SkuStore.GetSKU(tenant.SKU), Tags = tenant.Tags })); }
public async Task <Channel> GetChannelAsync( string requestId, string subscriptionId, string resourceGroupName, string accountName, string channelName) { return(await Task.FromResult(new Channel { Id = ResourceIdHelper.GetChannelId(subscriptionId, resourceGroupName, accountName, channelName), Name = channelName, Type = NameStore.FullyQualifiedChannelResourceType, Properties = new ChannelProperties { Credentials = new Dictionary <string, string> { { "appId", "<appId>" }, { "appKey", string.Empty } } } })); }
/// <summary> /// Executes the cmdlet to trigger a compliance scan /// </summary> public override void Execute() { var scanScope = string.IsNullOrEmpty(this.ResourceGroupName) ? ResourceIdHelper.GetSubscriptionScope(subscriptionId: this.DefaultContext.Subscription.Id) : ResourceIdHelper.GetResourceGroupScope(subscriptionId: this.DefaultContext.Subscription.Id, resourceGroupName: this.ResourceGroupName); if (this.ShouldProcess(target: scanScope, action: string.Format(CultureInfo.InvariantCulture, Resources.StartComplianceScan, scanScope))) { if (!string.IsNullOrEmpty(this.ResourceGroupName)) { this.PolicyInsightsClient.PolicyStates.TriggerResourceGroupEvaluation(subscriptionId: this.DefaultContext.Subscription.Id, resourceGroupName: this.ResourceGroupName); } else { this.PolicyInsightsClient.PolicyStates.TriggerSubscriptionEvaluation(subscriptionId: this.DefaultContext.Subscription.Id); } if (this.PassThru.IsPresent) { WriteObject(true); } } }
public async Task <Channel> GetChannelAsync( string requestId, string subscriptionId, string resourceGroupName, string accountName, string channelName) { var tenant = await this.tenantCacheClient.GetTenantAsync( requestId, subscriptionId, resourceGroupName, accountName); var channel = tenant.TenantDescription.ChannelSettings.SingleOrDefault(c => string.Equals(c.Name, channelName, StringComparison.OrdinalIgnoreCase)); if (channel == null) { throw new ResourceNotFoundException($"Can not find channel '{channelName}' in account '{accountName}'"); } return(new Channel { Id = ResourceIdHelper.GetChannelId( subscriptionId, resourceGroupName, accountName, channel.Name), Name = channel.Name, Type = NameStore.FullyQualifiedChannelResourceType, Properties = new ChannelProperties { ChannelType = channel.Type, ChannelFunctions = channel.Functions, Credentials = MaskCredentials(channel.Type, channel.Credentials) } }); }
public async Task <Account> CreateOrUpdateAccountAsync( string requestId, string subscriptionId, string resourceGroupName, string accountName, Account account) { await this.ValidateSubscriptionRegistration(subscriptionId); string message; if (!ValidateAccountName(accountName, out message)) { throw new InvalidArgumentException($"Invalid account name: {message}"); } var skuDescription = SkuStore.Descriptions.FirstOrDefault(description => string.Equals(description.Name, account.SKU.Name, StringComparison.OrdinalIgnoreCase)); if (skuDescription == null) { throw new InvalidArgumentException($"SKU {account.SKU.Name} is invalid. Supported SKUs are {string.Join(", ", SkuStore.Descriptions.Select(d => d.Name))}"); } var normalizedLocation = account.Location .Replace(" ", string.Empty) .ToLowerInvariant(); if (!skuDescription.Locations.Contains(normalizedLocation, StringComparer.OrdinalIgnoreCase)) { throw new InvalidArgumentException($"Location {account.Location} is invalid for SKU {account.SKU.Name}. Supported locations are {string.Join(", ", skuDescription.Locations)}"); } var sku = new SKU { Name = skuDescription.Name, Tier = skuDescription.Tier }; IReadOnlyDictionary <string, int> quotas; if (!SkuStore.Quotas.TryGetValue(skuDescription.Name, out quotas)) { quotas = new Dictionary <string, int>(); } var paramTenant = new Tenant { SubscriptionId = subscriptionId, ResourceGroupName = resourceGroupName, AccountName = accountName, Location = normalizedLocation, SKU = sku.Name, Tags = account.Tags ?? new Dictionary <string, string>(), State = TenantState.Active, ResourceId = ResourceIdHelper.GetAccountId( subscriptionId, resourceGroupName, accountName) }; var tenant = await this.tenantCacheClient.CreateOrUpdateTenantAsync( requestId, paramTenant, DefaultSASKeys.DefaultKeyNames.Select(name => new AuthenticationRule { KeyName = name, PrimaryKey = SASHelper.GenerateKey(DefaultSASKeys.DefaultKeyLength), SecondaryKey = SASHelper.GenerateKey(DefaultSASKeys.DefaultKeyLength), }).ToArray(), quotas.ToDictionary(pair => pair.Key, pair => pair.Value)); // Check subscription registration state to handle racing condition if (!await this.store.IsSubscriptionRegisteredAsync(subscriptionId)) { tenant.IsDisabled = true; await this.tenantCacheClient.UpdateTenantAsync( requestId, tenant); } return(await Task.FromResult(new Account { Id = ResourceIdHelper.GetAccountId( tenant.SubscriptionId, tenant.ResourceGroupName, tenant.AccountName), Name = tenant.AccountName, Type = NameStore.FullyQualifiedAccountResourceType, Location = tenant.Location, SKU = SkuStore.GetSKU(tenant.SKU), Tags = tenant.Tags })); }