private static PSParameterValueBase GetAssignmentParameters(KeyValuePair <string, ParameterValueBase> parameterKvp) { PSParameterValueBase parameter = null; if (parameterKvp.Value != null && parameterKvp.Value is ParameterValue) { // Need to cast as ParameterValue since assignment.Parameters value type is ParameterValueBase. var parameterValue = (ParameterValue)parameterKvp.Value; parameter = new PSParameterValue { Description = parameterValue.Description, Value = parameterValue.Value }; } else if (parameterKvp.Value != null && parameterKvp.Value is SecretReferenceParameterValue) { var parameterValue = (SecretReferenceParameterValue)parameterKvp.Value; var secretReference = new PSSecretValueReference { KeyVault = new PSKeyVaultReference { Id = parameterValue.Reference.KeyVault.Id }, SecretName = parameterValue.Reference.SecretName, SecretVersion = parameterValue.Reference.SecretVersion }; parameter = new PSSecretReferenceParameterValue { Reference = secretReference, Description = parameterValue.Description }; } return(parameter); }
internal static PSPolicyAssignmentArtifact FromArtifactModel(PolicyAssignmentArtifact artifact, string scope) { var psArtifact = new PSPolicyAssignmentArtifact { Id = artifact.Id, Type = artifact.Type, Name = artifact.Name, DisplayName = artifact.DisplayName, Description = artifact.Description, PolicyDefinitionId = artifact.PolicyDefinitionId, DependsOn = new List <string>(), Parameters = new Dictionary <string, PSParameterValueBase>(), ResourceGroup = artifact.ResourceGroup }; foreach (var item in artifact.Parameters) { PSParameterValueBase parameter = GetArtifactParameters(item); psArtifact.Parameters.Add(item.Key, parameter); } psArtifact.DependsOn = artifact.DependsOn?.ToList(); return(psArtifact); }
internal static PSTemplateArtifact FromArtifactModel(TemplateArtifact artifact, string scope) { var psArtifact = new PSTemplateArtifact { Id = artifact.Id, Type = artifact.Type, Name = artifact.Name, DisplayName = artifact.DisplayName, Description = artifact.Description, DependsOn = new List <string>(), Template = artifact.Template, Parameters = new Dictionary <string, PSParameterValueBase>(), ResourceGroup = artifact.ResourceGroup }; foreach (var item in artifact.Parameters) { PSParameterValueBase parameter = GetArtifactParameters(item); psArtifact.Parameters.Add(item.Key, parameter); } psArtifact.DependsOn = artifact.DependsOn.Select(x => x) as List <string>; return(psArtifact); }
private static PSParameterValueBase GetArtifactParameters(KeyValuePair <string, ParameterValueBase> parameterKvp) { PSParameterValueBase parameter = null; if (parameterKvp.Value != null && parameterKvp.Value is ParameterValue) { // Need to cast as ParameterValue since assignment.Parameters value type is ParameterValueBase. var parameterValue = (ParameterValue)parameterKvp.Value; parameter = new PSParameterValue { Description = parameterValue.Description, Value = parameterValue.Value }; } return(parameter); }
/// <summary> /// Create a PSBluprintAssignment object from an Assignment model. /// </summary> /// <param name="assignment">Assignment object from which to create the PSBlueprintAssignment.</param> /// <param name="subscriptionId">ID of the subscription the assignment is associated with.</param> /// <returns>A new PSBlueprintAssignment object.</returns> internal static PSBlueprintAssignment FromAssignment(Assignment assignment, string scope) { var psAssignment = new PSBlueprintAssignment { Name = assignment.Name, Id = assignment.Id, Type = assignment.Type, Location = assignment.Location, Scope = scope, Identity = new PSManagedServiceIdentity { PrincipalId = assignment.Identity.PrincipalId, TenantId = assignment.Identity.TenantId, Type = assignment.Type, UserAssignedIdentities = new Dictionary <string, PSUserAssignedIdentity>() }, DisplayName = assignment.DisplayName, Description = assignment.Description, BlueprintId = assignment.BlueprintId, ProvisioningState = PSAssignmentProvisioningState.Unknown, Status = new PSAssignmentStatus(), Locks = new PSAssignmentLockSettings { Mode = PSLockMode.None }, Parameters = new Dictionary <string, PSParameterValueBase>(), ResourceGroups = new Dictionary <string, PSResourceGroupValue>() }; psAssignment.Status.TimeCreated = assignment.Status.TimeCreated; psAssignment.Status.LastModified = assignment.Status.LastModified; if (Enum.TryParse(assignment.ProvisioningState, true, out PSAssignmentProvisioningState state)) { psAssignment.ProvisioningState = state; } else { psAssignment.ProvisioningState = PSAssignmentProvisioningState.Unknown; } if (Enum.TryParse(assignment.Locks.Mode, true, out PSLockMode lockMode)) { psAssignment.Locks.Mode = lockMode; } else { psAssignment.Locks.Mode = PSLockMode.None; } foreach (var item in assignment.Parameters) { PSParameterValueBase parameter = GetAssignmentParameters(item); psAssignment.Parameters.Add(item.Key, parameter); } foreach (var item in assignment.ResourceGroups) { psAssignment.ResourceGroups.Add(item.Key, new PSResourceGroupValue { Name = item.Value.Name, Location = item.Value.Location }); } if (assignment.Identity.UserAssignedIdentities != null) { foreach (var item in assignment.Identity.UserAssignedIdentities) { psAssignment.Identity.UserAssignedIdentities.Add(item.Key, new PSUserAssignedIdentity { ClientId = item.Value.ClientId, PrincipalId = item.Value.PrincipalId }); } } return(psAssignment); }