Search in sources :

Example 1 with SingularityAuthorizationScope

use of com.hubspot.singularity.SingularityAuthorizationScope in project Singularity by HubSpot.

the class SingularityClient method isUserAuthorized.

// 
// Auth
// 
/**
 * Check if a user is authorized for the specified scope on the specified request
 *
 * @param requestId
 *    The request to check authorization on
 * @param userId
 *    The user whose authorization will be checked
 * @param scope
 *    The scope to check that `user` has
 *
 * @return
 *    true if the user is authorized for scope, false otherwise
 */
public boolean isUserAuthorized(String requestId, String userId, SingularityAuthorizationScope scope) {
    final Function<String, String> requestUri = (host) -> String.format(AUTH_CHECK_USER_FORMAT, getApiBase(host), requestId, userId);
    Map<String, Object> params = Collections.singletonMap("scope", scope.name());
    HttpResponse response = executeGetSingleWithParams(requestUri, "auth check", "", Optional.of(params));
    return response.isSuccess();
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) Arrays(java.util.Arrays) Method(com.hubspot.horizon.HttpRequest.Method) ExtendedTaskState(com.hubspot.singularity.ExtendedTaskState) SingularityTaskCleanupResult(com.hubspot.singularity.SingularityTaskCleanupResult) SingularityPaginatedResponse(com.hubspot.singularity.SingularityPaginatedResponse) SingularityWebhook(com.hubspot.singularity.SingularityWebhook) Provider(javax.inject.Provider) Retryer(com.github.rholder.retry.Retryer) RetryerBuilder(com.github.rholder.retry.RetryerBuilder) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) RetryException(com.github.rholder.retry.RetryException) Inject(com.google.inject.Inject) SingularityRequestCleanup(com.hubspot.singularity.SingularityRequestCleanup) SingularityState(com.hubspot.singularity.SingularityState) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) SingularityTaskReconciliationStatistics(com.hubspot.singularity.SingularityTaskReconciliationStatistics) SingularityRequestGroup(com.hubspot.singularity.SingularityRequestGroup) SingularityDisasterType(com.hubspot.singularity.SingularityDisasterType) SingularityBounceRequest(com.hubspot.singularity.api.SingularityBounceRequest) SingularityPauseRequest(com.hubspot.singularity.api.SingularityPauseRequest) SingularityUpdateGroupsRequest(com.hubspot.singularity.api.SingularityUpdateGroupsRequest) Optional(com.google.common.base.Optional) Map(java.util.Map) HttpRequest(com.hubspot.horizon.HttpRequest) HttpClient(com.hubspot.horizon.HttpClient) TypeReference(com.fasterxml.jackson.core.type.TypeReference) SingularityPriorityFreeze(com.hubspot.singularity.api.SingularityPriorityFreeze) SingularityDisabledAction(com.hubspot.singularity.SingularityDisabledAction) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) SingularityUnpauseRequest(com.hubspot.singularity.api.SingularityUnpauseRequest) SingularityMachineChangeRequest(com.hubspot.singularity.api.SingularityMachineChangeRequest) SingularityDisastersData(com.hubspot.singularity.SingularityDisastersData) ImmutableMap(com.google.common.collect.ImmutableMap) SingularityPriorityFreezeParent(com.hubspot.singularity.SingularityPriorityFreezeParent) Predicate(java.util.function.Predicate) Collection(java.util.Collection) SingularityUpdatePendingDeployRequest(com.hubspot.singularity.SingularityUpdatePendingDeployRequest) List(java.util.List) SingularityTaskShellCommandRequest(com.hubspot.singularity.SingularityTaskShellCommandRequest) SingularityTaskShellCommandUpdate(com.hubspot.singularity.SingularityTaskShellCommandUpdate) StopStrategies(com.github.rholder.retry.StopStrategies) SingularityClusterUtilization(com.hubspot.singularity.SingularityClusterUtilization) OrderDirection(com.hubspot.singularity.OrderDirection) SingularityAuthorizationScope(com.hubspot.singularity.SingularityAuthorizationScope) Entry(java.util.Map.Entry) SingularitySandbox(com.hubspot.singularity.SingularitySandbox) SingularityS3Log(com.hubspot.singularity.SingularityS3Log) SingularityDisabledActionRequest(com.hubspot.singularity.api.SingularityDisabledActionRequest) SingularityCreateResult(com.hubspot.singularity.SingularityCreateResult) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) SingularityShellCommand(com.hubspot.singularity.SingularityShellCommand) SingularityRequestHistory(com.hubspot.singularity.SingularityRequestHistory) SingularityTaskIdHistory(com.hubspot.singularity.SingularityTaskIdHistory) SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) SingularityTaskShellCommandHistory(com.hubspot.singularity.SingularityTaskShellCommandHistory) HashMap(java.util.HashMap) SingularityClientCredentials(com.hubspot.singularity.SingularityClientCredentials) SingularityDeployUpdate(com.hubspot.singularity.SingularityDeployUpdate) Function(java.util.function.Function) SingularityTaskIdsByStatus(com.hubspot.singularity.SingularityTaskIdsByStatus) SingularityTaskState(com.hubspot.singularity.SingularityTaskState) SingularityExitCooldownRequest(com.hubspot.singularity.api.SingularityExitCooldownRequest) ArrayList(java.util.ArrayList) Builder(com.google.common.collect.ImmutableMap.Builder) ImmutableList(com.google.common.collect.ImmutableList) SingularitySlave(com.hubspot.singularity.SingularitySlave) SingularityDeleteResult(com.hubspot.singularity.SingularityDeleteResult) SingularityDeployKey(com.hubspot.singularity.SingularityDeployKey) RetryStrategy(com.hubspot.horizon.RetryStrategy) HttpResponse(com.hubspot.horizon.HttpResponse) SingularityPendingRequestParent(com.hubspot.singularity.SingularityPendingRequestParent) WaitStrategies(com.github.rholder.retry.WaitStrategies) SingularityAction(com.hubspot.singularity.SingularityAction) SingularityDeployHistory(com.hubspot.singularity.SingularityDeployHistory) Logger(org.slf4j.Logger) SingularityTaskHistory(com.hubspot.singularity.SingularityTaskHistory) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) SingularityRack(com.hubspot.singularity.SingularityRack) ExecutionException(java.util.concurrent.ExecutionException) SingularityKillTaskRequest(com.hubspot.singularity.api.SingularityKillTaskRequest) SingularityTaskRequest(com.hubspot.singularity.SingularityTaskRequest) MachineState(com.hubspot.singularity.MachineState) SingularityRequestParent(com.hubspot.singularity.SingularityRequestParent) SingularityDeleteRequestRequest(com.hubspot.singularity.api.SingularityDeleteRequestRequest) SingularityRunNowRequest(com.hubspot.singularity.api.SingularityRunNowRequest) Named(com.google.inject.name.Named) SingularityScaleRequest(com.hubspot.singularity.api.SingularityScaleRequest) MesosFileChunkObject(com.hubspot.mesos.json.MesosFileChunkObject) Collections(java.util.Collections) HttpResponse(com.hubspot.horizon.HttpResponse) MesosFileChunkObject(com.hubspot.mesos.json.MesosFileChunkObject)

Aggregations

TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 RetryException (com.github.rholder.retry.RetryException)1 Retryer (com.github.rholder.retry.Retryer)1 RetryerBuilder (com.github.rholder.retry.RetryerBuilder)1 StopStrategies (com.github.rholder.retry.StopStrategies)1 WaitStrategies (com.github.rholder.retry.WaitStrategies)1 Optional (com.google.common.base.Optional)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Builder (com.google.common.collect.ImmutableMap.Builder)1 Inject (com.google.inject.Inject)1 Named (com.google.inject.name.Named)1 HttpClient (com.hubspot.horizon.HttpClient)1 HttpRequest (com.hubspot.horizon.HttpRequest)1 Method (com.hubspot.horizon.HttpRequest.Method)1 HttpResponse (com.hubspot.horizon.HttpResponse)1 RetryStrategy (com.hubspot.horizon.RetryStrategy)1 MesosFileChunkObject (com.hubspot.mesos.json.MesosFileChunkObject)1 ExtendedTaskState (com.hubspot.singularity.ExtendedTaskState)1