com.microsoft.azure.management.eventhub.implementation.AuthorizationRuleBaseImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-mgmt-eventhub Show documentation
Show all versions of azure-mgmt-eventhub Show documentation
This package contains Microsoft EventHub Management SDK. This package has been deprecated. A replacement package com.azure.resourcemanager:azure-resourcemanager-eventhubs is available as of 31-March-2022. We strongly encourage you to upgrade to continue receiving updates. See Migration Guide https://aka.ms/java-track2-migration-guide for guidance on upgrading. Refer to our deprecation policy https://azure.github.io/azure-sdk/policies_support.html for more details.
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
package com.microsoft.azure.management.eventhub.implementation;
import com.microsoft.azure.management.apigeneration.LangDefinition;
import com.microsoft.azure.management.eventhub.AccessRights;
import com.microsoft.azure.management.eventhub.AuthorizationRule;
import com.microsoft.azure.management.eventhub.EventHubAuthorizationKey;
import com.microsoft.azure.management.eventhub.KeyType;
import com.microsoft.azure.management.resources.fluentcore.model.implementation.IndexableRefreshableWrapperImpl;
import rx.Observable;
import rx.functions.Func1;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Base implementation for authorization rule.
* (Internal use only)
*
* @param rule fluent model
* @param implementation of rule fluent model
*/
@LangDefinition
abstract class AuthorizationRuleBaseImpl, RuleImpl extends IndexableRefreshableWrapperImpl>
extends NestedResourceImpl implements AuthorizationRule {
protected AuthorizationRuleBaseImpl(String name, AuthorizationRuleInner inner, EventHubManager manager) {
super(name, inner, manager);
}
@Override
public Observable getKeysAsync() {
return this.getKeysInnerAsync()
.map(new Func1() {
@Override
public EventHubAuthorizationKey call(AccessKeysInner inner) {
return new EventHubAuthorizationKeyImpl(inner);
}
});
}
@Override
public EventHubAuthorizationKey getKeys() {
return getKeysAsync().toBlocking().last();
}
@Override
public Observable regenerateKeyAsync(KeyType keyType) {
return this.regenerateKeysInnerAsync(keyType)
.map(new Func1() {
@Override
public EventHubAuthorizationKey call(AccessKeysInner inner) {
return new EventHubAuthorizationKeyImpl(inner);
}
});
}
@Override
public EventHubAuthorizationKey regenerateKey(KeyType keyType) {
return regenerateKeyAsync(keyType).toBlocking().last();
}
@Override
public List rights() {
if (this.inner().rights() == null) {
return Collections.unmodifiableList(new ArrayList());
}
return Collections.unmodifiableList(this.inner().rights());
}
@SuppressWarnings("unchecked")
public RuleImpl withListenAccess() {
if (this.inner().rights() == null) {
this.inner().withRights(new ArrayList());
}
if (!this.inner().rights().contains(AccessRights.LISTEN)) {
this.inner().rights().add(AccessRights.LISTEN);
}
return (RuleImpl) this;
}
@SuppressWarnings("unchecked")
public RuleImpl withSendAccess() {
if (this.inner().rights() == null) {
this.inner().withRights(new ArrayList());
}
if (!this.inner().rights().contains(AccessRights.SEND)) {
this.inner().rights().add(AccessRights.SEND);
}
return (RuleImpl) this;
}
@SuppressWarnings("unchecked")
public RuleImpl withSendAndListenAccess() {
withListenAccess();
withSendAccess();
return (RuleImpl) this;
}
@SuppressWarnings("unchecked")
public RuleImpl withManageAccess() {
withListenAccess();
withSendAccess();
if (!this.inner().rights().contains(AccessRights.MANAGE)) {
this.inner().rights().add(AccessRights.MANAGE);
}
return (RuleImpl) this;
}
protected abstract Observable getKeysInnerAsync();
protected abstract Observable regenerateKeysInnerAsync(KeyType keyType);
protected abstract Observable getInnerAsync();
public abstract Observable createResourceAsync();
}