Skip to content

Commit

Permalink
mgmt make authenticate with http pipeline private access (Azure#16144)
Browse files Browse the repository at this point in the history
* mgmt make authenticate with http pipeline private access

* reformat pass http pipeline

* apply changes in storage

* apply changes for each service manager

* update azure resource manager

* update samples

* update pom based on the changes of tests

* remove unused sample utils method

* update test for jacoco coverage

* fix compile errors on latest code

* remove withHttpPipeline from Manager.java

* update pom and fix checkstyle
  • Loading branch information
xseeseesee authored Oct 15, 2020
1 parent 3a37c04 commit 8b823f7
Show file tree
Hide file tree
Showing 82 changed files with 598 additions and 272 deletions.
23 changes: 23 additions & 0 deletions sdk/resourcemanager/azure-resourcemanager-appplatform/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,29 @@
</dependency>
</dependencies>
</profile>
<profile>
<id>java-lts</id>
<activation>
<jdk>[11,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
<configuration>
<argLine>
<!-- tests fail without these exports. -->
--add-exports com.azure.resourcemanager.resources/com.azure.resourcemanager.resources.fluentcore.arm.implementation=ALL-UNNAMED

--add-opens com.azure.resourcemanager.appplatform/com.azure.resourcemanager.appplatform=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static AppPlatformManager authenticate(TokenCredential credential, AzureP
* @param profile the profile to use
* @return the AppPlatformManager
*/
public static AppPlatformManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) {
private static AppPlatformManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) {
return new AppPlatformManager(httpPipeline, profile);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ protected HttpPipeline buildHttpPipeline(
protected void initializeClients(HttpPipeline httpPipeline, AzureProfile profile) {
ResourceManagerUtils.InternalRuntimeContext.setDelayProvider(new TestDelayProvider(!isPlaybackMode()));
rgName = generateRandomResourceName("rg", 20);
appPlatformManager = AppPlatformManager.authenticate(httpPipeline, profile);
appServiceManager = AppServiceManager.authenticate(httpPipeline, profile);
dnsZoneManager = DnsZoneManager.authenticate(httpPipeline, profile);
keyVaultManager = KeyVaultManager.authenticate(httpPipeline, profile);
appPlatformManager = buildManager(AppPlatformManager.class, httpPipeline, profile);
appServiceManager = buildManager(AppServiceManager.class, httpPipeline, profile);
dnsZoneManager = buildManager(DnsZoneManager.class, httpPipeline, profile);
keyVaultManager = buildManager(KeyVaultManager.class, httpPipeline, profile);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
--add-opens com.azure.resourcemanager.msi/com.azure.resourcemanager.msi=ALL-UNNAMED
--add-opens com.azure.resourcemanager.resources/com.azure.resourcemanager.resources=ALL-UNNAMED
--add-opens com.azure.resourcemanager.resources/com.azure.resourcemanager.resources.fluentcore.arm=ALL-UNNAMED
--add-opens com.azure.resourcemanager.storage/com.azure.resourcemanager.storage=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static AppServiceManager authenticate(TokenCredential credential, AzurePr
* @param profile the profile to use
* @return the StorageManager
*/
public static AppServiceManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) {
private static AppServiceManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) {
return new AppServiceManager(httpPipeline, profile);
}

Expand Down Expand Up @@ -103,10 +103,15 @@ private AppServiceManager(HttpPipeline httpPipeline, AzureProfile profile) {
.endpoint(profile.getEnvironment().getResourceManagerEndpoint())
.subscriptionId(profile.getSubscriptionId())
.buildClient());
keyVaultManager = KeyVaultManager.authenticate(httpPipeline, profile);
storageManager = StorageManager.authenticate(httpPipeline, profile);
authorizationManager = AuthorizationManager.authenticate(httpPipeline, profile);
dnsZoneManager = DnsZoneManager.authenticate(httpPipeline, profile);
keyVaultManager = AzureConfigurableImpl.configureHttpPipeline(httpPipeline, KeyVaultManager.configure())
.authenticate(null, profile);
storageManager = AzureConfigurableImpl.configureHttpPipeline(httpPipeline, StorageManager.configure())
.authenticate(null, profile);
authorizationManager = AzureConfigurableImpl
.configureHttpPipeline(httpPipeline, AuthorizationManager.configure())
.authenticate(null, profile);
dnsZoneManager = AzureConfigurableImpl.configureHttpPipeline(httpPipeline, DnsZoneManager.configure())
.authenticate(null, profile);
}

/** @return the authorization manager instance. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ protected void initializeClients(HttpPipeline httpPipeline, AzureProfile profile
ResourceManagerUtils.InternalRuntimeContext.setDelayProvider(new TestDelayProvider(!isPlaybackMode()));
ResourceManagerUtils.InternalRuntimeContext internalContext = new ResourceManagerUtils.InternalRuntimeContext();
internalContext.setIdentifierFunction(name -> new TestIdentifierProvider(testResourceNamer));
resourceManager =
ResourceManager.authenticate(httpPipeline, profile).withDefaultSubscription();
keyVaultManager = KeyVaultManager.authenticate(httpPipeline, profile);
appServiceManager = AppServiceManager.authenticate(httpPipeline, profile);
msiManager = MsiManager.authenticate(httpPipeline, profile);

keyVaultManager = buildManager(KeyVaultManager.class, httpPipeline, profile);
appServiceManager = buildManager(AppServiceManager.class, httpPipeline, profile);
msiManager = buildManager(MsiManager.class, httpPipeline, profile);
resourceManager = appServiceManager.resourceManager();
setInternalContext(internalContext, appServiceManager, msiManager);

// useExistingDomainAndCertificate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected void initializeClients(HttpPipeline httpPipeline, AzureProfile profile
rgName1 = generateRandomResourceName("javacsmrg", 20);
rgName2 = generateRandomResourceName("javacsmrg", 20);

storageManager = StorageManager.authenticate(httpPipeline, profile);
storageManager = buildManager(StorageManager.class, httpPipeline, profile);

super.initializeClients(httpPipeline, profile);
}
Expand Down
22 changes: 22 additions & 0 deletions sdk/resourcemanager/azure-resourcemanager-authorization/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,28 @@
</dependency>
</dependencies>
</profile>
<profile>
<id>java-lts</id>
<activation>
<jdk>[11,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
<configuration>
<argLine>
<!-- tests fail without these exports. -->
--add-opens com.azure.resourcemanager.authorization/com.azure.resourcemanager.authorization=ALL-UNNAMED
--add-opens com.azure.resourcemanager.resources/com.azure.resourcemanager.resources=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static AuthorizationManager authenticate(TokenCredential credential, Azur
* @param profile the profile used in Active Directory
* @return the AuthorizationManager instance
*/
public static AuthorizationManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) {
private static AuthorizationManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) {
return new AuthorizationManager(httpPipeline, profile);
}

Expand Down Expand Up @@ -98,7 +98,7 @@ public interface Configurable extends AzureConfigurable<Configurable> {
private static class ConfigurableImpl extends AzureConfigurableImpl<Configurable> implements Configurable {
public AuthorizationManager authenticate(TokenCredential credential, AzureProfile profile) {
return AuthorizationManager
.authenticate(HttpPipelineProvider.buildHttpPipeline(credential, profile), profile);
.authenticate(buildHttpPipeline(credential, profile), profile);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ protected HttpPipeline buildHttpPipeline(
@Override
protected void initializeClients(HttpPipeline httpPipeline, AzureProfile profile) {
ResourceManagerUtils.InternalRuntimeContext.setDelayProvider(new TestDelayProvider(!isPlaybackMode()));
authorizationManager = AuthorizationManager.authenticate(httpPipeline, profile);
resourceManager =
ResourceManager.authenticate(httpPipeline, profile).withDefaultSubscription();
authorizationManager = buildManager(AuthorizationManager.class, httpPipeline, profile);
resourceManager = buildManager(ResourceManager.class, httpPipeline, profile);
}


Expand Down
21 changes: 21 additions & 0 deletions sdk/resourcemanager/azure-resourcemanager-cdn/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,27 @@
</dependency>
</dependencies>
</profile>
<profile>
<id>java-lts</id>
<activation>
<jdk>[11,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
<configuration>
<argLine>
<!-- tests fail without these exports. -->
--add-opens com.azure.resourcemanager.cdn/com.azure.resourcemanager.cdn=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static CdnManager authenticate(TokenCredential credential, AzureProfile p
* @param profile the profile to use
* @return the CDN Manager
*/
public static CdnManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) {
private static CdnManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) {
return new CdnManager(httpPipeline, profile);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ protected HttpPipeline buildHttpPipeline(
@Override
protected void initializeClients(HttpPipeline httpPipeline, AzureProfile profile) {
ResourceManagerUtils.InternalRuntimeContext.setDelayProvider(new TestDelayProvider(!isPlaybackMode()));
resourceManager =
ResourceManager.authenticate(httpPipeline, profile).withDefaultSubscription();
cdnManager = CdnManager.authenticate(httpPipeline, profile);
cdnManager = buildManager(CdnManager.class, httpPipeline, profile);
resourceManager = cdnManager.resourceManager();
}
}
4 changes: 4 additions & 0 deletions sdk/resourcemanager/azure-resourcemanager-compute/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,15 @@
<configuration>
<argLine>
<!-- tests fail without these exports. -->
--add-exports com.azure.resourcemanager.resources/com.azure.resourcemanager.resources.fluentcore.arm.implementation=ALL-UNNAMED

--add-opens com.azure.resourcemanager.authorization/com.azure.resourcemanager.authorization=ALL-UNNAMED
--add-opens com.azure.resourcemanager.msi/com.azure.resourcemanager.msi=ALL-UNNAMED
--add-opens com.azure.resourcemanager.network/com.azure.resourcemanager.network=ALL-UNNAMED
--add-opens com.azure.resourcemanager.compute/com.azure.resourcemanager.compute=ALL-UNNAMED
--add-opens com.azure.resourcemanager.resources/com.azure.resourcemanager.resources=ALL-UNNAMED
--add-opens com.azure.resourcemanager.resources/com.azure.resourcemanager.resources.fluentcore.arm=ALL-UNNAMED
--add-opens com.azure.resourcemanager.storage/com.azure.resourcemanager.storage=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static ComputeManager authenticate(TokenCredential credential, AzureProfi
* @param profile the profile to use
* @return the ComputeManager
*/
public static ComputeManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) {
private static ComputeManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) {
return new ComputeManager(httpPipeline, profile);
}

Expand Down Expand Up @@ -139,9 +139,13 @@ private ComputeManager(HttpPipeline httpPipeline, AzureProfile profile) {
.pipeline(httpPipeline)
.subscriptionId(profile.getSubscriptionId())
.buildClient());
storageManager = StorageManager.authenticate(httpPipeline, profile);
networkManager = NetworkManager.authenticate(httpPipeline, profile);
authorizationManager = AuthorizationManager.authenticate(httpPipeline, profile);
storageManager = AzureConfigurableImpl.configureHttpPipeline(httpPipeline, StorageManager.configure())
.authenticate(null, profile);
networkManager = AzureConfigurableImpl.configureHttpPipeline(httpPipeline, NetworkManager.configure())
.authenticate(null, profile);
authorizationManager = AzureConfigurableImpl
.configureHttpPipeline(httpPipeline, AuthorizationManager.configure())
.authenticate(null, profile);
}

/** @return the availability set resource management API entry point */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,13 @@ protected void initializeClients(HttpPipeline httpPipeline, AzureProfile profile
ResourceManagerUtils.InternalRuntimeContext.setDelayProvider(new TestDelayProvider(!isPlaybackMode()));
ResourceManagerUtils.InternalRuntimeContext internalContext = new ResourceManagerUtils.InternalRuntimeContext();
internalContext.setIdentifierFunction(name -> new TestIdentifierProvider(testResourceNamer));
resourceManager =
ResourceManager.authenticate(httpPipeline, profile).withDefaultSubscription();
computeManager = ComputeManager.authenticate(httpPipeline, profile);
networkManager = NetworkManager.authenticate(httpPipeline, profile);
storageManager = StorageManager.authenticate(httpPipeline, profile);
keyVaultManager = KeyVaultManager.authenticate(httpPipeline, profile);
authorizationManager = AuthorizationManager.authenticate(httpPipeline, profile);
msiManager = MsiManager.authenticate(httpPipeline, profile);
computeManager = buildManager(ComputeManager.class, httpPipeline, profile);
networkManager = buildManager(NetworkManager.class, httpPipeline, profile);
storageManager = buildManager(StorageManager.class, httpPipeline, profile);
keyVaultManager = buildManager(KeyVaultManager.class, httpPipeline, profile);
authorizationManager = buildManager(AuthorizationManager.class, httpPipeline, profile);
msiManager = buildManager(MsiManager.class, httpPipeline, profile);
resourceManager = computeManager.resourceManager();
setInternalContext(internalContext, computeManager, networkManager, keyVaultManager, msiManager);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static ContainerInstanceManager authenticate(TokenCredential credential,
* @param profile the profile to use
* @return the ContainerInstanceManager
*/
public static ContainerInstanceManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) {
private static ContainerInstanceManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) {
return new ContainerInstanceManager(httpPipeline, profile);
}

Expand Down Expand Up @@ -89,9 +89,13 @@ private ContainerInstanceManager(HttpPipeline httpPipeline, AzureProfile profile
.subscriptionId(profile.getSubscriptionId())
.buildClient());

this.storageManager = StorageManager.authenticate(httpPipeline, profile);
this.authorizationManager = AuthorizationManager.authenticate(httpPipeline, profile);
this.networkManager = NetworkManager.authenticate(httpPipeline, profile);
this.storageManager = AzureConfigurableImpl.configureHttpPipeline(httpPipeline, StorageManager.configure())
.authenticate(null, profile);
this.authorizationManager = AzureConfigurableImpl
.configureHttpPipeline(httpPipeline, AuthorizationManager.configure())
.authenticate(null, profile);
this.networkManager = AzureConfigurableImpl.configureHttpPipeline(httpPipeline, NetworkManager.configure())
.authenticate(null, profile);
}

/** @return the storage manager in container instance manager */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected void initializeClients(HttpPipeline httpPipeline, AzureProfile profile
ResourceManagerUtils.InternalRuntimeContext internalContext = new ResourceManagerUtils.InternalRuntimeContext();
internalContext.setIdentifierFunction(name -> new TestIdentifierProvider(testResourceNamer));
ResourceManagerUtils.InternalRuntimeContext.setDelayProvider(new TestDelayProvider(!isPlaybackMode()));
containerInstanceManager = ContainerInstanceManager.authenticate(httpPipeline, profile);
containerInstanceManager = buildManager(ContainerInstanceManager.class, httpPipeline, profile);
setInternalContext(internalContext, containerInstanceManager);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,27 @@
</dependency>
</dependencies>
</profile>
<profile>
<id>java-lts</id>
<activation>
<jdk>[11,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
<configuration>
<argLine>
<!-- tests fail without these exports. -->
--add-opens com.azure.resourcemanager.containerregistry/com.azure.resourcemanager.containerregistry=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static ContainerRegistryManager authenticate(TokenCredential credential,
* @param profile the profile to use
* @return the ContainerRegistryManager
*/
public static ContainerRegistryManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) {
private static ContainerRegistryManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) {
return new ContainerRegistryManager(httpPipeline, profile);
}

Expand Down Expand Up @@ -95,7 +95,8 @@ private ContainerRegistryManager(HttpPipeline httpPipeline, AzureProfile profile
.endpoint(profile.getEnvironment().getResourceManagerEndpoint())
.subscriptionId(profile.getSubscriptionId())
.buildClient());
this.storageManager = StorageManager.authenticate(httpPipeline, profile);
this.storageManager = AzureConfigurableImpl.configureHttpPipeline(httpPipeline, StorageManager.configure())
.authenticate(null, profile);
}

/** @return the availability set resource management API entry point */
Expand Down
Loading

0 comments on commit 8b823f7

Please sign in to comment.