private static void InitVMIdentity(VirtualMachineInner vmInner, ResourceIdentityType identityType) { if (!identityType.Equals(ResourceIdentityType.UserAssigned) && !identityType.Equals(ResourceIdentityType.SystemAssigned)) { throw new ArgumentException("Invalid argument: " + identityType); } if (vmInner.Identity == null) { vmInner.Identity = new VirtualMachineIdentity(); } ResourceIdentityType?parsedIdentityType = vmInner.Identity.Type; if (parsedIdentityType == null || parsedIdentityType.Equals(ResourceIdentityType.None) || parsedIdentityType.Equals(identityType)) { vmInner.Identity.Type = identityType; } else { vmInner.Identity.Type = ResourceIdentityType.SystemAssignedUserAssigned; } if (vmInner.Identity.IdentityIds == null) { if (identityType.Equals(ResourceIdentityType.UserAssigned) || identityType.Equals(ResourceIdentityType.SystemAssignedUserAssigned)) { vmInner.Identity.IdentityIds = new List <string>(); } } }
/// <summary> /// Initializes a new instance of the ConnectedClusterIdentity class. /// </summary> /// <param name="type">The type of identity used for the connected /// cluster. The type 'SystemAssigned, includes a system created /// identity. The type 'None' means no identity is assigned to the /// connected cluster. Possible values include: 'None', /// 'SystemAssigned'</param> /// <param name="principalId">The principal id of connected cluster /// identity. This property will only be provided for a system assigned /// identity.</param> /// <param name="tenantId">The tenant id associated with the connected /// cluster. This property will only be provided for a system assigned /// identity.</param> public ConnectedClusterIdentity(ResourceIdentityType type, string principalId = default(string), string tenantId = default(string)) { PrincipalId = principalId; TenantId = tenantId; Type = type; CustomInit(); }
private void InitContainerGroupIdentity(ResourceIdentityType identityType) { if (identityType != ResourceIdentityType.UserAssigned && identityType != ResourceIdentityType.SystemAssigned) { throw new ArgumentException("Invalid argument: " + identityType); } ContainerGroupInner containerGroupInner = this.containerGroup.Inner; if (containerGroupInner.Identity == null) { containerGroupInner.Identity = new ContainerGroupIdentity(); } if (containerGroupInner.Identity.Type == null || containerGroupInner.Identity.Type == ResourceIdentityType.None || containerGroupInner.Identity.Type == identityType) { containerGroupInner.Identity.Type = identityType; } else { containerGroupInner.Identity.Type = ResourceIdentityType.SystemAssignedUserAssigned; } }
/// <summary> /// Initializes a new instance of the ResourceIdentity class. /// </summary> /// <param name="type">String of the resource identity type. Possible /// values include: 'None', 'SystemAssigned'</param> /// <param name="principalId">GUID that represents the principal ID of /// this resource identity.</param> /// <param name="tenantId">GUID that represents the tenant ID of this /// resource identity.</param> public ResourceIdentity(ResourceIdentityType type, string principalId = default(string), string tenantId = default(string)) { Type = type; PrincipalId = principalId; TenantId = tenantId; CustomInit(); }
/// <summary> /// Initialize VMSS's identity property. /// </summary> /// <param name="identityType">The identity type to set.</param> private void InitVMSSIdentity(ResourceIdentityType identityType) { if (!identityType.Equals(ResourceIdentityType.UserAssigned) && !identityType.Equals(ResourceIdentityType.SystemAssigned)) { throw new ArgumentException("Invalid argument: " + identityType); } var scaleSetInner = this.scaleSet.Inner; if (scaleSetInner.Identity == null) { scaleSetInner.Identity = new VirtualMachineScaleSetIdentity(); } if (scaleSetInner.Identity.Type == null || scaleSetInner.Identity.Type.Equals(ResourceIdentityType.None) || scaleSetInner.Identity.Type.Equals(identityType)) { scaleSetInner.Identity.Type = identityType; } else { scaleSetInner.Identity.Type = ResourceIdentityType.SystemAssignedUserAssigned; } }
/// <summary> /// Initialize VMSS's identity property. /// </summary> /// <param name="identityType">The identity type to set.</param> private void InitVMSSIdentity(ResourceIdentityType identityType) { if (!identityType.Equals(ResourceIdentityType.UserAssigned) && !identityType.Equals(ResourceIdentityType.SystemAssigned)) { throw new ArgumentException("Invalid argument: " + identityType); } var scaleSetInner = this.scaleSet.Inner; if (scaleSetInner.Identity == null) { scaleSetInner.Identity = new VirtualMachineScaleSetIdentity(); } if (scaleSetInner.Identity.Type == null || scaleSetInner.Identity.Type.Equals(ResourceIdentityTypeEnumExtension.ToSerializedValue(ResourceIdentityType.None), StringComparison.OrdinalIgnoreCase) || scaleSetInner.Identity.Type.Equals(ResourceIdentityTypeEnumExtension.ToSerializedValue(identityType), StringComparison.OrdinalIgnoreCase)) { scaleSetInner.Identity.Type = ResourceIdentityTypeEnumExtension.ToSerializedValue(identityType); } else { scaleSetInner.Identity.Type = ResourceIdentityTypeEnumExtension.ToSerializedValue(ResourceIdentityType.SystemAssignedUserAssigned); } }
private static void InitVMIdentity(VirtualMachineScaleSetInner vmssInner, ResourceIdentityType identityType) { if (!identityType.Equals(ResourceIdentityType.UserAssigned) && !identityType.Equals(ResourceIdentityType.SystemAssigned)) { throw new ArgumentException("Invalid argument: " + identityType); } if (vmssInner.Identity == null) { vmssInner.Identity = new VirtualMachineScaleSetIdentity(); } ResourceIdentityType?parsedIdentityType = ResourceIdentityTypeEnumExtension.ParseResourceIdentityType(vmssInner.Identity.Type); if (parsedIdentityType == null || parsedIdentityType.Equals(ResourceIdentityType.None) || parsedIdentityType.Equals(identityType)) { vmssInner.Identity.Type = ResourceIdentityTypeEnumExtension.ToSerializedValue(identityType); } else { vmssInner.Identity.Type = ResourceIdentityTypeEnumExtension.ToSerializedValue(ResourceIdentityType.SystemAssignedUserAssigned); } if (vmssInner.Identity.IdentityIds == null) { if (identityType.Equals(ResourceIdentityType.UserAssigned) || identityType.Equals(ResourceIdentityType.SystemAssignedUserAssigned)) { vmssInner.Identity.IdentityIds = new List <string>(); } } }
/// <summary> /// Initializes a new instance of the BatchAccountIdentity class. /// </summary> /// <param name="type">The type of identity used for the Batch account. /// Possible values include: 'SystemAssigned', 'UserAssigned', /// 'None'</param> /// <param name="principalId">The principal id of the Batch account. /// This property will only be provided for a system assigned /// identity.</param> /// <param name="tenantId">The tenant id associated with the Batch /// account. This property will only be provided for a system assigned /// identity.</param> /// <param name="userAssignedIdentities">The list of user identities /// associated with the Batch account. The user identity dictionary key /// references will be ARM resource ids in the form: /// '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'.</param> public BatchAccountIdentity(ResourceIdentityType type, string principalId = default(string), string tenantId = default(string), IDictionary <string, BatchAccountIdentityUserAssignedIdentitiesValue> userAssignedIdentities = default(IDictionary <string, BatchAccountIdentityUserAssignedIdentitiesValue>)) { PrincipalId = principalId; TenantId = tenantId; Type = type; UserAssignedIdentities = userAssignedIdentities; CustomInit(); }
internal static string ToSerializedValue(this ResourceIdentityType value) { switch (value) { case ResourceIdentityType.SystemAssigned: return("SystemAssigned"); } return(null); }
/// <summary> /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider" /// /> and <see cref="ignoreCase" /> /// </summary> /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param> /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param> /// <param name="formatProvider">not used by this TypeConverter.</param> /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param> /// <returns> /// an instance of <see cref="ResourceIdentityType" />, or <c>null</c> if there is no suitable conversion. /// </returns> public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => ResourceIdentityType.CreateFrom(sourceValue);
public static string ToSerialString(this ResourceIdentityType value) => value switch {
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); RunCmdLet(() => { var properties = new AccountProperties(); if (!string.IsNullOrWhiteSpace(CustomSubdomainName)) { properties.CustomSubDomainName = CustomSubdomainName; } if (NetworkRuleSet != null) { properties.NetworkAcls = NetworkRuleSet.ToNetworkRuleSet(); } if (ApiProperty != null) { properties.ApiProperties = ApiProperty; } var createParameters = new Account() { Location = Location, Kind = Type, // must have value, mandatory parameter Sku = new Sku(SkuName, null), Tags = TagsConversionHelper.CreateTagDictionary(Tag), Properties = properties }; if (!string.IsNullOrEmpty(PublicNetworkAccess)) { createParameters.Properties.PublicNetworkAccess = PublicNetworkAccess; } if (DisableLocalAuth != null) { createParameters.Properties.DisableLocalAuth = DisableLocalAuth; } if (RestrictOutboundNetworkAccess != null) { createParameters.Properties.RestrictOutboundNetworkAccess = RestrictOutboundNetworkAccess; } if (AllowedFqdnList != null) { createParameters.Properties.AllowedFqdnList = AllowedFqdnList; } if (AssignIdentity.IsPresent || this.UserAssignedIdentityId != null || this.IdentityType != null) { ResourceIdentityType resourceIdentityType = ResourceIdentityType.SystemAssigned; if (this.IdentityType == null || !Enum.TryParse(this.IdentityType.ToString(), out resourceIdentityType)) { resourceIdentityType = ResourceIdentityType.SystemAssigned; } createParameters.Identity = new Identity(resourceIdentityType); if (this.UserAssignedIdentityId != null) { createParameters.Identity.UserAssignedIdentities = new Dictionary <string, UserAssignedIdentity>(); foreach (var userAssignedIdentityId in this.UserAssignedIdentityId) { createParameters.Identity.UserAssignedIdentities.Add(userAssignedIdentityId, new UserAssignedIdentity()); } } } if (CognitiveServicesEncryption.IsPresent) { createParameters.Properties.Encryption = new Encryption(null, KeySource.MicrosoftCognitiveServices); } if (ParameterSetName == KeyVaultEncryptionParameterSet) { createParameters.Properties.Encryption = new Encryption( new KeyVaultProperties() { KeyName = KeyName, KeyVersion = KeyVersion, KeyVaultUri = KeyVaultUri, IdentityClientId = KeyVaultIdentityClientId }, KeySource.MicrosoftKeyVault); } if (StorageAccountId != null && StorageAccountId.Length > 0) { createParameters.Properties.UserOwnedStorage = new List <UserOwnedStorage>(); foreach (var storageAccountId in StorageAccountId) { createParameters.Properties.UserOwnedStorage.Add(new UserOwnedStorage(storageAccountId)); } } if (ShouldProcess( Name, string.Format(CultureInfo.CurrentCulture, Resources.NewAccount_ProcessMessage, Name, Type, SkuName, Location))) { if (Type.StartsWith("Bing.", StringComparison.InvariantCultureIgnoreCase)) { if (Force.IsPresent) { WriteWarning(Resources.NewAccount_Notice); } else { bool yesToAll = false, noToAll = false; if (!ShouldContinue(Resources.NewAccount_Notice, "Notice", true, ref yesToAll, ref noToAll)) { return; } } } if (Type.Equals("Face", StringComparison.InvariantCultureIgnoreCase) || Type.Equals("CognitiveServices", StringComparison.InvariantCultureIgnoreCase)) { if (Force.IsPresent) { WriteWarning(Resources.NewAccount_LegalTerm_NotPolice); } else { bool yesToAll = false, noToAll = false; if (!ShouldContinue(Resources.NewAccount_LegalTerm_NotPolice, "Notice", true, ref yesToAll, ref noToAll)) { return; } } } var createAccountResponse = CognitiveServicesClient.Accounts.Create( ResourceGroupName, Name, createParameters); var cognitiveServicesAccount = CognitiveServicesClient.Accounts.Get(ResourceGroupName, Name); WriteCognitiveServicesAccount(cognitiveServicesAccount); } }); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); var properties = new AccountProperties(); if (!string.IsNullOrWhiteSpace(CustomSubdomainName)) { properties.CustomSubDomainName = CustomSubdomainName; } if (NetworkRuleSet != null) { properties.NetworkAcls = NetworkRuleSet.ToNetworkRuleSet(); } if (ApiProperty != null) { properties.ApiProperties = ApiProperty; } Sku sku = null; if (!string.IsNullOrWhiteSpace(this.SkuName)) { sku = new Sku(this.SkuName); } Dictionary <string, string> tags = null; if (this.Tag != null) { Dictionary <string, string> tagDictionary = TagsConversionHelper.CreateTagDictionary(Tag); tags = tagDictionary ?? new Dictionary <string, string>(); } Account updateParameters = new Account() { Sku = sku, Tags = tags, Properties = properties }; if (!string.IsNullOrEmpty(PublicNetworkAccess)) { updateParameters.Properties.PublicNetworkAccess = PublicNetworkAccess; } if (DisableLocalAuth != null) { updateParameters.Properties.DisableLocalAuth = DisableLocalAuth; } if (RestrictOutboundNetworkAccess != null) { updateParameters.Properties.RestrictOutboundNetworkAccess = RestrictOutboundNetworkAccess; } if (AllowedFqdnList != null) { updateParameters.Properties.AllowedFqdnList = AllowedFqdnList; } if (AssignIdentity.IsPresent || this.UserAssignedIdentityId != null || this.IdentityType != null) { ResourceIdentityType resourceIdentityType = ResourceIdentityType.SystemAssigned; if (this.IdentityType == null || !Enum.TryParse(this.IdentityType.ToString(), out resourceIdentityType)) { resourceIdentityType = ResourceIdentityType.SystemAssigned; } if (this.UserAssignedIdentityId != null && resourceIdentityType == ResourceIdentityType.SystemAssigned) { resourceIdentityType = ResourceIdentityType.SystemAssignedUserAssigned; } updateParameters.Identity = new Identity(resourceIdentityType); if (this.UserAssignedIdentityId != null) { updateParameters.Identity.UserAssignedIdentities = new Dictionary <string, UserAssignedIdentity>(); foreach (var userAssignedIdentityId in this.UserAssignedIdentityId) { updateParameters.Identity.UserAssignedIdentities.Add(userAssignedIdentityId, new UserAssignedIdentity()); } } } if (CognitiveServicesEncryption.IsPresent) { updateParameters.Properties.Encryption = new Encryption(null, KeySource.MicrosoftCognitiveServices); } if (ParameterSetName == KeyVaultEncryptionParameterSet) { updateParameters.Properties.Encryption = new Encryption( new KeyVaultProperties() { KeyName = KeyName, KeyVersion = KeyVersion, KeyVaultUri = KeyVaultUri, IdentityClientId = KeyVaultIdentityClientId }, KeySource.MicrosoftKeyVault); } if (StorageAccountId != null && StorageAccountId.Length > 0) { updateParameters.Properties.UserOwnedStorage = new List <UserOwnedStorage>(); foreach (var storageAccountId in StorageAccountId) { updateParameters.Properties.UserOwnedStorage.Add(new UserOwnedStorage(storageAccountId)); } } string processMessage = string.Empty; if (sku != null && tags != null) { processMessage = string.Format(CultureInfo.CurrentCulture, Resources.SetAccount_ProcessMessage_UpdateSkuAndTags, this.Name, sku.Name); } else if (sku != null) { processMessage = string.Format(CultureInfo.CurrentCulture, Resources.SetAccount_ProcessMessage_UpdateSku, this.Name, sku.Name); } else if (tags != null) { processMessage = string.Format(CultureInfo.CurrentCulture, Resources.SetAccount_ProcessMessage_UpdateTags, this.Name); } else { processMessage = string.Format(CultureInfo.CurrentCulture, Resources.SetAccount_ProcessMessage, this.Name); } if (ShouldProcess( this.Name, processMessage) || Force.IsPresent) { RunCmdLet(() => { var updatedAccount = this.CognitiveServicesClient.Accounts.Update( this.ResourceGroupName, this.Name, updateParameters ); WriteCognitiveServicesAccount(updatedAccount); }); } }
public BatchAccountIdentity(ResourceIdentityType type, IDictionary <string, BatchAccountIdentityUserAssignedIdentitiesValue> userAssignedIdentities) : this(type, default(string), default(string), userAssignedIdentities.ToDictionary(k => k.Key, v => (UserAssignedIdentities)v.Value)) { // This constructor exists for legacy support. Do not add anything here. }
public BatchAccountIdentity(ResourceIdentityType type, IDictionary <string, UserAssignedIdentities> userAssignedIdentities) : this(type, default(string), default(string), userAssignedIdentities) { }
public BatchAccountIdentity(ResourceIdentityType type, string principalId = default(string), string tenantId = default(string), IDictionary <string, BatchAccountIdentityUserAssignedIdentitiesValue> userAssignedIdentities = default(IDictionary <string, BatchAccountIdentityUserAssignedIdentitiesValue>)) : this(type, principalId, tenantId, userAssignedIdentities as IDictionary <string, UserAssignedIdentities>) { }