Skip to content

Commit

Permalink
mgmt disallow user pass SdkContext into Manager class (#15539)
Browse files Browse the repository at this point in the history
* remove SdkContext from user input

* update msi for sdk context change

* update storage

* add method setSdkContext

* update after adding new method to set SdkContext

* update pom for -add-opens
  • Loading branch information
xseeseesee authored Sep 24, 2020
1 parent 1c8391b commit 298fb25
Show file tree
Hide file tree
Showing 227 changed files with 1,136 additions and 1,251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.azure.resourcemanager.resources.fluentcore.arm.Manager;
import com.azure.core.management.profile.AzureProfile;
import com.azure.resourcemanager.resources.fluentcore.utils.HttpPipelineProvider;
import com.azure.resourcemanager.resources.fluentcore.utils.SdkContext;

/** Entry point to Azure App Platform management. */
public final class AppPlatformManager extends Manager<AppPlatformManagementClient> {
Expand Down Expand Up @@ -48,20 +47,7 @@ public static AppPlatformManager authenticate(TokenCredential credential, AzureP
* @return the AppPlatformManager
*/
public static AppPlatformManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) {
return authenticate(httpPipeline, profile, new SdkContext());
}

/**
* Creates an instance of AppPlatformManager that exposes app platform resource management API entry points.
*
* @param httpPipeline the HttpPipeline to be used for API calls.
* @param profile the profile to use
* @param sdkContext the sdk context
* @return the AppPlatformManager
*/
public static AppPlatformManager authenticate(
HttpPipeline httpPipeline, AzureProfile profile, SdkContext sdkContext) {
return new AppPlatformManager(httpPipeline, profile, sdkContext);
return new AppPlatformManager(httpPipeline, profile);
}

/** The interface allowing configurations to be set. */
Expand All @@ -83,16 +69,15 @@ public AppPlatformManager authenticate(TokenCredential credential, AzureProfile
}
}

private AppPlatformManager(HttpPipeline httpPipeline, AzureProfile profile, SdkContext sdkContext) {
private AppPlatformManager(HttpPipeline httpPipeline, AzureProfile profile) {
super(
httpPipeline,
profile,
new AppPlatformManagementClientBuilder()
.pipeline(httpPipeline)
.endpoint(profile.getEnvironment().getResourceManagerEndpoint())
.subscriptionId(profile.getSubscriptionId())
.buildClient(),
sdkContext);
.buildClient());
}

/** @return Entry point for Spring Service management API. */
Expand Down
26 changes: 26 additions & 0 deletions sdk/resourcemanager/azure-resourcemanager-appservice/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,32 @@
</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.appservice/com.azure.resourcemanager.appservice=ALL-UNNAMED
--add-opens com.azure.resourcemanager.authorization/com.azure.resourcemanager.authorization=ALL-UNNAMED
--add-opens com.azure.resourcemanager.keyvault/com.azure.resourcemanager.keyvault=ALL-UNNAMED
--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
</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.azure.resourcemanager.resources.fluentcore.arm.Manager;
import com.azure.core.management.profile.AzureProfile;
import com.azure.resourcemanager.resources.fluentcore.utils.HttpPipelineProvider;
import com.azure.resourcemanager.resources.fluentcore.utils.SdkContext;
import com.azure.resourcemanager.storage.StorageManager;

/** Entry point to Azure storage resource management. */
Expand Down Expand Up @@ -73,20 +72,7 @@ public static AppServiceManager authenticate(TokenCredential credential, AzurePr
* @return the StorageManager
*/
public static AppServiceManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) {
return authenticate(httpPipeline, profile, new SdkContext());
}

/**
* Creates an instance of StorageManager that exposes storage resource management API entry points.
*
* @param httpPipeline the HttpPipeline to be used for API calls.
* @param profile the profile to use
* @param sdkContext the sdk context
* @return the StorageManager
*/
public static AppServiceManager authenticate(
HttpPipeline httpPipeline, AzureProfile profile, SdkContext sdkContext) {
return new AppServiceManager(httpPipeline, profile, sdkContext);
return new AppServiceManager(httpPipeline, profile);
}

/** The interface allowing configurations to be set. */
Expand All @@ -108,20 +94,19 @@ public AppServiceManager authenticate(TokenCredential credential, AzureProfile p
}
}

private AppServiceManager(HttpPipeline httpPipeline, AzureProfile profile, SdkContext sdkContext) {
private AppServiceManager(HttpPipeline httpPipeline, AzureProfile profile) {
super(
httpPipeline,
profile,
new WebSiteManagementClientBuilder()
.pipeline(httpPipeline)
.endpoint(profile.getEnvironment().getResourceManagerEndpoint())
.subscriptionId(profile.getSubscriptionId())
.buildClient(),
sdkContext);
keyVaultManager = KeyVaultManager.authenticate(httpPipeline, profile, sdkContext);
storageManager = StorageManager.authenticate(httpPipeline, profile, sdkContext);
authorizationManager = AuthorizationManager.authenticate(httpPipeline, profile, sdkContext);
dnsZoneManager = DnsZoneManager.authenticate(httpPipeline, profile, sdkContext);
.buildClient());
keyVaultManager = KeyVaultManager.authenticate(httpPipeline, profile);
storageManager = StorageManager.authenticate(httpPipeline, profile);
authorizationManager = AuthorizationManager.authenticate(httpPipeline, profile);
dnsZoneManager = DnsZoneManager.authenticate(httpPipeline, profile);
}

/** @return the Graph RBAC manager instance. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ Mono<SiteLogsConfigInner> updateDiagnosticLogsConfig(SiteLogsConfigInner siteLog
}

private AppServicePlanImpl newDefaultAppServicePlan() {
String planName = this.manager().sdkContext().randomResourceName(name() + "plan", 32);
String planName = this.manager().resourceManager().sdkContext().randomResourceName(name() + "plan", 32);
return newDefaultAppServicePlan(planName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ Mono<Indexable> submitAppSettings() {
SETTING_WEBSITE_CONTENTAZUREFILECONNECTIONSTRING, connectionString);
addAppSettingIfNotModified(
SETTING_WEBSITE_CONTENTSHARE,
this.manager().sdkContext().randomResourceName(name(), 32));
this.manager().resourceManager().sdkContext().randomResourceName(name(), 32));
}
return FunctionAppImpl.super.submitAppSettings();
}))
Expand Down Expand Up @@ -594,7 +594,7 @@ public Mono<FunctionApp> createAsync() {
}
if (currentStorageAccount == null && storageAccountToSet == null && storageAccountCreatable == null) {
withNewStorageAccount(
this.manager().sdkContext().randomResourceName(name(), 20),
this.manager().resourceManager().sdkContext().randomResourceName(name(), 20),
StorageAccountSkuType.STANDARD_GRS);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ protected void initializeClients(HttpPipeline httpPipeline, AzureProfile profile
resourceManager =
ResourceManager.authenticate(httpPipeline, profile).withDefaultSubscription();
keyVaultManager = KeyVaultManager.authenticate(httpPipeline, profile);
appServiceManager = AppServiceManager.authenticate(httpPipeline, profile, sdkContext);
msiManager = MSIManager.authenticate(httpPipeline, profile, sdkContext);
appServiceManager = AppServiceManager.authenticate(httpPipeline, profile);
msiManager = MSIManager.authenticate(httpPipeline, profile);
setSdkContext(sdkContext, appServiceManager, msiManager);

// useExistingDomainAndCertificate();
// createNewDomainAndCertificate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
/** Entry point to Azure Graph RBAC management. */
public final class AuthorizationManager implements HasServiceClient<GraphRbacManagementClient> {
private final String tenantId;
private final SdkContext sdkContext;
private SdkContext sdkContext;
// The sdk clients
private final GraphRbacManagementClient graphRbacManagementClient;
private final AuthorizationManagementClient authorizationManagementClient;
Expand Down Expand Up @@ -62,20 +62,7 @@ public static AuthorizationManager authenticate(TokenCredential credential, Azur
* @return the interface exposing Graph RBAC management API entry points that work across subscriptions
*/
public static AuthorizationManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) {
return authenticate(httpPipeline, profile, new SdkContext());
}

/**
* Creates an instance of GraphRbacManager that exposes Graph RBAC management API entry points.
*
* @param httpPipeline the HttpPipeline to be used for API calls
* @param profile the profile used in Active Directory
* @param sdkContext the sdk context
* @return the interface exposing Graph RBAC management API entry points that work across subscriptions
*/
public static AuthorizationManager authenticate(
HttpPipeline httpPipeline, AzureProfile profile, SdkContext sdkContext) {
return new AuthorizationManager(httpPipeline, profile, sdkContext);
return new AuthorizationManager(httpPipeline, profile);
}

/**
Expand Down Expand Up @@ -112,7 +99,7 @@ public AuthorizationManager authenticate(TokenCredential credential, AzureProfil
}
}

private AuthorizationManager(HttpPipeline httpPipeline, AzureProfile profile, SdkContext sdkContext) {
private AuthorizationManager(HttpPipeline httpPipeline, AzureProfile profile) {
this.graphRbacManagementClient =
new GraphRbacManagementClientBuilder()
.pipeline(httpPipeline)
Expand All @@ -126,7 +113,6 @@ private AuthorizationManager(HttpPipeline httpPipeline, AzureProfile profile, Sd
.subscriptionId(profile.getSubscriptionId())
.buildClient();
this.tenantId = profile.getTenantId();
this.sdkContext = sdkContext;
}

/**
Expand All @@ -144,6 +130,9 @@ public String tenantId() {

/** @return the sdk context in graph manager */
public SdkContext sdkContext() {
if (sdkContext == null) {
sdkContext = new SdkContext();
}
return sdkContext;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.azure.resourcemanager.resources.fluentcore.arm.Manager;
import com.azure.resourcemanager.resources.fluentcore.arm.implementation.AzureConfigurableImpl;
import com.azure.resourcemanager.resources.fluentcore.utils.HttpPipelineProvider;
import com.azure.resourcemanager.resources.fluentcore.utils.SdkContext;
import com.azure.resourcemanager.cdn.models.CdnProfiles;

/**
Expand Down Expand Up @@ -52,19 +51,7 @@ public static CdnManager authenticate(TokenCredential credential, AzureProfile p
* @return the CDN Manager
*/
public static CdnManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) {
return authenticate(httpPipeline, profile, new SdkContext());
}

/**
* Creates an instance of CDN Manager that exposes CDN manager management API entry points.
*
* @param httpPipeline the HttpPipeline to be used for API calls.
* @param profile the profile to use
* @param sdkContext the sdk context
* @return the CDN Manager
*/
public static CdnManager authenticate(HttpPipeline httpPipeline, AzureProfile profile, SdkContext sdkContext) {
return new CdnManager(httpPipeline, profile, sdkContext);
return new CdnManager(httpPipeline, profile);
}

/**
Expand Down Expand Up @@ -93,17 +80,15 @@ public CdnManager authenticate(TokenCredential credential, AzureProfile profile)
}
}

private CdnManager(HttpPipeline httpPipeline, AzureProfile profile, SdkContext sdkContext) {
private CdnManager(HttpPipeline httpPipeline, AzureProfile profile) {
super(
httpPipeline,
profile,
new CdnManagementClientBuilder()
.pipeline(httpPipeline)
.endpoint(profile.getEnvironment().getResourceManagerEndpoint())
.subscriptionId(profile.getSubscriptionId())
.buildClient(),
sdkContext
);
.buildClient());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public Mono<CdnEndpoint> createResourceAsync() {
self.parent().resourceGroupName(),
self.parent().name(),
self.name(),
self.parent().manager().sdkContext().randomResourceName("CustomDomain", 50),
self.parent().manager().resourceManager().sdkContext()
.randomResourceName("CustomDomain", 50),
customDomainInner.hostname()), 32, 32)
.then(self.parent().manager().serviceClient()
.getCustomDomains().listByEndpointAsync(
Expand Down Expand Up @@ -137,7 +138,8 @@ public Mono<CdnEndpoint> updateResourceAsync() {
this.parent().resourceGroupName(),
this.parent().name(),
this.name(),
self.parent().manager().sdkContext().randomResourceName("CustomDomain", 50),
self.parent().manager().resourceManager().sdkContext()
.randomResourceName("CustomDomain", 50),
itemToCreate.hostname()
), 32, 32);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ private String generateUniqueEndpointName(String endpointNamePrefix) {
CheckNameAvailabilityResult result;

do {
endpointName = this.getParent().manager().sdkContext().randomResourceName(endpointNamePrefix, 50);
endpointName = this.getParent().manager().resourceManager().sdkContext()
.randomResourceName(endpointNamePrefix, 50);
result = this.getParent().checkEndpointNameAvailability(endpointName);
} while (!result.nameAvailable());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.azure.resourcemanager.resources.fluentcore.utils.SdkContext;
import com.azure.resourcemanager.test.ResourceManagerTestBase;
import com.azure.resourcemanager.test.utils.TestDelayProvider;
import com.azure.resourcemanager.test.utils.TestIdentifierProvider;

import java.time.temporal.ChronoUnit;
import java.util.List;
Expand Down Expand Up @@ -46,10 +45,8 @@ protected HttpPipeline buildHttpPipeline(
@Override
protected void initializeClients(HttpPipeline httpPipeline, AzureProfile profile) {
SdkContext.setDelayProvider(new TestDelayProvider(!isPlaybackMode()));
SdkContext sdkContext = new SdkContext();
sdkContext.setIdentifierFunction(name -> new TestIdentifierProvider(testResourceNamer));
resourceManager =
ResourceManager.authenticate(httpPipeline, profile).withSdkContext(sdkContext).withDefaultSubscription();
cdnManager = CdnManager.authenticate(httpPipeline, profile, sdkContext);
ResourceManager.authenticate(httpPipeline, profile).withDefaultSubscription();
cdnManager = CdnManager.authenticate(httpPipeline, profile);
}
}
25 changes: 25 additions & 0 deletions sdk/resourcemanager/azure-resourcemanager-compute/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,31 @@
</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.msi/com.azure.resourcemanager.msi=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
</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
Expand Down
Loading

0 comments on commit 298fb25

Please sign in to comment.