diff --git a/sdk/resourcemanager/README.md b/sdk/resourcemanager/README.md index aab9395c1ec62..373b8460efde5 100644 --- a/sdk/resourcemanager/README.md +++ b/sdk/resourcemanager/README.md @@ -77,6 +77,7 @@ In addition, Azure subscription ID can be configured via environment variable `A With above configuration, `azure` client can be authenticated by following code: + ```java AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); TokenCredential credential = new DefaultAzureCredentialBuilder() @@ -142,25 +143,27 @@ Services in preview You can create a virtual machine instance, together with required virtual network and ip address created automatically. + ```java VirtualMachine linuxVM = azure.virtualMachines().define("myLinuxVM") .withRegion(Region.US_EAST) .withNewResourceGroup(rgName) .withNewPrimaryNetwork("10.0.0.0/28") .withPrimaryPrivateIPAddressDynamic() - .withNewPrimaryPublicIPAddress("mylinuxvm") - .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS) - .withRootUsername("tirekicker") - .withSsh(sshKey) + .withoutPrimaryPublicIPAddress() + .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_18_04_LTS) + .withRootUsername("") + .withSsh("") .withSize(VirtualMachineSizeTypes.STANDARD_D3_V2) .create(); ``` Update. + ```java linuxVM.update() - .withNewDataDisk(20, lun, CachingTypes.READ_WRITE) + .withNewDataDisk(10, 0, CachingTypes.READ_WRITE) .apply(); ``` @@ -168,29 +171,28 @@ linuxVM.update() You can create a function app, together with required storage account and app service plan created on specification. + ```java Creatable creatableStorageAccount = azure.storageAccounts() - .define(storageAccountName) + .define("") .withRegion(Region.US_EAST) .withExistingResourceGroup(rgName) .withGeneralPurposeAccountKindV2() .withSku(StorageAccountSkuType.STANDARD_LRS); - Creatable creatableAppServicePlan = azure.appServicePlans() - .define(appServicePlanName) + .define("") .withRegion(Region.US_EAST) .withExistingResourceGroup(rgName) .withPricingTier(PricingTier.STANDARD_S1) .withOperatingSystem(OperatingSystem.LINUX); - -FunctionApp linuxFunctionApp = azure.functionApps().define(functionAppName) +FunctionApp linuxFunctionApp = azure.functionApps().define("") .withRegion(Region.US_EAST) .withExistingResourceGroup(rgName) .withNewLinuxAppServicePlan(creatableAppServicePlan) .withBuiltInImage(FunctionRuntimeStack.JAVA_8) .withNewStorageAccount(creatableStorageAccount) .withHttpsOnly(true) - .withAppSetting("WEBSITE_RUN_FROM_PACKAGE", functionAppPackageUrl) + .withAppSetting("WEBSITE_RUN_FROM_PACKAGE", "") .create(); ``` @@ -198,21 +200,19 @@ FunctionApp linuxFunctionApp = azure.functionApps().define(functionAppName) You can batch create and delete managed disk instances. + ```java List diskNames = Arrays.asList("datadisk1", "datadisk2"); - List> creatableDisks = diskNames.stream() .map(diskName -> azure.disks() .define(diskName) .withRegion(Region.US_EAST) .withExistingResourceGroup(rgName) .withData() - .withSizeInGB(1) + .withSizeInGB(10) .withSku(DiskSkuTypes.STANDARD_LRS)) .collect(Collectors.toList()); - Collection disks = azure.disks().create(creatableDisks).values(); - azure.disks().deleteByIds(disks.stream().map(Disk::id).collect(Collectors.toList())); ``` @@ -220,6 +220,7 @@ azure.disks().deleteByIds(disks.stream().map(Disk::id).collect(Collectors.toList You can assign Contributor for an Azure resource to a service principal. + ```java String raName = UUID.randomUUID().toString(); RoleAssignment roleAssignment = azure.accessManagement().roleAssignments() @@ -234,8 +235,9 @@ RoleAssignment roleAssignment = azure.accessManagement().roleAssignments() You can create storage account, then blob container, in reactive programming. + ```java -azure.storageAccounts().define(storageAccountName) +azure.storageAccounts().define("") .withRegion(Region.US_EAST) .withNewResourceGroup(rgName) .withSku(StorageAccountSkuType.STANDARD_LRS) @@ -248,28 +250,29 @@ azure.storageAccounts().define(storageAccountName) .withPublicAccess(PublicAccess.BLOB) .createAsync() ) - ... + //... ``` You can operate on virtual machines in parallel. + ```java azure.virtualMachines().listByResourceGroupAsync(rgName) .flatMap(VirtualMachine::restartAsync) - ... + //... ``` ### Configurable client -You can customize various aspects of the client. +You can customize various aspects of the client and pipeline. + ```java AzureResourceManager azure = AzureResourceManager .configure() .withHttpClient(customizedHttpClient) .withPolicy(additionalPolicy) - .withConfiguration(customizedConfiguration) - ... + //... ``` ### Include single package @@ -289,9 +292,11 @@ For example, here is sample maven dependency for Compute package. [//]: # ({x-version-update-end}) Sample code to create the authenticated client. + + ```java -ComputeManager client = ComputeManager.authenticate(credential, profile); -client.virtualMachines().listByResourceGroup(rgName); +ComputeManager manager = ComputeManager.authenticate(credential, profile); +manager.virtualMachines().list(); ``` ## Troubleshooting @@ -314,6 +319,8 @@ their resolution. The logs produced will capture the flow of an application befo locate the root issue. View the [logging][logging] wiki for guidance about enabling logging. Sample code to enable logging in Azure Management Libraries. + + ```java AzureResourceManager azure = AzureResourceManager .configure() diff --git a/sdk/resourcemanager/azure-resourcemanager-appplatform/README.md b/sdk/resourcemanager/azure-resourcemanager-appplatform/README.md index 8ebf6ce89fe0d..37de09edfc1c3 100644 --- a/sdk/resourcemanager/azure-resourcemanager-appplatform/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-appplatform/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,46 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +AppPlatformManager manager = AppPlatformManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-appplatform/src/samples/java/com/azure/resourcemanager/appplatform/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-appplatform/src/samples/java/com/azure/resourcemanager/appplatform/ReadmeSamples.java new file mode 100644 index 0000000000000..f961efa46e42c --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-appplatform/src/samples/java/com/azure/resourcemanager/appplatform/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.appplatform; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + AppPlatformManager manager = AppPlatformManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/README.md b/sdk/resourcemanager/azure-resourcemanager-appservice/README.md index 1ac88bf240111..c9cb374fe2a54 100644 --- a/sdk/resourcemanager/azure-resourcemanager-appservice/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,46 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +AppServiceManager manager = AppServiceManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/src/samples/java/com/azure/resourcemanager/appservice/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-appservice/src/samples/java/com/azure/resourcemanager/appservice/ReadmeSamples.java new file mode 100644 index 0000000000000..713b69c8e81f2 --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/src/samples/java/com/azure/resourcemanager/appservice/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.appservice; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + AppServiceManager manager = AppServiceManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-authorization/README.md b/sdk/resourcemanager/azure-resourcemanager-authorization/README.md index c94f649012581..43ef55d885dfd 100644 --- a/sdk/resourcemanager/azure-resourcemanager-authorization/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-authorization/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,46 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +AuthorizationManager manager = AuthorizationManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-authorization/src/samples/java/com/azure/resourcemanager/authorization/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-authorization/src/samples/java/com/azure/resourcemanager/authorization/ReadmeSamples.java new file mode 100644 index 0000000000000..6500698169831 --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-authorization/src/samples/java/com/azure/resourcemanager/authorization/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.authorization; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + AuthorizationManager manager = AuthorizationManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-cdn/README.md b/sdk/resourcemanager/azure-resourcemanager-cdn/README.md index d3c48cb53823f..66d44788cd6f1 100644 --- a/sdk/resourcemanager/azure-resourcemanager-cdn/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-cdn/README.md @@ -2,13 +2,14 @@ Azure Resource Manager CDN client library for Java -For documentation on how to use this package, please see [Azure Management Libraries for Java](https://aka.ms/azure-sdk-java-mgmt). +For documentation on how to use this package, please see [Azure Management Libraries for Java](https://aka.ms/azsdk/java/mgmt). ## Getting started ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,46 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +CdnManager manager = CdnManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-cdn/src/samples/java/com/azure/resourcemanager/cdn/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-cdn/src/samples/java/com/azure/resourcemanager/cdn/ReadmeSamples.java new file mode 100644 index 0000000000000..542d6478492a6 --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-cdn/src/samples/java/com/azure/resourcemanager/cdn/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.cdn; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + CdnManager manager = CdnManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-compute/README.md b/sdk/resourcemanager/azure-resourcemanager-compute/README.md index 5ea0ec01077aa..764e64e5b0eeb 100644 --- a/sdk/resourcemanager/azure-resourcemanager-compute/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-compute/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,46 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +ComputeManager manager = ComputeManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-compute/src/samples/java/com/azure/resourcemanager/compute/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-compute/src/samples/java/com/azure/resourcemanager/compute/ReadmeSamples.java new file mode 100644 index 0000000000000..2087ee7fc6618 --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-compute/src/samples/java/com/azure/resourcemanager/compute/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.compute; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + ComputeManager manager = ComputeManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-containerinstance/README.md b/sdk/resourcemanager/azure-resourcemanager-containerinstance/README.md index 70004df765d9e..18e6dae3b8f39 100644 --- a/sdk/resourcemanager/azure-resourcemanager-containerinstance/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-containerinstance/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,46 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +ContainerInstanceManager manager = ContainerInstanceManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-containerinstance/src/samples/java/com/azure/resourcemanager/containerinstance/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-containerinstance/src/samples/java/com/azure/resourcemanager/containerinstance/ReadmeSamples.java new file mode 100644 index 0000000000000..154184f54c878 --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-containerinstance/src/samples/java/com/azure/resourcemanager/containerinstance/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.containerinstance; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + ContainerInstanceManager manager = ContainerInstanceManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-containerregistry/README.md b/sdk/resourcemanager/azure-resourcemanager-containerregistry/README.md index 0bddd5f955fda..c27b7c61291b4 100644 --- a/sdk/resourcemanager/azure-resourcemanager-containerregistry/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-containerregistry/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,46 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +ContainerRegistryManager manager = ContainerRegistryManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-containerregistry/src/samples/java/com/azure/resourcemanager/containerregistry/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-containerregistry/src/samples/java/com/azure/resourcemanager/containerregistry/ReadmeSamples.java new file mode 100644 index 0000000000000..6797f37a1712a --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-containerregistry/src/samples/java/com/azure/resourcemanager/containerregistry/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.containerregistry; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + ContainerRegistryManager manager = ContainerRegistryManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-containerservice/README.md b/sdk/resourcemanager/azure-resourcemanager-containerservice/README.md index 6ff4dadf5de81..b43319dddfa6f 100644 --- a/sdk/resourcemanager/azure-resourcemanager-containerservice/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-containerservice/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,46 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +ContainerServiceManager manager = ContainerServiceManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-containerservice/src/samples/java/com/azure/resourcemanager/containerservice/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-containerservice/src/samples/java/com/azure/resourcemanager/containerservice/ReadmeSamples.java new file mode 100644 index 0000000000000..3b51f747f9225 --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-containerservice/src/samples/java/com/azure/resourcemanager/containerservice/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.containerservice; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + ContainerServiceManager manager = ContainerServiceManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-cosmos/README.md b/sdk/resourcemanager/azure-resourcemanager-cosmos/README.md index f7f1b202e3c0c..cfeddee0634ca 100644 --- a/sdk/resourcemanager/azure-resourcemanager-cosmos/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-cosmos/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,46 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +CosmosManager manager = CosmosManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-cosmos/src/samples/java/com/azure/resourcemanager/cosmos/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-cosmos/src/samples/java/com/azure/resourcemanager/cosmos/ReadmeSamples.java new file mode 100644 index 0000000000000..e201429c9262e --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-cosmos/src/samples/java/com/azure/resourcemanager/cosmos/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.cosmos; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + CosmosManager manager = CosmosManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-dns/README.md b/sdk/resourcemanager/azure-resourcemanager-dns/README.md index 7bb1ce00568d3..8ac5a5689802e 100644 --- a/sdk/resourcemanager/azure-resourcemanager-dns/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-dns/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,46 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +DnsZoneManager manager = DnsZoneManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-dns/src/samples/java/com/azure/resourcemanager/dns/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-dns/src/samples/java/com/azure/resourcemanager/dns/ReadmeSamples.java new file mode 100644 index 0000000000000..e68f63d692d5d --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-dns/src/samples/java/com/azure/resourcemanager/dns/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.dns; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + DnsZoneManager manager = DnsZoneManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-eventhubs/README.md b/sdk/resourcemanager/azure-resourcemanager-eventhubs/README.md index 3f8269ce8a4e5..e690f4ca9f970 100644 --- a/sdk/resourcemanager/azure-resourcemanager-eventhubs/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-eventhubs/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,46 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +EventHubsManager manager = EventHubsManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-eventhubs/src/samples/java/com/azure/resourcemanager/eventhubs/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-eventhubs/src/samples/java/com/azure/resourcemanager/eventhubs/ReadmeSamples.java new file mode 100644 index 0000000000000..bee086e356068 --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-eventhubs/src/samples/java/com/azure/resourcemanager/eventhubs/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.eventhubs; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + EventHubsManager manager = EventHubsManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-keyvault/README.md b/sdk/resourcemanager/azure-resourcemanager-keyvault/README.md index 208870f5f9821..4d8c77ed47bc7 100644 --- a/sdk/resourcemanager/azure-resourcemanager-keyvault/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-keyvault/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,46 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +KeyVaultManager manager = KeyVaultManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-keyvault/src/samples/java/com/azure/resourcemanager/keyvault/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-keyvault/src/samples/java/com/azure/resourcemanager/keyvault/ReadmeSamples.java new file mode 100644 index 0000000000000..22d6551593534 --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-keyvault/src/samples/java/com/azure/resourcemanager/keyvault/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.keyvault; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + KeyVaultManager manager = KeyVaultManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-monitor/README.md b/sdk/resourcemanager/azure-resourcemanager-monitor/README.md index ceefd31398f18..bf24f28535bd7 100644 --- a/sdk/resourcemanager/azure-resourcemanager-monitor/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-monitor/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,46 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +MonitorManager manager = MonitorManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-monitor/src/samples/java/com/azure/resourcemanager/monitor/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-monitor/src/samples/java/com/azure/resourcemanager/monitor/ReadmeSamples.java new file mode 100644 index 0000000000000..290ded2d7b3f3 --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-monitor/src/samples/java/com/azure/resourcemanager/monitor/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.monitor; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + MonitorManager manager = MonitorManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-msi/README.md b/sdk/resourcemanager/azure-resourcemanager-msi/README.md index d385f4b809676..fe8596e589e7a 100644 --- a/sdk/resourcemanager/azure-resourcemanager-msi/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-msi/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,46 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +MsiManager manager = MsiManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-msi/src/samples/java/com/azure/resourcemanager/msi/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-msi/src/samples/java/com/azure/resourcemanager/msi/ReadmeSamples.java new file mode 100644 index 0000000000000..68790096934cb --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-msi/src/samples/java/com/azure/resourcemanager/msi/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.msi; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + MsiManager manager = MsiManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-network/README.md b/sdk/resourcemanager/azure-resourcemanager-network/README.md index b1f23c1ad1d37..abd4852f985ac 100644 --- a/sdk/resourcemanager/azure-resourcemanager-network/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-network/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,46 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +NetworkManager manager = NetworkManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-network/src/samples/java/com/azure/resourcemanager/network/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-network/src/samples/java/com/azure/resourcemanager/network/ReadmeSamples.java new file mode 100644 index 0000000000000..4458faf60fd78 --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-network/src/samples/java/com/azure/resourcemanager/network/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.network; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + NetworkManager manager = NetworkManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-privatedns/README.md b/sdk/resourcemanager/azure-resourcemanager-privatedns/README.md index ecafae0ef443c..84e9c021f6d32 100644 --- a/sdk/resourcemanager/azure-resourcemanager-privatedns/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-privatedns/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,46 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +PrivateDnsZoneManager manager = PrivateDnsZoneManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-privatedns/src/samples/java/com/azure/resourcemanager/privatedns/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-privatedns/src/samples/java/com/azure/resourcemanager/privatedns/ReadmeSamples.java new file mode 100644 index 0000000000000..25170d408b0b7 --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-privatedns/src/samples/java/com/azure/resourcemanager/privatedns/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.privatedns; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + PrivateDnsZoneManager manager = PrivateDnsZoneManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-redis/README.md b/sdk/resourcemanager/azure-resourcemanager-redis/README.md index f018c7ce48ef0..602600b23a726 100644 --- a/sdk/resourcemanager/azure-resourcemanager-redis/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-redis/README.md @@ -2,11 +2,14 @@ Azure Resource Manager redis cache client library for Java +For documentation on how to use this package, please see [Azure Management Libraries for Java](https://aka.ms/azsdk/java/mgmt). + ## Getting started ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -20,10 +23,46 @@ Azure Resource Manager redis cache client library for Java ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +RedisManager manager = RedisManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -38,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-redis/src/samples/java/com/azure/resourcemanager/redis/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-redis/src/samples/java/com/azure/resourcemanager/redis/ReadmeSamples.java new file mode 100644 index 0000000000000..96f51e81558c1 --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-redis/src/samples/java/com/azure/resourcemanager/redis/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.redis; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + RedisManager manager = RedisManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-resources/README.md b/sdk/resourcemanager/azure-resourcemanager-resources/README.md index 2d49e9b4bbab7..a0b5517f81337 100644 --- a/sdk/resourcemanager/azure-resourcemanager-resources/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-resources/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,47 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +ResourceManager manager = ResourceManager + .authenticate(credential, profile) + .withDefaultSubscription(); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +78,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-resources/src/samples/java/com/azure/resourcemanager/resources/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-resources/src/samples/java/com/azure/resourcemanager/resources/ReadmeSamples.java new file mode 100644 index 0000000000000..f2d0c67872360 --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-resources/src/samples/java/com/azure/resourcemanager/resources/ReadmeSamples.java @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.resources; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + ResourceManager manager = ResourceManager + .authenticate(credential, profile) + .withDefaultSubscription(); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-servicebus/README.md b/sdk/resourcemanager/azure-resourcemanager-servicebus/README.md index 45e24231cfa3c..7d878eac0ed47 100644 --- a/sdk/resourcemanager/azure-resourcemanager-servicebus/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-servicebus/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,46 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +ServiceBusManager manager = ServiceBusManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-servicebus/src/samples/java/com/azure/resourcemanager/servicebus/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-servicebus/src/samples/java/com/azure/resourcemanager/servicebus/ReadmeSamples.java new file mode 100644 index 0000000000000..a5f826b2513dd --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-servicebus/src/samples/java/com/azure/resourcemanager/servicebus/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.servicebus; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + ServiceBusManager manager = ServiceBusManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-sql/README.md b/sdk/resourcemanager/azure-resourcemanager-sql/README.md index 7419e6e817850..b66201410fc8a 100644 --- a/sdk/resourcemanager/azure-resourcemanager-sql/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-sql/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,46 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +SqlServerManager manager = SqlServerManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-sql/src/samples/java/com/azure/resourcemanager/sql/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-sql/src/samples/java/com/azure/resourcemanager/sql/ReadmeSamples.java new file mode 100644 index 0000000000000..3273e2fdbf768 --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-sql/src/samples/java/com/azure/resourcemanager/sql/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.sql; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + SqlServerManager manager = SqlServerManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-storage/README.md b/sdk/resourcemanager/azure-resourcemanager-storage/README.md index 6b2add96c8b17..0bbf60bec87e6 100644 --- a/sdk/resourcemanager/azure-resourcemanager-storage/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-storage/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,46 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +StorageManager manager = StorageManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-storage/src/samples/java/com/azure/resourcemanager/storage/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-storage/src/samples/java/com/azure/resourcemanager/storage/ReadmeSamples.java new file mode 100644 index 0000000000000..4ae644e01b20b --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-storage/src/samples/java/com/azure/resourcemanager/storage/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.storage; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + StorageManager manager = StorageManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-trafficmanager/README.md b/sdk/resourcemanager/azure-resourcemanager-trafficmanager/README.md index 979a8fc4ebf6c..5ebcd24de7516 100644 --- a/sdk/resourcemanager/azure-resourcemanager-trafficmanager/README.md +++ b/sdk/resourcemanager/azure-resourcemanager-trafficmanager/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,46 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +TrafficManager manager = TrafficManager + .authenticate(credential, profile); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +77,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager-trafficmanager/src/samples/java/com/azure/resourcemanager/trafficmanager/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager-trafficmanager/src/samples/java/com/azure/resourcemanager/trafficmanager/ReadmeSamples.java new file mode 100644 index 0000000000000..4564d8b5b620b --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-trafficmanager/src/samples/java/com/azure/resourcemanager/trafficmanager/ReadmeSamples.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.trafficmanager; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + TrafficManager manager = TrafficManager + .authenticate(credential, profile); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager/README.md b/sdk/resourcemanager/azure-resourcemanager/README.md index 5195fd0609d2d..3ad41daeaa46d 100644 --- a/sdk/resourcemanager/azure-resourcemanager/README.md +++ b/sdk/resourcemanager/azure-resourcemanager/README.md @@ -8,7 +8,8 @@ For documentation on how to use this package, please see [Azure Management Libra ### Prerequisites -- Java Development Kit (JDK) with version 8 or above +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] ### Adding the package to your product @@ -22,10 +23,47 @@ For documentation on how to use this package, please see [Azure Management Libra ``` [//]: # ({x-version-update-end}) +### Include the recommended packages + +Azure Management Libraries require a `TokenCredential` implementation for authentication and an `HttpClient` implementation for HTTP client. + +[Azure Identity][azure_identity] package and [Azure Core Netty HTTP][azure_core_http_netty] package provide the default implementation. + +### Authentication + +By default, Azure Active Directory token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH` for client secret or client certificate. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, `azure` client can be authenticated by following code: + + +```java +AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); +TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); +AzureResourceManager azure = AzureResourceManager + .authenticate(credential, profile) + .withDefaultSubscription(); +``` + +The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise. + +See [Authentication][authenticate] for more options. + ## Key concepts +See [API design][design] for general introduction on design and key concepts on Azure Management Libraries. + ## Examples +See [Samples][sample] for code snippets and samples. + ## Troubleshooting ## Next steps @@ -40,3 +78,12 @@ Azure Projects Contribution Guidelines](https://azure.github.io/guidelines.html) 1. Commit your changes (`git commit -am 'Add some feature'`) 1. Push to the branch (`git push origin my-new-feature`) 1. Create new Pull Request + + +[jdk]: https://docs.microsoft.com/java/azure/jdk/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/identity/azure-identity +[azure_core_http_netty]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-http-netty +[authenticate]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md +[sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/SAMPLE.md +[design]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/DESIGN.md diff --git a/sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/ReadmeSamples.java b/sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/ReadmeSamples.java new file mode 100644 index 0000000000000..a5f9816172fdf --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager/src/samples/java/com/azure/resourcemanager/ReadmeSamples.java @@ -0,0 +1,224 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.http.HttpClient; +import com.azure.core.http.policy.HttpLogDetailLevel; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.TimeoutPolicy; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.Region; +import com.azure.core.management.profile.AzureProfile; +import com.azure.identity.DefaultAzureCredentialBuilder; +import com.azure.resourcemanager.appservice.models.AppServicePlan; +import com.azure.resourcemanager.appservice.models.FunctionApp; +import com.azure.resourcemanager.appservice.models.FunctionRuntimeStack; +import com.azure.resourcemanager.appservice.models.OperatingSystem; +import com.azure.resourcemanager.appservice.models.PricingTier; +import com.azure.resourcemanager.authorization.models.BuiltInRole; +import com.azure.resourcemanager.authorization.models.RoleAssignment; +import com.azure.resourcemanager.authorization.models.ServicePrincipal; +import com.azure.resourcemanager.compute.ComputeManager; +import com.azure.resourcemanager.compute.models.CachingTypes; +import com.azure.resourcemanager.compute.models.Disk; +import com.azure.resourcemanager.compute.models.DiskSkuTypes; +import com.azure.resourcemanager.compute.models.KnownLinuxVirtualMachineImage; +import com.azure.resourcemanager.compute.models.VirtualMachine; +import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes; +import com.azure.resourcemanager.resources.fluentcore.model.Creatable; +import com.azure.resourcemanager.resources.models.ResourceGroup; +import com.azure.resourcemanager.storage.models.PublicAccess; +import com.azure.resourcemanager.storage.models.StorageAccount; +import com.azure.resourcemanager.storage.models.StorageAccountSkuType; + +import java.time.Duration; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +/** + * WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS + * ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING + * LINE NUMBERS OF EXISTING CODE SAMPLES. + * + * Code samples for the README.md + */ +public class ReadmeSamples { + + private final String rgName = "rg-test"; + + // extra empty lines to compensate import lines + + + + + + // THIS LINE MUST BE AT LINE NO. 60 + public void authenticate() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + AzureResourceManager azure = AzureResourceManager + .authenticate(credential, profile) + .withDefaultSubscription(); + } + + public void configureWithLogging() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + AzureResourceManager azure = AzureResourceManager + .configure() + .withLogLevel(HttpLogDetailLevel.BASIC) + .authenticate(credential, profile) + .withDefaultSubscription(); + } + + public void authenticateComputeManager() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + ComputeManager manager = ComputeManager.authenticate(credential, profile); + manager.virtualMachines().list(); + } + + public void createAndUpdateVirtualMachine() { + AzureResourceManager azure = newAzureResourceManager(); + + VirtualMachine linuxVM = azure.virtualMachines().define("myLinuxVM") + .withRegion(Region.US_EAST) + .withNewResourceGroup(rgName) + .withNewPrimaryNetwork("10.0.0.0/28") + .withPrimaryPrivateIPAddressDynamic() + .withoutPrimaryPublicIPAddress() + .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_18_04_LTS) + .withRootUsername("") + .withSsh("") + .withSize(VirtualMachineSizeTypes.STANDARD_D3_V2) + .create(); + + linuxVM.update() + .withNewDataDisk(10, 0, CachingTypes.READ_WRITE) + .apply(); + } + + public void createFunctionApp() { + AzureResourceManager azure = newAzureResourceManager(); + + Creatable creatableStorageAccount = azure.storageAccounts() + .define("") + .withRegion(Region.US_EAST) + .withExistingResourceGroup(rgName) + .withGeneralPurposeAccountKindV2() + .withSku(StorageAccountSkuType.STANDARD_LRS); + Creatable creatableAppServicePlan = azure.appServicePlans() + .define("") + .withRegion(Region.US_EAST) + .withExistingResourceGroup(rgName) + .withPricingTier(PricingTier.STANDARD_S1) + .withOperatingSystem(OperatingSystem.LINUX); + FunctionApp linuxFunctionApp = azure.functionApps().define("") + .withRegion(Region.US_EAST) + .withExistingResourceGroup(rgName) + .withNewLinuxAppServicePlan(creatableAppServicePlan) + .withBuiltInImage(FunctionRuntimeStack.JAVA_8) + .withNewStorageAccount(creatableStorageAccount) + .withHttpsOnly(true) + .withAppSetting("WEBSITE_RUN_FROM_PACKAGE", "") + .create(); + } + + public void batchCreateAndDeleteDisk() { + AzureResourceManager azure = newAzureResourceManager(); + + List diskNames = Arrays.asList("datadisk1", "datadisk2"); + List> creatableDisks = diskNames.stream() + .map(diskName -> azure.disks() + .define(diskName) + .withRegion(Region.US_EAST) + .withExistingResourceGroup(rgName) + .withData() + .withSizeInGB(10) + .withSku(DiskSkuTypes.STANDARD_LRS)) + .collect(Collectors.toList()); + Collection disks = azure.disks().create(creatableDisks).values(); + azure.disks().deleteByIds(disks.stream().map(Disk::id).collect(Collectors.toList())); + } + + public void createRoleAssignment() { + AzureResourceManager azure = newAzureResourceManager(); + ResourceGroup resource = azure.resourceGroups().getByName(rgName); + ServicePrincipal servicePrincipal = azure.accessManagement().servicePrincipals().getById(""); + + String raName = UUID.randomUUID().toString(); + RoleAssignment roleAssignment = azure.accessManagement().roleAssignments() + .define(raName) + .forServicePrincipal(servicePrincipal) + .withBuiltInRole(BuiltInRole.CONTRIBUTOR) + .withScope(resource.id()) + .create(); + } + + public void createStorageAccountAndBlobContainerAsync() { + AzureResourceManager azure = newAzureResourceManager(); + + azure.storageAccounts().define("") + .withRegion(Region.US_EAST) + .withNewResourceGroup(rgName) + .withSku(StorageAccountSkuType.STANDARD_LRS) + .withGeneralPurposeAccountKindV2() + .withOnlyHttpsTraffic() + .createAsync() + .flatMap(storageAccount -> azure.storageBlobContainers() + .defineContainer("container") + .withExistingBlobService(rgName, storageAccount.name()) + .withPublicAccess(PublicAccess.BLOB) + .createAsync() + ) + //... + .block(); + } + + public void restartVirtualMachineAsync() { + AzureResourceManager azure = newAzureResourceManager(); + + azure.virtualMachines().listByResourceGroupAsync(rgName) + .flatMap(VirtualMachine::restartAsync) + //... + .blockLast(); + } + + public void configureClientAndPipeline() { + HttpClient customizedHttpClient = HttpClient.createDefault(); + HttpPipelinePolicy additionalPolicy = new TimeoutPolicy(Duration.ofMinutes(2)); + + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + AzureResourceManager azure = AzureResourceManager + .configure() + .withHttpClient(customizedHttpClient) + .withPolicy(additionalPolicy) + //... + .authenticate(credential, profile) + .withDefaultSubscription(); + } + + private AzureResourceManager newAzureResourceManager() { + AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + TokenCredential credential = new DefaultAzureCredentialBuilder() + .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()) + .build(); + return AzureResourceManager + .authenticate(credential, profile) + .withDefaultSubscription(); + } +}