protected string GetResourceGroupName(string vaultName) { var localResourcesClient = new PSResourceManagerModels.ResourcesClient(DefaultContext) { VerboseLogger = WriteVerboseWithTimestamp, ErrorLogger = WriteVerboseWithTimestamp, WarningLogger = WriteWarningWithTimestamp }; string rg = null; var resourcesByName = localResourcesClient.FilterResources( new PSResourceManagerModels.FilterResourcesOptions() { ResourceType = Constants.KeyVaultType }); if (resourcesByName != null && resourcesByName.Count > 0) { var vault = resourcesByName.FirstOrDefault( r => r.Name.Equals(vaultName, StringComparison.OrdinalIgnoreCase)); if (vault != null) { rg = new PSResourceManagerModels.ResourceIdentifier(vault.Id).ResourceGroupName; } } return(rg); }
public static PSResourceGroup ToPSResourceGroup(this ResourceGroup resourceGroup, ResourcesClient client) { List<PSResource> resources = client.FilterResources(new FilterResourcesOptions { ResourceGroup = resourceGroup.Name }) .Select(r => r.ToPSResource(client)).ToList(); return new PSResourceGroup() { ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, Resources = resources, ResourcesTable = ConstructResourcesTable(resources), ProvisioningState = resourceGroup.ProvisioningState }; }
public static PSResourceGroup ToPSResourceGroup(this ResourceGroup resourceGroup, ResourcesClient client) { List<PSResource> resources = client.FilterResources(new FilterResourcesOptions { ResourceGroup = resourceGroup.Name }) .Select(r => r.ToPSResource(client)).ToList(); return new PSResourceGroup { ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, Resources = resources, ProvisioningState = resourceGroup.ProvisioningState, Tags = TagsConversionHelper.CreateTagHashtable(resourceGroup.Tags), }; }
public static PSResource ToPSResource(this Resource resource, ResourcesClient client) { ResourceIdentifier identifier = new ResourceIdentifier(resource.Id); return new PSResource { Name = identifier.ResourceName, Location = resource.Location, ResourceType = identifier.ResourceType, ResourceGroupName = identifier.ResourceGroupName, ParentResource = identifier.ParentResource, Properties = JsonUtilities.DeserializeJson(resource.Properties), PropertiesText = resource.Properties, Tags = TagsConversionHelper.CreateTagHashtable(resource.Tags) }; }
public static PSResource ToPSResource(this Resource resource, ResourcesClient client) { ResourceIdentifier identifier = new ResourceIdentifier(resource.Id); return(new PSResource() { Name = identifier.ResourceName, Location = resource.Location, ResourceType = identifier.ResourceType, ResourceGroupName = identifier.ResourceGroupName, ParentResource = identifier.ParentResource, Properties = JsonUtilities.DeserializeJson(resource.Properties), PropertiesText = resource.Properties }); }
public static PSResource ToPSResource(this Resource resource, ResourcesClient client) { ResourceIdentifier identifier = new ResourceIdentifier(resource.Id); return(new PSResource { Name = identifier.ResourceName, Location = resource.Location, ResourceType = identifier.ResourceType, ResourceGroupName = identifier.ResourceGroupName, ParentResource = identifier.ParentResource, Properties = JsonUtilities.DeserializeJson(resource.Properties), PropertiesText = resource.Properties, Tags = TagsConversionHelper.CreateTagHashtable(resource.Tags) }); }
public static PSResource ToPSResource(this GenericResourceExtended resource, ResourcesClient client, bool minimal) { ResourceIdentifier identifier = new ResourceIdentifier(resource.Id); return new PSResource { Name = identifier.ResourceName, Location = resource.Location, ResourceType = identifier.ResourceType, ResourceGroupName = identifier.ResourceGroupName, ParentResource = identifier.ParentResource, Properties = JsonUtilities.DeserializeJson(resource.Properties), PropertiesText = resource.Properties, Tags = TagsConversionHelper.CreateTagHashtable(resource.Tags), Permissions = minimal ? null : client.GetResourcePermissions(identifier), ResourceId = identifier.ToString() }; }
public static PSResource ToPSResource(this GenericResource resource, ResourcesClient client, bool minimal) { var identifier = new ResourceIdentifier(resource.Id); return(new PSResource { Name = identifier.ResourceName, Location = resource.Location, ResourceType = identifier.ResourceType, ResourceGroupName = identifier.ResourceGroupName, ParentResource = identifier.ParentResource, Properties = JsonUtilities.DeserializeJson(resource.Properties?.ToString()), PropertiesText = resource.Properties?.ToString(), Tags = TagsConversionHelper.CreateTagHashtable(resource.Tags), Permissions = minimal ? null : client.GetResourcePermissions(identifier), ResourceId = identifier.ToString() }); }
public static PSResourceGroup ToPSResourceGroup(this ResourceGroupExtended resourceGroup, ResourcesClient client, bool detailed) { var result = new PSResourceGroup { ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, ProvisioningState = resourceGroup.ProvisioningState, Tags = TagsConversionHelper.CreateTagHashtable(resourceGroup.Tags), ResourceId = resourceGroup.Id }; if (detailed) { result.Resources = client.FilterResources(new FilterResourcesOptions { ResourceGroup = resourceGroup.Name }) .Select(r => r.ToPSResource(client, true)).ToList(); } return result; }
public ResourceClientTests() { resourceManagementClientMock = new Mock<IResourceManagementClient>(); authorizationManagementClientMock = new Mock<IAuthorizationManagementClient>(); deploymentsMock = new Mock<IDeploymentOperations>(); resourceGroupMock = new Mock<IResourceGroupOperations>(); resourceOperationsMock = new Mock<IResourceOperations>(); galleryTemplatesClientMock = new Mock<GalleryTemplatesClient>(); eventsClientMock = new Mock<IEventsClient>(); deploymentOperationsMock = new Mock<IDeploymentOperationOperations>(); eventDataOperationsMock = new Mock<IEventDataOperations>(); providersMock = new Mock<IProviderOperations>(); providersMock.Setup(f => f.ListAsync(null, new CancellationToken())) .Returns(Task.Factory.StartNew(() => new ProviderListResult { Providers = new List<Provider>() })); progressLoggerMock = new Mock<Action<string>>(); errorLoggerMock = new Mock<Action<string>>(); permissionOperationsMock = new Mock<IPermissionOperations>(); resourceManagementClientMock.Setup(f => f.Deployments).Returns(deploymentsMock.Object); resourceManagementClientMock.Setup(f => f.ResourceGroups).Returns(resourceGroupMock.Object); resourceManagementClientMock.Setup(f => f.Resources).Returns(resourceOperationsMock.Object); resourceManagementClientMock.Setup(f => f.DeploymentOperations).Returns(deploymentOperationsMock.Object); resourceManagementClientMock.Setup(f => f.Providers).Returns(providersMock.Object); eventsClientMock.Setup(f => f.EventData).Returns(eventDataOperationsMock.Object); authorizationManagementClientMock.Setup(f => f.Permissions).Returns(permissionOperationsMock.Object); resourcesClient = new ResourcesClient( resourceManagementClientMock.Object, galleryTemplatesClientMock.Object, eventsClientMock.Object, authorizationManagementClientMock.Object) { VerboseLogger = progressLoggerMock.Object, ErrorLogger = errorLoggerMock.Object }; resourceIdentity = new ResourceIdentity { ParentResourcePath = "sites/siteA", ResourceName = "myResource", ResourceProviderNamespace = "Microsoft.Web", ResourceType = "sites" }; properties = new Dictionary<string, object> { {"name", "site1"}, {"siteMode", "Standard"}, {"computeMode", "Dedicated"}, {"misc", new Dictionary<string, object> { {"key1", "value1"}, {"key2", "value2"} }} }; serializedProperties = JsonConvert.SerializeObject(properties, new JsonSerializerSettings { TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple, TypeNameHandling = TypeNameHandling.None }); sampleEvents = new List<EventData>(); sampleEvents.Add(new EventData { EventDataId = "ac7d2ab5-698a-4c33-9c19-0a93d3d7f527", EventName = new LocalizableString { LocalizedValue = "Start request" }, EventSource = new LocalizableString { LocalizedValue = "Microsoft Resources" }, EventChannels = EventChannels.Operation, Level = EventLevel.Informational, EventTimestamp = DateTime.Now, OperationId = "c0f2e85f-efb0-47d0-bf90-f983ec8be91d", SubscriptionId = "c0f2e85f-efb0-47d0-bf90-f983ec8be91d", CorrelationId = "c0f2e85f-efb0-47d0-bf90-f983ec8be91d", OperationName = new LocalizableString { LocalizedValue = "Microsoft.Resources/subscriptions/resourcegroups/deployments/write" }, Status = new LocalizableString { LocalizedValue = "Succeeded" }, SubStatus = new LocalizableString { LocalizedValue = "Created" }, ResourceGroupName = "foo", ResourceProviderName = new LocalizableString { LocalizedValue = "Microsoft Resources" }, ResourceUri = "/subscriptions/ffce8037-a374-48bf-901d-dac4e3ea8c09/resourcegroups/foo/deployments/testdeploy", HttpRequest = new HttpRequestInfo { Uri = "http://path/subscriptions/ffce8037-a374-48bf-901d-dac4e3ea8c09/resourcegroups/foo/deployments/testdeploy", Method = "PUT", ClientRequestId = "1234", ClientIpAddress = "123.123.123.123" }, Authorization = new SenderAuthorization { Action = "PUT", Condition = "", Role = "Sender", Scope = "None" }, Claims = new Dictionary<string, string> { {"aud", "https://management.core.windows.net/"}, {"iss", "https://sts.windows.net/123456/"}, {"iat", "h123445"}, {"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name", "*****@*****.**"} }, Properties = new Dictionary<string, string>() }); sampleEvents.Add(new EventData { EventDataId = "ac7d2ab5-698a-4c33-9c19-0sdfsdf34r54", EventName = new LocalizableString { LocalizedValue = "End request" }, EventSource = new LocalizableString { LocalizedValue = "Microsoft Resources" }, EventChannels = EventChannels.Operation, Level = EventLevel.Informational, EventTimestamp = DateTime.Now, OperationId = "c0f2e85f-efb0-47d0-bf90-f983ec8be91d", OperationName = new LocalizableString { LocalizedValue = "Microsoft.Resources/subscriptions/resourcegroups/deployments/write" }, Status = new LocalizableString { LocalizedValue = "Succeeded" }, SubStatus = new LocalizableString { LocalizedValue = "Created" }, ResourceGroupName = "foo", ResourceProviderName = new LocalizableString { LocalizedValue = "Microsoft Resources" }, ResourceUri = "/subscriptions/ffce8037-a374-48bf-901d-dac4e3ea8c09/resourcegroups/foo/deployments/testdeploy", HttpRequest = new HttpRequestInfo { Uri = "http://path/subscriptions/ffce8037-a374-48bf-901d-dac4e3ea8c09/resourcegroups/foo/deployments/testdeploy", Method = "PUT", ClientRequestId = "1234", ClientIpAddress = "123.123.123.123" }, Authorization = new SenderAuthorization { Action = "PUT", Condition = "", Role = "Sender", Scope = "None" }, Claims = new Dictionary<string, string> { {"aud", "https://management.core.windows.net/"}, {"iss", "https://sts.windows.net/123456/"}, {"iat", "h123445"} }, Properties = new Dictionary<string, string>() }); }
internal static Certificate[] GetCertificates(ResourcesClient resourceClient, WebsitesClient websitesClient, string resourceGroupName, string thumbPrint) { var certificateResources = resourceClient.FilterPSResources(new BasePSResourceParameters() { ResourceType = "Microsoft.Web/Certificates" }).ToArray(); if (!string.IsNullOrEmpty(resourceGroupName)) { certificateResources = certificateResources.Where(c => string.Equals(c.ResourceGroupName, resourceGroupName, StringComparison.OrdinalIgnoreCase)).ToArray(); } var certificates = certificateResources.Select( certificateResource => websitesClient.GetCertificate(certificateResource.ResourceGroupName, certificateResource.Name)); if (!string.IsNullOrEmpty(thumbPrint)) { certificates = certificates.Where(c => string.Equals(c.Thumbprint, thumbPrint, StringComparison.OrdinalIgnoreCase)).ToList(); } return certificates.ToArray(); }
public static PSResourceGroup ToPSResourceGroup(this ResourceGroup resourceGroup, ResourcesClient client, bool detailed) { var result = new PSResourceGroup { ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, ProvisioningState = resourceGroup.ProvisioningState, Tags = TagsConversionHelper.CreateTagHashtable(resourceGroup.Tags), ResourceId = resourceGroup.Id }; if (detailed) { result.Resources = client.FilterResources(new FilterResourcesOptions { ResourceGroup = resourceGroup.Name }) .Select(r => r.ToPSResource(client, true)).ToList(); result.Permissions = client.GetResourceGroupPermissions(resourceGroup.Name); } return(result); }
public static PSResource ToPSResource(this Resource resource, ResourcesClient client) { ResourceIdentifier identifier = new ResourceIdentifier(resource.Id); return new PSResource() { Name = identifier.ResourceName, Location = resource.Location, ResourceType = identifier.ResourceType, ResourceGroupName = identifier.ResourceGroupName, ParentResource = identifier.ParentResource, Properties = JsonUtilities.DeserializeJson(resource.Properties), PropertiesText = resource.Properties }; }
public static PSResourceGroup ToPSResourceGroup(this ResourceGroup resourceGroup, ResourcesClient client) { List <PSResource> resources = client.FilterResources(new FilterResourcesOptions { ResourceGroup = resourceGroup.Name }) .Select(r => r.ToPSResource(client)).ToList(); return(new PSResourceGroup { ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, Resources = resources, ProvisioningState = resourceGroup.ProvisioningState, Tags = TagsConversionHelper.CreateTagHashtable(resourceGroup.Tags), }); }
public static PSResourceGroup ToPSResourceGroup(this ResourceGroup resourceGroup, ResourcesClient client) { List <PSResource> resources = client.FilterResources(new FilterResourcesOptions { ResourceGroup = resourceGroup.Name }) .Select(r => r.ToPSResource(client)).ToList(); return(new PSResourceGroup() { ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, Resources = resources, ResourcesTable = ConstructResourcesTable(resources), ProvisioningState = resourceGroup.ProvisioningState }); }