예제 #1
0
 public static PaintingMesh create(GameObject lObject, GenericResource<PaintingModelData> pResource)
 {
     PaintingMesh lOut = lObject.GetComponent<PaintingMesh>();
     lOut.modelResource = pResource;
     return lOut;
 }
 /// <summary>
 /// Create a resource.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Resources.IResourceOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group. The name is case
 /// insensitive.
 /// </param>
 /// <param name='identity'>
 /// Required. Resource identity.
 /// </param>
 /// <param name='parameters'>
 /// Required. Create or update resource parameters.
 /// </param>
 /// <returns>
 /// Resource information.
 /// </returns>
 public static Task<ResourceCreateOrUpdateResult> CreateOrUpdateAsync(this IResourceOperations operations, string resourceGroupName, ResourceIdentity identity, GenericResource parameters)
 {
     return operations.CreateOrUpdateAsync(resourceGroupName, identity, parameters, CancellationToken.None);
 }
        public void ResourceGetCreateOrUpdateDeleteAndExistsThrowExceptionWithoutApiVersion()
        {
            var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK };
            var client = GetResourceManagementClient(handler);

            var identity = new ResourceIdentity
            {
                ResourceName = "site3",
                ResourceProviderNamespace = "Microsoft.Web",
                ResourceProviderApiVersion = null,
                ResourceType = "sites",
            };

            var resource = new GenericResource
            {
                Location = "South Central US",
                Properties = @"{
                                'name':'site3',
	                            'siteMode': 'Standard',
                                'computeMode':'Dedicated'
                            }"
            };


            Assert.Throws<ArgumentNullException>(() => client.Resources.Get("foo",
                identity));
            Assert.Throws<ArgumentNullException>(() => client.Resources.CheckExistence("foo",
                identity));
            Assert.Throws<ArgumentNullException>(() => client.Resources.CreateOrUpdate("foo",
                identity, resource));
            Assert.Throws<ArgumentNullException>(() => client.Resources.Delete("foo",
                identity));
        }
 /// <summary>
 /// Create a resource.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Resources.IResourceOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group. The name is case
 /// insensitive.
 /// </param>
 /// <param name='identity'>
 /// Required. Resource identity.
 /// </param>
 /// <param name='parameters'>
 /// Required. Create or update resource parameters.
 /// </param>
 /// <returns>
 /// Resource information.
 /// </returns>
 public static ResourceCreateOrUpdateResult CreateOrUpdate(this IResourceOperations operations, string resourceGroupName, ResourceIdentity identity, GenericResource parameters)
 {
     return Task.Factory.StartNew((object s) =>
     {
         return ((IResourceOperations)s).CreateOrUpdateAsync(resourceGroupName, identity, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
예제 #5
0
        private static GenericResourceExtended CreateOrUpdateWebTest(
            ResourceManagementClient resourceClient, 
            string resourceGroupName, 
            string insightsResourceUri, 
            string webTestName, 
            string webTestUrl,
            string location)
        {
            string insightsResourceName = GetNameFromUri(insightsResourceUri);
            string webTestMonitorId = string.Format("{0}-{1}", webTestName, insightsResourceName);

            var webTestResourceIdentity = new ResourceIdentity(
                webTestMonitorId,
                "microsoft.insights/webtests",
                "2015-05-01");

            var webTestResource = new GenericResource(location)
            {
                Properties = new PingWebTestProperties
                {
                    Name = webTestName,
                    SyntheticMonitorId = webTestMonitorId,
                    Enabled = true,
                    Configuration = new PingWebTestConfiguration(webTestUrl),
                    Locations = { WebTestLocations.USSanAntonioTX },
                    RetryEnabled = true
                },
                Tags =
                {
                    { string.Format("hidden-link:{0}", insightsResourceUri), "Resource" }
                }
            };

            var webTestResourceCreateOrUpdateResult = resourceClient.Resources.CreateOrUpdateAsync(
                resourceGroupName,
                webTestResourceIdentity,
                webTestResource).Result;

            if (webTestResourceCreateOrUpdateResult.StatusCode != HttpStatusCode.Created && webTestResourceCreateOrUpdateResult.StatusCode != HttpStatusCode.OK)
            {
                throw new InvalidOperationException(
                    string.Format("Unable to create resource '{0}' (HTTP Status Code: {1}).",
                    insightsResourceName,
                    webTestResourceCreateOrUpdateResult.StatusCode));
            }

            return webTestResourceCreateOrUpdateResult.Resource;
        }
        public void TestGenericResourceWithNullPropertiesSerialization()
        {
            var sampleResource = new GenericResource()
            {
                Location = "EastUS"
            };
            sampleResource.Tags = new Dictionary<string, string>();
            sampleResource.Tags["tag1"] = "value1";
            var serializeSettings = new JsonSerializerSettings()
            {
                Formatting = Formatting.Indented,
                NullValueHandling = NullValueHandling.Ignore,
                ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
                ContractResolver = new ReadOnlyJsonContractResolver()
            };
            serializeSettings.Converters.Add(new ResourceJsonConverter());
            serializeSettings.Converters.Add(new PolymorphicSerializeJsonConverter<SampleResourceChild>("dType"));
            string json = JsonConvert.SerializeObject(sampleResource, serializeSettings);
            Assert.Equal(@"{
  ""location"": ""EastUS"",
  ""tags"": {
    ""tag1"": ""value1""
  }
}", json);

            var deserializeSettings = new JsonSerializerSettings()
            {
                Formatting = Formatting.Indented,
                NullValueHandling = NullValueHandling.Ignore,
                ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
                ContractResolver = new ReadOnlyJsonContractResolver()
            };
            deserializeSettings.Converters.Add(new ResourceJsonConverter());
            deserializeSettings.Converters.Add(new PolymorphicDeserializeJsonConverter<SampleResourceChild>("dType"));
            var deserializedResource = JsonConvert.DeserializeObject<GenericResource>(json, deserializeSettings);
            var jsonoverProcessed = JsonConvert.SerializeObject(deserializedResource, serializeSettings);

            Assert.Equal(json, jsonoverProcessed);
        }
        public async Task PrivateDnsZoneGroupTest()
        {
            virtualNetwork = (await createVirtualNetwork()).Value;
            storageAccount = await createStorageAccount();

            // create
            var privateEndpointCollection = resourceGroup.GetPrivateEndpoints();
            var name = Recording.GenerateAssetName("pe");

            System.Console.WriteLine($"SubnetResource ID: {virtualNetwork.Data.Subnets[0].Id}");
            var privateEndpointData = new PrivateEndpointData
            {
                Location = TestEnvironment.Location,
                Subnet   = virtualNetwork.Data.Subnets[0],
                PrivateLinkServiceConnections =
                {
                    new PrivateLinkServiceConnection
                    {
                        Name = Recording.GenerateAssetName("pec"),
                        // TODO: externalize or create the service on-demand, like virtual network
                        //PrivateLinkServiceId = "/subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c/resourceGroups/sdktest7669/providers/Microsoft.KeyVault/vaults/TierRuanKeyVaultJustTest",
                        PrivateLinkServiceId = storageAccount.Id,
                        RequestMessage       = "SDK test",
                        GroupIds             = { "storage" }
                    }
                },
            };

            var privateEndpoint = (await privateEndpointCollection.CreateOrUpdateAsync(WaitUntil.Completed, name, privateEndpointData)).Value;

            var privateDnsZoneName       = Recording.GenerateAssetName("private_dns_zone");
            var privateDnsZoneResourceId = new ResourceIdentifier($"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/{resourceGroup.Data.Name}/Microsoft.Network/privateDnsZones/{privateDnsZoneName}");

            privateDnsZone = ArmClient.GetGenericResources().CreateOrUpdate(WaitUntil.Completed, privateDnsZoneResourceId, new GenericResourceData(TestEnvironment.Location)).Value;

            var privateDnsZoneGroupName       = Recording.GenerateAssetName("private_dns_zone_group");
            var privateDnsZoneGroupCollection = privateEndpoint.GetPrivateDnsZoneGroups();
            var privateDnsZoneGroup           = (await privateDnsZoneGroupCollection.CreateOrUpdateAsync(WaitUntil.Completed, privateDnsZoneGroupName, new PrivateDnsZoneGroupData {
                PrivateDnsZoneConfigs =
                {
                    new PrivateDnsZoneConfig
                    {
                        Name = privateDnsZoneName,
                        PrivateDnsZoneId = privateDnsZone.Id,
                    }
                }
            })).Value;

            Assert.IsNotEmpty(privateDnsZoneGroup.Data.PrivateDnsZoneConfigs);
            Assert.That(privateDnsZoneGroup.Data.PrivateDnsZoneConfigs, Has.Count.EqualTo(1));
            Assert.AreEqual(privateDnsZoneName, privateDnsZoneGroup.Data.PrivateDnsZoneConfigs[0].Name);
            Assert.AreEqual(privateDnsZone.Id, privateDnsZoneGroup.Data.PrivateDnsZoneConfigs[0].PrivateDnsZoneId);

            // list
            var groups = (await privateDnsZoneGroupCollection.GetAllAsync().ToEnumerableAsync());

            Assert.That(groups, Has.Count.EqualTo(1));
            privateDnsZoneGroup = groups[0];
            Assert.IsNotEmpty(privateDnsZoneGroup.Data.PrivateDnsZoneConfigs);
            Assert.That(privateDnsZoneGroup.Data.PrivateDnsZoneConfigs, Has.Count.EqualTo(1));
            Assert.AreEqual(privateDnsZoneName, privateDnsZoneGroup.Data.PrivateDnsZoneConfigs[0].Name);
            Assert.AreEqual(privateDnsZone.Id, privateDnsZoneGroup.Data.PrivateDnsZoneConfigs[0].PrivateDnsZoneId);

            // get
            privateDnsZoneGroup = (await privateDnsZoneGroupCollection.GetAsync(privateDnsZoneGroupName)).Value;
            Assert.IsNotEmpty(privateDnsZoneGroup.Data.PrivateDnsZoneConfigs);
            Assert.That(privateDnsZoneGroup.Data.PrivateDnsZoneConfigs, Has.Count.EqualTo(1));
            Assert.AreEqual(privateDnsZoneName, privateDnsZoneGroup.Data.PrivateDnsZoneConfigs[0].Name);
            Assert.AreEqual(privateDnsZone.Id, privateDnsZoneGroup.Data.PrivateDnsZoneConfigs[0].PrivateDnsZoneId);

            // update
            privateDnsZoneGroup = (await privateDnsZoneGroupCollection.CreateOrUpdateAsync(WaitUntil.Completed, privateDnsZoneGroupName, new PrivateDnsZoneGroupData {
            })).Value;
            Assert.IsEmpty(privateDnsZoneGroup.Data.PrivateDnsZoneConfigs);

            // delete
            await privateDnsZoneGroup.DeleteAsync(WaitUntil.Completed);

            // list again
            groups = (await privateDnsZoneGroupCollection.GetAllAsync().ToEnumerableAsync());
            Assert.IsEmpty(groups);

            await privateEndpoint.DeleteAsync(WaitUntil.Completed);
        }
예제 #8
0
        public static ActionResponse RegisterKeyVault(ActionRequest request)
        {
            string azureToken     = request.DataStore.GetJson("AzureToken", "access_token");
            string subscriptionId = request.DataStore.GetJson("SelectedSubscription", "SubscriptionId");
            string resourceGroup  = request.DataStore.GetValue("SelectedResourceGroup");

            // Make sure the Key Vault is registered
            SubscriptionCloudCredentials creds = new TokenCloudCredentials(subscriptionId, azureToken);

            using (ResourceManagementClient managementClient = new ResourceManagementClient(creds))
            {
                ProviderListResult providersResult = managementClient.Providers.List(null);

                bool kvExists = false;
                foreach (var p in providersResult.Providers)
                {
                    if (p.Namespace.EqualsIgnoreCase("Microsoft.KeyVault"))
                    {
                        kvExists = p.RegistrationState.EqualsIgnoreCase("Registered");
                        break;
                    }
                }

                AzureOperationResponse operationResponse;
                if (!kvExists)
                {
                    operationResponse = managementClient.Providers.Register("Microsoft.KeyVault");
                    if (operationResponse.StatusCode != System.Net.HttpStatusCode.OK && operationResponse.StatusCode != System.Net.HttpStatusCode.Accepted)
                    {
                        return(new ActionResponse(ActionStatus.Failure, JsonUtility.GetEmptyJObject(), "MsCrm_ErrorRegisterKv"));
                    }

                    Thread.Sleep(10000); // Wait for it to register
                }

                string oid;
                string tenantID;
                ExtractUserandTenant(azureToken, out oid, out tenantID);

                const string    vaultApiVersion = "2015-06-01";
                string          tempVaultName   = "bpst-" + RandomGenerator.GetRandomLowerCaseCharacters(12);
                GenericResource genRes          = new GenericResource("westus")
                {
                    Properties = "{\"sku\": { \"family\": \"A\", \"name\": \"Standard\" }, \"tenantId\": \"" + tenantID + "\", \"accessPolicies\": [], \"enabledForDeployment\": true }"
                };

                operationResponse = managementClient.Resources.CreateOrUpdate(resourceGroup, new ResourceIdentity(tempVaultName, "Microsoft.KeyVault/vaults", vaultApiVersion), genRes);
                bool operationSucceeded = (operationResponse.StatusCode == System.Net.HttpStatusCode.OK) || (operationResponse.StatusCode == System.Net.HttpStatusCode.Accepted);
                Thread.Sleep(15000); // The created vault has an Url. DNS propagation will take a while

                if (operationSucceeded)
                {
                    ResourceIdentity resIdent = new ResourceIdentity(tempVaultName, "Microsoft.KeyVault/vaults", vaultApiVersion);
                    operationResponse  = managementClient.Resources.Delete(resourceGroup, resIdent);
                    operationSucceeded = (operationResponse.StatusCode == System.Net.HttpStatusCode.OK) || (operationResponse.StatusCode == System.Net.HttpStatusCode.Accepted);
                }

                if (!operationSucceeded)
                {
                    return(new ActionResponse(ActionStatus.Failure, JsonUtility.GetEmptyJObject(), "MsCrm_ErrorRegisterKv"));
                }

                return(new ActionResponse(ActionStatus.Success));
            }
        }