public void CreateRoleAssignment() { client = Client; Pageable <KeyVaultRoleDefinition> allDefinitions = client.GetRoleDefinitions(KeyVaultRoleScope.Global); _roleDefinitionId = allDefinitions.FirstOrDefault(d => d.RoleName == RoleName).Id; // Replace roleDefinitionId with a role definition Id from the definitions returned from the List the role definitions section above string definitionIdToAssign = _roleDefinitionId; // Replace objectId with the service principal object id from the Create/Get credentials section above string servicePrincipalObjectId = _objectId; #region Snippet:ReadmeCreateRoleAssignment #if SNIPPET // Replace <roleDefinitionId> with a role definition Id from the definitions returned from the List the role definitions section above string definitionIdToAssign = "<roleDefinitionId>"; // Replace <objectId> with the service principal object id from the Create/Get credentials section above string servicePrincipalObjectId = "<objectId>"; RoleAssignment createdAssignment = client.CreateRoleAssignment(RoleAssignmentScope.Global, properties); #else KeyVaultRoleAssignment createdAssignment = client.CreateRoleAssignment(KeyVaultRoleScope.Global, definitionIdToAssign, servicePrincipalObjectId, _roleAssignmentId); #endif Console.WriteLine(createdAssignment.Name); Console.WriteLine(createdAssignment.Properties.PrincipalId); Console.WriteLine(createdAssignment.Properties.RoleDefinitionId); KeyVaultRoleAssignment fetchedAssignment = client.GetRoleAssignment(KeyVaultRoleScope.Global, createdAssignment.Name); Console.WriteLine(fetchedAssignment.Name); Console.WriteLine(fetchedAssignment.Properties.PrincipalId); Console.WriteLine(fetchedAssignment.Properties.RoleDefinitionId); KeyVaultRoleAssignment deletedAssignment = client.DeleteRoleAssignment(KeyVaultRoleScope.Global, createdAssignment.Name); Console.WriteLine(deletedAssignment.Name); Console.WriteLine(deletedAssignment.Properties.PrincipalId); Console.WriteLine(deletedAssignment.Properties.RoleDefinitionId); #endregion }
public void FineGrainedBatching() { string connectionString = ConnectionString; string containerName = Randomize("sample-container"); #region Snippet:SampleSnippetsBatch_FineGrainedBatching // Get a connection string to our Azure Storage account. //@@ string connectionString = "<connection_string>"; //@@ string containerName = "sample-container"; // Get a reference to a container named "sample-container" and then create it BlobServiceClient service = new BlobServiceClient(connectionString); BlobContainerClient container = service.GetBlobContainerClient(containerName); container.Create(); // Create three blobs named "foo", "bar", and "baz" BlobClient foo = container.GetBlobClient("foo"); BlobClient bar = container.GetBlobClient("bar"); BlobClient baz = container.GetBlobClient("baz"); foo.Upload(new MemoryStream(Encoding.UTF8.GetBytes("Foo!"))); foo.CreateSnapshot(); bar.Upload(new MemoryStream(Encoding.UTF8.GetBytes("Bar!"))); bar.CreateSnapshot(); baz.Upload(new MemoryStream(Encoding.UTF8.GetBytes("Baz!"))); // Create a batch with three deletes BlobBatchClient batchClient = service.GetBlobBatchClient(); BlobBatch batch = batchClient.CreateBatch(); batch.DeleteBlob(foo.Uri, DeleteSnapshotsOption.IncludeSnapshots); batch.DeleteBlob(bar.Uri, DeleteSnapshotsOption.OnlySnapshots); batch.DeleteBlob(baz.Uri); // Submit the batch batchClient.SubmitBatch(batch); #endregion Pageable <BlobItem> blobs = container.GetBlobs(states: BlobStates.Snapshots); Assert.AreEqual(1, blobs.Count()); Assert.AreEqual("bar", blobs.FirstOrDefault().Name); // Clean up after the test when we're finished container.Delete(); }