Search in sources :

Example 6 with Tenant

use of com.yahoo.vespa.hosted.controller.api.Tenant in project vespa by vespa-engine.

the class ApplicationApiHandler method authenticatedUser.

private HttpResponse authenticatedUser(HttpRequest request) {
    String userIdString = request.getProperty("userOverride");
    if (userIdString == null)
        userIdString = getUserId(request).map(UserId::id).orElseThrow(() -> new ForbiddenException("You must be authenticated or specify userOverride"));
    UserId userId = new UserId(userIdString);
    List<Tenant> tenants = controller.tenants().asList(userId);
    Slime slime = new Slime();
    Cursor response = slime.setObject();
    response.setString("user", userId.id());
    Cursor tenantsArray = response.setArray("tenants");
    for (Tenant tenant : tenants) tenantInTenantsListToSlime(tenant, request.getUri(), tenantsArray.addObject());
    response.setBool("tenantExists", tenants.stream().map(Tenant::getId).anyMatch(id -> id.isTenantFor(userId)));
    return new SlimeJsonResponse(slime);
}
Also used : AlreadyExistsException(com.yahoo.vespa.hosted.controller.AlreadyExistsException) EndpointStatus(com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus) Inject(com.google.inject.Inject) URISyntaxException(java.net.URISyntaxException) SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) Scanner(java.util.Scanner) DeploymentJobs(com.yahoo.vespa.hosted.controller.application.DeploymentJobs) ConfigServerException(com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServerException) RegionName(com.yahoo.config.provision.RegionName) TenantName(com.yahoo.config.provision.TenantName) ResourceResponse(com.yahoo.vespa.hosted.controller.restapi.ResourceResponse) Tenant(com.yahoo.vespa.hosted.controller.api.Tenant) ZoneId(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId) ClusterUtilization(com.yahoo.vespa.hosted.controller.application.ClusterUtilization) Duration(java.time.Duration) Map(java.util.Map) LogLevel(com.yahoo.log.LogLevel) Path(com.yahoo.vespa.hosted.controller.restapi.Path) JobStatus(com.yahoo.vespa.hosted.controller.application.JobStatus) GitRevision(com.yahoo.vespa.hosted.controller.api.application.v4.model.GitRevision) ClusterCost(com.yahoo.vespa.hosted.controller.application.ClusterCost) BadRequestException(javax.ws.rs.BadRequestException) DeployOptions(com.yahoo.vespa.hosted.controller.api.application.v4.model.DeployOptions) URI(java.net.URI) DeploymentCost(com.yahoo.vespa.hosted.controller.application.DeploymentCost) ScrewdriverBuildJob(com.yahoo.vespa.hosted.controller.api.application.v4.model.ScrewdriverBuildJob) Exceptions(com.yahoo.yolean.Exceptions) AthenzDomain(com.yahoo.vespa.athenz.api.AthenzDomain) ImmutableSet(com.google.common.collect.ImmutableSet) Inspector(com.yahoo.slime.Inspector) NotExistsException(com.yahoo.vespa.hosted.controller.NotExistsException) ApplicationVersion(com.yahoo.vespa.hosted.controller.application.ApplicationVersion) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) ErrorResponse(com.yahoo.vespa.hosted.controller.restapi.ErrorResponse) RestartAction(com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbindings.RestartAction) Property(com.yahoo.vespa.hosted.controller.api.identifiers.Property) ApplicationView(com.yahoo.vespa.serviceview.bindings.ApplicationView) Objects(java.util.Objects) ZmsException(com.yahoo.vespa.hosted.controller.api.integration.athenz.ZmsException) List(java.util.List) Principal(java.security.Principal) AthenzPrincipal(com.yahoo.vespa.athenz.api.AthenzPrincipal) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) Optional(java.util.Optional) Deployment(com.yahoo.vespa.hosted.controller.application.Deployment) HttpResponse(com.yahoo.container.jdisc.HttpResponse) Controller(com.yahoo.vespa.hosted.controller.Controller) Joiner(com.google.common.base.Joiner) Log(com.yahoo.vespa.hosted.controller.api.integration.configserver.Log) AthenzClientFactory(com.yahoo.vespa.hosted.controller.api.integration.athenz.AthenzClientFactory) GitRepository(com.yahoo.vespa.hosted.controller.api.identifiers.GitRepository) ApplicationName(com.yahoo.config.provision.ApplicationName) AthenzUser(com.yahoo.vespa.athenz.api.AthenzUser) Version(com.yahoo.component.Version) ApplicationId(com.yahoo.config.provision.ApplicationId) PropertyId(com.yahoo.vespa.hosted.controller.api.identifiers.PropertyId) RefeedAction(com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbindings.RefeedAction) DeploymentId(com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId) Slime(com.yahoo.slime.Slime) AthenzIdentity(com.yahoo.vespa.athenz.api.AthenzIdentity) IOUtils(com.yahoo.io.IOUtils) NToken(com.yahoo.vespa.athenz.api.NToken) Level(java.util.logging.Level) DeploymentMetrics(com.yahoo.vespa.hosted.controller.application.DeploymentMetrics) ApplicationResource(com.yahoo.vespa.hosted.controller.api.application.v4.ApplicationResource) SlimeUtils(com.yahoo.vespa.config.SlimeUtils) Change(com.yahoo.vespa.hosted.controller.application.Change) TenantId(com.yahoo.vespa.hosted.controller.api.identifiers.TenantId) GitBranch(com.yahoo.vespa.hosted.controller.api.identifiers.GitBranch) ServiceInfo(com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbindings.ServiceInfo) SetBouncerPassthruHeaderFilter(com.yahoo.vespa.hosted.controller.restapi.filter.SetBouncerPassthruHeaderFilter) EnvironmentResource(com.yahoo.vespa.hosted.controller.api.application.v4.EnvironmentResource) TenantResource(com.yahoo.vespa.hosted.controller.api.application.v4.TenantResource) Application(com.yahoo.vespa.hosted.controller.Application) ActivateResult(com.yahoo.vespa.hosted.controller.api.ActivateResult) Cursor(com.yahoo.slime.Cursor) StringResponse(com.yahoo.vespa.hosted.controller.restapi.StringResponse) ForbiddenException(javax.ws.rs.ForbiddenException) Hostname(com.yahoo.vespa.hosted.controller.api.identifiers.Hostname) Environment(com.yahoo.config.provision.Environment) GitCommit(com.yahoo.vespa.hosted.controller.api.identifiers.GitCommit) HttpRequest(com.yahoo.container.jdisc.HttpRequest) SourceRevision(com.yahoo.vespa.hosted.controller.application.SourceRevision) IOException(java.io.IOException) MessageResponse(com.yahoo.vespa.hosted.controller.restapi.MessageResponse) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage) LoggingRequestHandler(com.yahoo.container.jdisc.LoggingRequestHandler) User(com.yahoo.vespa.hosted.controller.api.integration.organization.User) UserId(com.yahoo.vespa.hosted.controller.api.identifiers.UserId) RotationStatus(com.yahoo.vespa.hosted.controller.api.integration.routing.RotationStatus) DeploymentSpec(com.yahoo.config.application.api.DeploymentSpec) DayOfWeek(java.time.DayOfWeek) ScrewdriverId(com.yahoo.vespa.hosted.controller.api.identifiers.ScrewdriverId) Collections(java.util.Collections) InputStream(java.io.InputStream) ForbiddenException(javax.ws.rs.ForbiddenException) Tenant(com.yahoo.vespa.hosted.controller.api.Tenant) SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) UserId(com.yahoo.vespa.hosted.controller.api.identifiers.UserId) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 7 with Tenant

use of com.yahoo.vespa.hosted.controller.api.Tenant in project vespa by vespa-engine.

the class ApplicationApiHandler method verifyApplicationIdentityConfiguration.

private void verifyApplicationIdentityConfiguration(String tenantName, Optional<ApplicationPackage> applicationPackage) {
    // Validate that domain in identity configuration (deployment.xml) is same as tenant domain
    applicationPackage.map(ApplicationPackage::deploymentSpec).flatMap(DeploymentSpec::athenzDomain).ifPresent(identityDomain -> {
        Tenant tenant = controller.tenants().tenant(new TenantId(tenantName)).orElseThrow(() -> new IllegalArgumentException("Tenant does not exist"));
        AthenzDomain tenantDomain = tenant.getAthensDomain().orElseThrow(() -> new IllegalArgumentException("Identity provider only available to Athenz onboarded tenants"));
        if (!Objects.equals(tenantDomain.getName(), identityDomain.value())) {
            throw new ForbiddenException(String.format("Athenz domain in deployment.xml: [%s] must match tenant domain: [%s]", identityDomain.value(), tenantDomain.getName()));
        }
    });
}
Also used : TenantId(com.yahoo.vespa.hosted.controller.api.identifiers.TenantId) ForbiddenException(javax.ws.rs.ForbiddenException) Tenant(com.yahoo.vespa.hosted.controller.api.Tenant) AthenzDomain(com.yahoo.vespa.athenz.api.AthenzDomain) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage)

Example 8 with Tenant

use of com.yahoo.vespa.hosted.controller.api.Tenant in project vespa by vespa-engine.

the class ApplicationApiHandler method deleteTenant.

private HttpResponse deleteTenant(String tenantName, HttpRequest request) {
    Optional<Tenant> tenant = controller.tenants().tenant(new TenantId(tenantName));
    // NOTE: The Jersey implementation would silently ignore this
    if (!tenant.isPresent())
        return ErrorResponse.notFoundError("Could not delete tenant '" + tenantName + "': Tenant not found");
    controller.tenants().deleteTenant(new TenantId(tenantName), getUserPrincipal(request).getNToken());
    // TODO: Change to a message response saying the tenant was deleted
    return tenant(tenant.get(), request, false);
}
Also used : TenantId(com.yahoo.vespa.hosted.controller.api.identifiers.TenantId) Tenant(com.yahoo.vespa.hosted.controller.api.Tenant)

Example 9 with Tenant

use of com.yahoo.vespa.hosted.controller.api.Tenant in project vespa by vespa-engine.

the class ApplicationApiHandler method tenants.

private HttpResponse tenants(HttpRequest request) {
    Slime slime = new Slime();
    Cursor response = slime.setArray();
    for (Tenant tenant : controller.tenants().asList()) tenantInTenantsListToSlime(tenant, request.getUri(), response.addObject());
    return new SlimeJsonResponse(slime);
}
Also used : Tenant(com.yahoo.vespa.hosted.controller.api.Tenant) SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 10 with Tenant

use of com.yahoo.vespa.hosted.controller.api.Tenant in project vespa by vespa-engine.

the class DeploymentIssueReporter method fileDeploymentIssueFor.

/**
 * File an issue for applicationId, if it doesn't already have an open issue associated with it.
 */
private void fileDeploymentIssueFor(ApplicationId applicationId) {
    try {
        Tenant tenant = ownerOf(applicationId);
        Optional<IssueId> ourIssueId = controller().applications().require(applicationId).deploymentJobs().issueId();
        IssueId issueId = tenant.tenantType() == TenantType.USER ? deploymentIssues.fileUnlessOpen(ourIssueId, applicationId, userFor(tenant)) : deploymentIssues.fileUnlessOpen(ourIssueId, applicationId, propertyIdFor(tenant));
        store(applicationId, issueId);
    } catch (RuntimeException e) {
        // Catch errors due to wrong data in the controller, or issues client timeout.
        log.log(Level.WARNING, "Exception caught when attempting to file an issue for " + applicationId, e);
    }
}
Also used : Tenant(com.yahoo.vespa.hosted.controller.api.Tenant) IssueId(com.yahoo.vespa.hosted.controller.api.integration.organization.IssueId)

Aggregations

Tenant (com.yahoo.vespa.hosted.controller.api.Tenant)18 TenantId (com.yahoo.vespa.hosted.controller.api.identifiers.TenantId)11 AthenzDomain (com.yahoo.vespa.athenz.api.AthenzDomain)7 Inspector (com.yahoo.slime.Inspector)5 Cursor (com.yahoo.slime.Cursor)4 Slime (com.yahoo.slime.Slime)4 NToken (com.yahoo.vespa.athenz.api.NToken)4 Lock (com.yahoo.vespa.curator.Lock)4 EndpointStatus (com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus)4 Version (com.yahoo.component.Version)3 DeploymentSpec (com.yahoo.config.application.api.DeploymentSpec)3 ApplicationId (com.yahoo.config.provision.ApplicationId)3 Environment (com.yahoo.config.provision.Environment)3 TenantName (com.yahoo.config.provision.TenantName)3 ActivateResult (com.yahoo.vespa.hosted.controller.api.ActivateResult)3 DeployOptions (com.yahoo.vespa.hosted.controller.api.application.v4.model.DeployOptions)3 DeploymentId (com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId)3 Property (com.yahoo.vespa.hosted.controller.api.identifiers.Property)3 ApplicationPackage (com.yahoo.vespa.hosted.controller.application.ApplicationPackage)3 SlimeJsonResponse (com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse)3