Search in sources :

Example 1 with Application

use of com.netflix.spinnaker.fiat.model.resources.Application in project fiat by spinnaker.

the class DefaultApplicationResourceProvider method loadAll.

@Override
protected Set<Application> loadAll() throws ProviderException {
    try {
        List<Application> front50Applications = front50Service.getAllApplications();
        List<Application> clouddriverApplications = clouddriverService.getApplications();
        // Stream front50 first so that if there's a name collision, we'll keep that one instead of
        // the clouddriver application (since front50 might have permissions stored on it, but the
        // clouddriver version definitely won't)
        List<Application> applications = Streams.concat(front50Applications.stream(), clouddriverApplications.stream()).filter(distinctByKey(a -> a.getName().toUpperCase())).collect(toImmutableList());
        applications.forEach(application -> {
            Permissions permissions = permissionProvider.getPermissions(application);
            // Check to see if we need to fallback permissions to the configured fallback
            application.setPermissions(executeFallbackPermissionsResolver.shouldResolve(permissions) ? executeFallbackPermissionsResolver.resolve(permissions) : permissions);
        });
        if (allowAccessToUnknownApplications) {
            // unknown applications by default
            return applications.stream().filter(a -> a.getPermissions().isRestricted()).collect(toImmutableSet());
        } else {
            return ImmutableSet.copyOf(applications);
        }
    } catch (RuntimeException e) {
        throw new ProviderException(this.getClass(), e);
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Predicate(java.util.function.Predicate) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) Streams(com.google.common.collect.Streams) Application(com.netflix.spinnaker.fiat.model.resources.Application) Function(java.util.function.Function) Permissions(com.netflix.spinnaker.fiat.model.resources.Permissions) HashSet(java.util.HashSet) List(java.util.List) ClouddriverService(com.netflix.spinnaker.fiat.providers.internal.ClouddriverService) Role(com.netflix.spinnaker.fiat.model.resources.Role) FallbackPermissionsResolver(com.netflix.spinnaker.fiat.permissions.FallbackPermissionsResolver) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Front50Service(com.netflix.spinnaker.fiat.providers.internal.Front50Service) Collections(java.util.Collections) Permissions(com.netflix.spinnaker.fiat.model.resources.Permissions) Application(com.netflix.spinnaker.fiat.model.resources.Application)

Aggregations

ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 Streams (com.google.common.collect.Streams)1 Application (com.netflix.spinnaker.fiat.model.resources.Application)1 Permissions (com.netflix.spinnaker.fiat.model.resources.Permissions)1 Role (com.netflix.spinnaker.fiat.model.resources.Role)1 FallbackPermissionsResolver (com.netflix.spinnaker.fiat.permissions.FallbackPermissionsResolver)1 ClouddriverService (com.netflix.spinnaker.fiat.providers.internal.ClouddriverService)1 Front50Service (com.netflix.spinnaker.fiat.providers.internal.Front50Service)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1