com.microsoft.azure.management.eventhub.implementation.AuthorizationRuleBaseImpl Maven / Gradle / Ivy
/**
* 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();
}