com.azure.resourcemanager.servicebus.implementation.AuthorizationRuleBaseImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-resourcemanager-servicebus Show documentation
Show all versions of azure-resourcemanager-servicebus Show documentation
This package contains Microsoft Azure ServiceBus Management SDK. For documentation on how to use this package, please see https://aka.ms/azsdk/java/mgmt
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.resourcemanager.servicebus.implementation;
import com.azure.resourcemanager.resources.fluentcore.arm.models.HasResourceGroup;
import com.azure.resourcemanager.resources.fluentcore.arm.models.IndependentChildResource;
import com.azure.resourcemanager.resources.fluentcore.arm.models.Resource;
import com.azure.resourcemanager.resources.fluentcore.arm.models.implementation.IndependentChildResourceImpl;
import com.azure.resourcemanager.servicebus.fluent.models.AccessKeysInner;
import com.azure.resourcemanager.servicebus.fluent.models.SBAuthorizationRuleInner;
import com.azure.resourcemanager.servicebus.models.AccessRights;
import com.azure.resourcemanager.servicebus.models.AuthorizationKeys;
import com.azure.resourcemanager.servicebus.models.KeyType;
import com.azure.resourcemanager.servicebus.models.RegenerateAccessKeyParameters;
import reactor.core.publisher.Mono;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Base type for various entity specific authorization rules.
*
* @param the rule fluent interface
* @param the rule parent fluent interface
* @param the rule inner model
* @param the parent fluent implementation
* @param the manager
*/
abstract class AuthorizationRuleBaseImpl<
FluentModelT extends IndependentChildResource,
FluentParentModelT extends Resource & HasResourceGroup,
InnerModelT extends SBAuthorizationRuleInner,
FluentModelImplT extends IndependentChildResourceImpl<
FluentModelT,
FluentParentModelT,
InnerModelT,
FluentModelImplT,
ManagerT>,
ManagerT> extends IndependentChildResourceImpl {
protected AuthorizationRuleBaseImpl(String name, InnerModelT innerObject, ManagerT manager) {
super(name, innerObject, manager);
}
/**
* @return stream that emits primary, secondary keys and connection strings
*/
public Mono getKeysAsync() {
return this.getKeysInnerAsync()
.map(inner -> new AuthorizationKeysImpl(inner));
}
/**
* @return primary, secondary keys and connection strings
*/
public AuthorizationKeys getKeys() {
return getKeysAsync().block();
}
public Mono regenerateKeyAsync(RegenerateAccessKeyParameters regenerateAccessKeyParameters) {
return this.regenerateKeysInnerAsync(regenerateAccessKeyParameters)
.map(AuthorizationKeysImpl::new);
}
public AuthorizationKeys regenerateKey(RegenerateAccessKeyParameters regenerateAccessKeyParameters) {
return regenerateKeyAsync(regenerateAccessKeyParameters).block();
}
public Mono regenerateKeyAsync(KeyType keyType) {
return this.regenerateKeysInnerAsync(new RegenerateAccessKeyParameters().withKeyType(keyType))
.map(AuthorizationKeysImpl::new);
}
public AuthorizationKeys regenerateKey(KeyType keyType) {
return regenerateKeyAsync(keyType).block();
}
public List rights() {
if (this.innerModel().rights() == null) {
return Collections.unmodifiableList(new ArrayList());
}
return Collections.unmodifiableList(this.innerModel().rights());
}
@SuppressWarnings("unchecked")
public FluentModelImplT withListeningEnabled() {
if (this.innerModel().rights() == null) {
this.innerModel().withRights(new ArrayList());
}
if (!this.innerModel().rights().contains(AccessRights.LISTEN)) {
this.innerModel().rights().add(AccessRights.LISTEN);
}
return (FluentModelImplT) this;
}
@SuppressWarnings("unchecked")
public FluentModelImplT withSendingEnabled() {
if (this.innerModel().rights() == null) {
this.innerModel().withRights(new ArrayList());
}
if (!this.innerModel().rights().contains(AccessRights.SEND)) {
this.innerModel().rights().add(AccessRights.SEND);
}
return (FluentModelImplT) this;
}
@SuppressWarnings("unchecked")
public FluentModelImplT withManagementEnabled() {
withListeningEnabled();
withSendingEnabled();
if (!this.innerModel().rights().contains(AccessRights.MANAGE)) {
this.innerModel().rights().add(AccessRights.MANAGE);
}
return (FluentModelImplT) this;
}
protected abstract Mono getKeysInnerAsync();
protected abstract Mono regenerateKeysInnerAsync(RegenerateAccessKeyParameters regenerateAccessKeyParameters);
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy