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);
}
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()));
}
});
}
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);
}
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);
}
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);
}
}
Aggregations