All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.microsoft.azure.management.graphrbac.implementation.ServicePrincipalsImpl Maven / Gradle / Ivy

Go to download

This package contains Microsoft Azure Graph RBAC Management SDK. This package has been deprecated. A replacement package com.azure.resourcemanager:azure-resourcemanager-authorization 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.

There is a newer version: 1.41.4
Show newest version
/**
 * 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.graphrbac.implementation;

import com.microsoft.azure.Page;
import com.microsoft.azure.PagedList;
import com.microsoft.azure.management.apigeneration.LangDefinition;
import com.microsoft.azure.management.graphrbac.ServicePrincipal;
import com.microsoft.azure.management.graphrbac.ServicePrincipals;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.CreatableWrappersImpl;
import com.microsoft.azure.management.resources.fluentcore.arm.models.HasManager;
import com.microsoft.azure.management.resources.fluentcore.model.HasInner;
import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceFuture;
import com.microsoft.rest.ServiceResponse;
import rx.Completable;
import rx.Observable;
import rx.functions.Func1;

/**
 * The implementation of ServicePrincipals and its parent interfaces.
 */
@LangDefinition(ContainerName = "/Microsoft.Azure.Management.Graph.RBAC.Fluent")
class ServicePrincipalsImpl
        extends CreatableWrappersImpl<
            ServicePrincipal,
            ServicePrincipalImpl,
            ServicePrincipalInner>
        implements
            ServicePrincipals,
            HasManager,
            HasInner {
    private final PagedListConverter converter;
    private ServicePrincipalsInner innerCollection;
    private GraphRbacManager manager;

    ServicePrincipalsImpl(
            final ServicePrincipalsInner client,
            final GraphRbacManager graphRbacManager) {
        this.innerCollection = client;
        this.manager = graphRbacManager;
        converter = new PagedListConverter() {
            @Override
            public Observable typeConvertAsync(ServicePrincipalInner servicePrincipalInner) {
                ServicePrincipalImpl impl = wrapModel(servicePrincipalInner);
                return impl.refreshCredentialsAsync();
            }
        };
    }

    @Override
    public PagedList list() {
        return converter.convert(this.inner().list());
    }

    @Override
    public Observable listAsync() {
        return wrapPageAsync(this.inner().listAsync())
                .flatMap(new Func1>() {
                    @Override
                    public Observable call(ServicePrincipal servicePrincipal) {
                        return ((ServicePrincipalImpl) servicePrincipal).refreshCredentialsAsync();
                    }
                });
    }

    @Override
    protected ServicePrincipalImpl wrapModel(ServicePrincipalInner servicePrincipalInner) {
        if (servicePrincipalInner == null) {
            return null;
        }
        return new ServicePrincipalImpl(servicePrincipalInner, manager());
    }

    @Override
    public ServicePrincipalImpl getById(String id) {
        return (ServicePrincipalImpl) getByIdAsync(id).toBlocking().single();
    }

    @Override
    public Observable getByIdAsync(String id) {
        return innerCollection.getAsync(id)
                .flatMap(new Func1>() {
                    @Override
                    public Observable call(ServicePrincipalInner servicePrincipalInner) {
                        if (servicePrincipalInner == null) {
                            return Observable.just(null);
                        } else {
                            return new ServicePrincipalImpl(servicePrincipalInner, manager()).refreshCredentialsAsync();
                        }
                    }
                });
    }

    @Override
    public ServiceFuture getByIdAsync(String id, ServiceCallback callback) {
        return ServiceFuture.fromBody(getByIdAsync(id), callback);
    }

    @Override
    public ServicePrincipal getByName(String spn) {
        return getByNameAsync(spn).toBlocking().single();
    }

    @Override
    public Observable getByNameAsync(final String name) {
        return innerCollection.listWithServiceResponseAsync(String.format("servicePrincipalNames/any(c:c eq '%s')", name))
                .flatMap(new Func1>, Observable>>() {
                    @Override
                    public Observable> call(ServiceResponse> result) {
                        if (result == null || result.body().items() == null || result.body().items().isEmpty()) {
                            return innerCollection.listAsync(String.format("displayName eq '%s'", name));
                        }
                        return Observable.just(result.body());
                    }
                }).map(new Func1, ServicePrincipalImpl>() {
                    @Override
                    public ServicePrincipalImpl call(Page result) {
                        if (result == null || result.items() == null || result.items().isEmpty()) {
                            return null;
                        }
                        return new ServicePrincipalImpl(result.items().get(0), manager());
                    }
                }).flatMap(new Func1>() {
                    @Override
                    public Observable call(ServicePrincipalImpl servicePrincipal) {
                        if (servicePrincipal == null) {
                            return Observable.just(null);
                        }
                        return servicePrincipal.refreshCredentialsAsync();
                    }
                });
    }

    @Override
    public GraphRbacManager manager() {
        return this.manager;
    }

    @Override
    public ServicePrincipalsInner inner() {
        return this.innerCollection;
    }

    @Override
    public ServicePrincipalImpl define(String name) {
        return new ServicePrincipalImpl((ServicePrincipalInner) new ServicePrincipalInner().withDisplayName(name), manager());
    }

    @Override
    protected ServicePrincipalImpl wrapModel(String name) {
        return new ServicePrincipalImpl((ServicePrincipalInner) new ServicePrincipalInner().withDisplayName(name), manager());
    }

    @Override
    public Completable deleteByIdAsync(String id) {
        return manager().inner().servicePrincipals().deleteAsync(id).toCompletable();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy