Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ abstract class WebAppBaseImpl<FluentT extends WebAppBase, FluentImplT extends We
private boolean diagnosticLogsToUpdate;
private FunctionalTaskItem msiHandler;
private boolean isInCreateMode;
private WebAppMsiHandler webAppMsiHandler;
private WebAppMsiHandler<FluentT, FluentImplT> webAppMsiHandler;

WebAppBaseImpl(
String name,
Expand All @@ -151,7 +151,7 @@ abstract class WebAppBaseImpl<FluentT extends WebAppBase, FluentImplT extends We
this.diagnosticLogs = new WebAppDiagnosticLogsImpl<>(logConfig, this);
}

webAppMsiHandler = new WebAppMsiHandler(manager.authorizationManager(), this);
webAppMsiHandler = new WebAppMsiHandler<>(manager.authorizationManager(), this);
normalizeProperties();
isInCreateMode = inner() == null || inner().id() == null;
if (!isInCreateMode) {
Expand Down Expand Up @@ -199,8 +199,7 @@ public String resourceId() {
};
}

@SuppressWarnings("unchecked")
private FluentT normalizeProperties() {
private void normalizeProperties() {
this.hostNameBindingsToCreate = new TreeMap<>();
this.hostNameBindingsToDelete = new ArrayList<>();
this.appSettingsToAdd = new HashMap<>();
Expand Down Expand Up @@ -238,7 +237,6 @@ private FluentT normalizeProperties() {
}
}
this.webAppMsiHandler.clear();
return (FluentT) this;
}

@Override
Expand Down Expand Up @@ -843,7 +841,7 @@ public Mono<FluentT> createResourceAsync() {
@Override
@SuppressWarnings("unchecked")
public Mono<FluentT> updateResourceAsync() {
SiteInner siteInner = (SiteInner) this.inner();
SiteInner siteInner = this.inner();
SitePatchResourceInner siteUpdate = new SitePatchResourceInner();
siteUpdate.withHostnameSslStates(siteInner.hostnameSslStates());
siteUpdate.withKind(siteInner.kind());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.azure.resourcemanager.appservice.models.ManagedServiceIdentityUserAssignedIdentities;
import com.azure.resourcemanager.appservice.fluent.inner.SiteInner;
import com.azure.resourcemanager.appservice.fluent.inner.SitePatchResourceInner;
import com.azure.resourcemanager.appservice.models.WebAppBase;
import com.azure.resourcemanager.authorization.AuthorizationManager;
import com.azure.resourcemanager.authorization.implementation.RoleAssignmentHelper;
import com.azure.resourcemanager.msi.models.Identity;
Expand All @@ -27,11 +28,12 @@
* Utility class to set Managed Service Identity (MSI) property on a web app, install or update MSI extension and create
* role assignments for the service principal associated with the web app.
*/
public class WebAppMsiHandler extends RoleAssignmentHelper {
public class WebAppMsiHandler<FluentT extends WebAppBase, FluentImplT extends WebAppBaseImpl<FluentT, FluentImplT>>
extends RoleAssignmentHelper {

private final ClientLogger logger = new ClientLogger(getClass());

private WebAppBaseImpl webAppBase;
private WebAppBaseImpl<FluentT, FluentImplT> webAppBase;

private List<String> creatableIdentityKeys;
private Map<String, ManagedServiceIdentityUserAssignedIdentities> userAssignedIdentities;
Expand All @@ -43,7 +45,7 @@ public class WebAppMsiHandler extends RoleAssignmentHelper {
* @param webAppBase the web app to which MSI extension needs to be installed and for which role assignments needs
* to be created
*/
WebAppMsiHandler(final AuthorizationManager authorizationManager, WebAppBaseImpl webAppBase) {
WebAppMsiHandler(final AuthorizationManager authorizationManager, WebAppBaseImpl<FluentT, FluentImplT> webAppBase) {
super(authorizationManager, webAppBase.taskGroup(), webAppBase.idProvider());
this.webAppBase = webAppBase;
this.creatableIdentityKeys = new ArrayList<>();
Expand All @@ -56,7 +58,7 @@ public class WebAppMsiHandler extends RoleAssignmentHelper {
*
* @return WebAppMsiHandler
*/
WebAppMsiHandler withLocalManagedServiceIdentity() {
WebAppMsiHandler<FluentT, FluentImplT> withLocalManagedServiceIdentity() {
this.initSiteIdentity(ManagedServiceIdentityType.SYSTEM_ASSIGNED);
return this;
}
Expand All @@ -66,8 +68,8 @@ WebAppMsiHandler withLocalManagedServiceIdentity() {
*
* @return WebAppMsiHandler
*/
WebAppMsiHandler withoutLocalManagedServiceIdentity() {
SiteInner siteInner = (SiteInner) this.webAppBase.inner();
WebAppMsiHandler<FluentT, FluentImplT> withoutLocalManagedServiceIdentity() {
SiteInner siteInner = this.webAppBase.inner();

if (siteInner.identity() == null
|| siteInner.identity().type() == null
Expand All @@ -88,7 +90,7 @@ WebAppMsiHandler withoutLocalManagedServiceIdentity() {
* @param creatableIdentity yet-to-be-created identity to be associated with the virtual machine
* @return WebAppMsiHandler
*/
WebAppMsiHandler withNewExternalManagedServiceIdentity(Creatable<Identity> creatableIdentity) {
WebAppMsiHandler<FluentT, FluentImplT> withNewExternalManagedServiceIdentity(Creatable<Identity> creatableIdentity) {
this.initSiteIdentity(ManagedServiceIdentityType.USER_ASSIGNED);

TaskGroup.HasTaskGroup dependency = (TaskGroup.HasTaskGroup) creatableIdentity;
Expand All @@ -106,7 +108,7 @@ WebAppMsiHandler withNewExternalManagedServiceIdentity(Creatable<Identity> creat
* @param identity an identity to associate
* @return WebAppMsiHandler
*/
WebAppMsiHandler withExistingExternalManagedServiceIdentity(Identity identity) {
WebAppMsiHandler<FluentT, FluentImplT> withExistingExternalManagedServiceIdentity(Identity identity) {
this.initSiteIdentity(ManagedServiceIdentityType.USER_ASSIGNED);
this.userAssignedIdentities.put(identity.id(), new ManagedServiceIdentityUserAssignedIdentities());
return this;
Expand All @@ -119,7 +121,7 @@ WebAppMsiHandler withExistingExternalManagedServiceIdentity(Identity identity) {
* @param identityId resource id of the identity
* @return WebAppMsiHandler
*/
WebAppMsiHandler withoutExternalManagedServiceIdentity(String identityId) {
WebAppMsiHandler<FluentT, FluentImplT> withoutExternalManagedServiceIdentity(String identityId) {
this.userAssignedIdentities.put(identityId, null);
return this;
}
Expand All @@ -134,7 +136,7 @@ void processCreatedExternalIdentities() {
}

void handleExternalIdentities() {
SiteInner siteInner = (SiteInner) this.webAppBase.inner();
SiteInner siteInner = this.webAppBase.inner();
if (!this.userAssignedIdentities.isEmpty()) {
siteInner.identity().withUserAssignedIdentities(this.userAssignedIdentities);
}
Expand All @@ -157,7 +159,7 @@ void handleExternalIdentities(SitePatchResourceInner siteUpdate) {
// 4. User want to add and remove (all or subset) some identities in 'Site.Identity.userAssignedIdentities'
// [this.userAssignedIdentities.empty() == false and this.webAppBase.inner().identity() != null]
//
SiteInner siteInner = (SiteInner) this.webAppBase.inner();
SiteInner siteInner = this.webAppBase.inner();
ManagedServiceIdentity currentIdentity = siteInner.identity();
siteUpdate.withIdentity(currentIdentity);
if (!this.userAssignedIdentities.isEmpty()) {
Expand Down Expand Up @@ -187,7 +189,7 @@ void clear() {
* @return true if user indented to remove all the identities.
*/
private boolean handleRemoveAllExternalIdentitiesCase(SitePatchResourceInner siteUpdate) {
SiteInner siteInner = (SiteInner) this.webAppBase.inner();
SiteInner siteInner = this.webAppBase.inner();
if (!this.userAssignedIdentities.isEmpty()) {
int rmCount = 0;
for (ManagedServiceIdentityUserAssignedIdentities v : this.userAssignedIdentities.values()) {
Expand Down Expand Up @@ -260,7 +262,7 @@ private void initSiteIdentity(ManagedServiceIdentityType identityType) {
throw logger.logExceptionAsError(new IllegalArgumentException("Invalid argument: " + identityType));
}

SiteInner siteInner = (SiteInner) this.webAppBase.inner();
SiteInner siteInner = this.webAppBase.inner();
if (siteInner.identity() == null) {
siteInner.withIdentity(new ManagedServiceIdentity());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void canBindHostnameAndSsl() throws Exception {
// hostname binding shortcut
webApp.update().withManagedHostnameBindings(domain, webappName + "-1", webappName + "-2").apply();
if (!isPlaybackMode()) {
Response response = curl("http://" + webappName + "-1." + domainName);
Response<String> response = curl("http://" + webappName + "-1." + domainName);
Assertions.assertEquals(200, response.getStatusCode());
Assertions.assertNotNull(response.getValue());
response = curl("http://" + webappName + "-2." + domainName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Mono<ActiveDirectoryApplication> refreshCredentialsAsync() {
.map(
(Function<KeyCredentialInner, CertificateCredential>)
keyCredentialInner ->
new CertificateCredentialImpl<ActiveDirectoryApplication>(keyCredentialInner))
new CertificateCredentialImpl<ActiveDirectoryApplicationImpl>(keyCredentialInner))
.collectMap(certificateCredential -> certificateCredential.name())
.map(
stringCertificateCredentialMap -> {
Expand All @@ -94,7 +94,7 @@ Mono<ActiveDirectoryApplication> refreshCredentialsAsync() {
.map(
(Function<PasswordCredentialInner, PasswordCredential>)
passwordCredentialInner ->
new PasswordCredentialImpl<ActiveDirectoryApplication>(passwordCredentialInner))
new PasswordCredentialImpl<ActiveDirectoryApplicationImpl>(passwordCredentialInner))
.collectMap(passwordCredential -> passwordCredential.name())
.map(
stringPasswordCredentialMap -> {
Expand Down Expand Up @@ -133,15 +133,15 @@ public Set<String> identifierUris() {
if (inner().identifierUris() == null) {
return null;
}
return Collections.unmodifiableSet(new HashSet(inner().identifierUris()));
return Collections.unmodifiableSet(new HashSet<>(inner().identifierUris()));
}

@Override
public Set<String> replyUrls() {
if (inner().replyUrls() == null) {
return null;
}
return Collections.unmodifiableSet(new HashSet(inner().replyUrls()));
return Collections.unmodifiableSet(new HashSet<>(inner().replyUrls()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
import java.util.Base64;

/** Implementation for ServicePrincipal and its parent interfaces. */
class CertificateCredentialImpl<T> extends IndexableRefreshableWrapperImpl<CertificateCredential, KeyCredentialInner>
class CertificateCredentialImpl<T extends HasCredential<T>>
extends IndexableRefreshableWrapperImpl<CertificateCredential, KeyCredentialInner>
implements CertificateCredential, CertificateCredential.Definition<T>, CertificateCredential.UpdateDefinition<T> {

private String name;
private HasCredential<?> parent;
private HasCredential<T> parent;
private OutputStream authFile;
private String privateKeyPath;
private String privateKeyPassword;
Expand All @@ -39,7 +40,7 @@ class CertificateCredentialImpl<T> extends IndexableRefreshableWrapperImpl<Certi
}
}

CertificateCredentialImpl(String name, HasCredential<?> parent) {
CertificateCredentialImpl(String name, HasCredential<T> parent) {
super(
new KeyCredentialInner()
.withUsage("Verify")
Expand Down Expand Up @@ -76,10 +77,8 @@ public String value() {
}

@Override
@SuppressWarnings("unchecked")
public T attach() {
parent.withCertificateCredential(this);
return (T) parent;
return parent.withCertificateCredential(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
import java.util.Base64;

/** Implementation for ServicePrincipal and its parent interfaces. */
class PasswordCredentialImpl<T> extends IndexableRefreshableWrapperImpl<PasswordCredential, PasswordCredentialInner>
class PasswordCredentialImpl<T extends HasCredential<T>>
extends IndexableRefreshableWrapperImpl<PasswordCredential, PasswordCredentialInner>
implements PasswordCredential, PasswordCredential.Definition<T>, PasswordCredential.UpdateDefinition<T> {

private String name;
private HasCredential<?> parent;
private HasCredential<T> parent;
OutputStream authFile;
private String subscriptionId;
private final ClientLogger logger = new ClientLogger(PasswordCredentialImpl.class);
Expand All @@ -39,7 +40,7 @@ class PasswordCredentialImpl<T> extends IndexableRefreshableWrapperImpl<Password
}
}

PasswordCredentialImpl(String name, HasCredential<?> parent) {
PasswordCredentialImpl(String name, HasCredential<T> parent) {
super(
new PasswordCredentialInner()
.withCustomKeyIdentifier(Base64.getEncoder().encode(name.getBytes(StandardCharsets.UTF_8)))
Expand Down Expand Up @@ -75,10 +76,8 @@ public String value() {
}

@Override
@SuppressWarnings("unchecked")
public T attach() {
parent.withPasswordCredential(this);
return (T) parent;
return parent.withPasswordCredential(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Set<Permission> permissions() {

@Override
public Set<String> assignableScopes() {
return Collections.unmodifiableSet(new HashSet(inner().assignableScopes()));
return Collections.unmodifiableSet(new HashSet<>(inner().assignableScopes()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,13 @@ public Mono<ServicePrincipal> refreshAsync() {
}

@Override
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "rawtypes"})
public CertificateCredentialImpl defineCertificateCredential(String name) {
return new CertificateCredentialImpl<>(name, this);
}

@Override
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "rawtypes"})
public PasswordCredentialImpl definePasswordCredential(String name) {
return new PasswordCredentialImpl<>(name, this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected Mono<Void> deleteInnerAsync(String resourceGroupName, String name) {
}

@Override
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "rawtypes"})
public Flux<String> deleteByIdsAsync(Collection<String> ids) {
if (ids == null || ids.isEmpty()) {
return Flux.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public Mono<VirtualMachineExtension> createResourceAsync() {
}

@Override
@SuppressWarnings("unchecked")
public Mono<VirtualMachineExtension> updateResourceAsync() {
this.nullifySettingsIfEmpty();
if (this.isReference()) {
Expand Down Expand Up @@ -294,6 +295,7 @@ private void nullifySettingsIfEmpty() {
}
}

@SuppressWarnings("unchecked")
private void initializeSettings() {
if (this.inner().settings() == null) {
this.publicSettings = new LinkedHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public boolean autoUpgradeMinorVersionEnabled() {
}

@Override
@SuppressWarnings("unchecked")
public Map<String, Object> publicSettings() {
if (this.inner().settings() == null) {
return Collections.unmodifiableMap(new LinkedHashMap<String, Object>());
Expand Down Expand Up @@ -160,13 +161,15 @@ public VirtualMachineScaleSetImpl attach() {
// are used to ensure we initialize settings/protectedSettings of an extension only if user choose to update
// it.
//
@SuppressWarnings("unchecked")
private HashMap<String, Object> ensurePublicSettings() {
if (this.inner().settings() == null) {
this.inner().withSettings(new LinkedHashMap<String, Object>());
}
return (LinkedHashMap<String, Object>) this.inner().settings();
}

@SuppressWarnings("unchecked")
private HashMap<String, Object> ensureProtectedSettings() {
if (this.inner().protectedSettings() == null) {
this.inner().withProtectedSettings(new LinkedHashMap<String, Object>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -2211,10 +2212,8 @@ private static void removeInboundNatPoolsFromIpConfiguration(
}
}

private static <T> void addToList(List<T> list, T... items) {
for (T item : items) {
list.add(item);
}
private static <T> void addToList(List<T> list, T[] items) {
list.addAll(Arrays.asList(items));
}

private static String mergePath(String... segments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public Map<String, String> tags() {
return Collections.unmodifiableMap(this.inner().tags());
}

@SuppressWarnings("unchecked")
private void initializeSettings() {
if (this.inner().settings() == null) {
this.publicSettings = new LinkedHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public EncryptionStatus osDiskStatus() {
}

@Override
@SuppressWarnings("unchecked")
public EncryptionStatus dataDiskStatus() {
if (!hasEncryptionDetails()) {
return EncryptionStatus.NOT_ENCRYPTED;
Expand Down
Loading