Search in sources :

Example 21 with OrganizationEntry

use of com.walmartlabs.concord.server.org.OrganizationEntry in project concord by walmartlabs.

the class InventoryDataResource method delete.

/**
 * Deletes inventory data
 *
 * @param orgName       organization's name
 * @param inventoryName inventory's name
 * @param itemPath      inventory's data path
 * @return
 */
@DELETE
@ApiOperation("Delete inventory data")
@Path("/{orgName}/inventory/{inventoryName}/data/{itemPath:.*}")
@Produces(MediaType.APPLICATION_JSON)
public DeleteInventoryDataResponse delete(@ApiParam @PathParam("orgName") String orgName, @ApiParam @PathParam("inventoryName") String inventoryName, @ApiParam @PathParam("itemPath") String itemPath) {
    OrganizationEntry org = orgManager.assertAccess(orgName, true);
    JsonStoreEntry inventory = inventoryManager.assertAccess(org.getId(), null, inventoryName, ResourceAccessLevel.WRITER, true);
    inventoryDataDao.delete(inventory.id(), itemPath);
    return new DeleteInventoryDataResponse();
}
Also used : JsonStoreEntry(com.walmartlabs.concord.server.org.jsonstore.JsonStoreEntry) OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry) ApiOperation(io.swagger.annotations.ApiOperation)

Example 22 with OrganizationEntry

use of com.walmartlabs.concord.server.org.OrganizationEntry in project concord by walmartlabs.

the class InventoryDataResource method list.

/**
 * Returns all inventory data for inventory.
 *
 * @param orgName       organization's name
 * @param inventoryName inventory's name
 * @return
 */
@GET
@ApiOperation("List inventory data")
@Path("/{orgName}/inventory/{inventoryName}/data")
@Produces(MediaType.APPLICATION_JSON)
public List<Map<String, Object>> list(@ApiParam @PathParam("orgName") String orgName, @ApiParam @PathParam("inventoryName") String inventoryName) {
    OrganizationEntry org = orgManager.assertAccess(orgName, true);
    JsonStoreEntry inventory = inventoryManager.assertAccess(org.getId(), null, inventoryName, ResourceAccessLevel.READER, true);
    return inventoryDataDao.list(inventory.id());
}
Also used : JsonStoreEntry(com.walmartlabs.concord.server.org.jsonstore.JsonStoreEntry) OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry) ApiOperation(io.swagger.annotations.ApiOperation)

Example 23 with OrganizationEntry

use of com.walmartlabs.concord.server.org.OrganizationEntry in project concord by walmartlabs.

the class InventoryDataResource method data.

/**
 * Modifies inventory data
 *
 * @param orgName       organization's name
 * @param inventoryName inventory's name
 * @param itemPath      inventory's data path
 * @param data          inventory's data
 * @return full inventory data by path
 */
@POST
@ApiOperation("Modify inventory data")
@Path("/{orgName}/inventory/{inventoryName}/data/{itemPath:.*}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Object data(@ApiParam @PathParam("orgName") String orgName, @ApiParam @PathParam("inventoryName") String inventoryName, @ApiParam @PathParam("itemPath") String itemPath, @ApiParam Object data) {
    // we expect all top-level entries to be JSON objects
    if (!itemPath.contains("/") && !(data instanceof Map)) {
        throw new ValidationErrorsException("Top-level inventory entries must be JSON objects. Got: " + data.getClass());
    }
    OrganizationEntry org = orgManager.assertAccess(orgName, true);
    JsonStoreEntry inventory = inventoryManager.assertAccess(org.getId(), null, inventoryName, ResourceAccessLevel.WRITER, true);
    inventoryDataDao.merge(inventory.id(), itemPath, data);
    return build(inventory.id(), itemPath);
}
Also used : JsonStoreEntry(com.walmartlabs.concord.server.org.jsonstore.JsonStoreEntry) Map(java.util.Map) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException) OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry) ApiOperation(io.swagger.annotations.ApiOperation)

Example 24 with OrganizationEntry

use of com.walmartlabs.concord.server.org.OrganizationEntry in project concord by walmartlabs.

the class ConsoleService method isRepositoryExists.

@GET
@Path("/org/{orgName}/project/{projectName}/repo/{repoName}/exists")
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public boolean isRepositoryExists(@PathParam("orgName") @ConcordKey String orgName, @PathParam("projectName") @ConcordKey String projectName, @PathParam("repoName") String repoName) {
    try {
        OrganizationEntry org = orgManager.assertAccess(orgName, true);
        UUID projectId = projectDao.getId(org.getId(), projectName);
        if (projectId == null) {
            throw new ConcordApplicationException("Project not found: " + projectName, Status.BAD_REQUEST);
        }
        return repositoryDao.getId(projectId, repoName) != null;
    } catch (UnauthorizedException e) {
        return false;
    }
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UnauthorizedException(org.apache.shiro.authz.UnauthorizedException) OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 25 with OrganizationEntry

use of com.walmartlabs.concord.server.org.OrganizationEntry in project concord by walmartlabs.

the class UserDao method getUserInfo.

private UserEntry getUserInfo(DSLContext tx, Record7<UUID, String, String, String, String, String, Boolean> r) {
    // TODO join?
    Field<String> orgNameField = select(ORGANIZATIONS.ORG_NAME).from(ORGANIZATIONS).where(ORGANIZATIONS.ORG_ID.eq(TEAMS.ORG_ID)).asField();
    SelectConditionStep<Record1<UUID>> teamIds = select(V_USER_TEAMS.TEAM_ID).from(V_USER_TEAMS).where(V_USER_TEAMS.USER_ID.eq(r.get(USERS.USER_ID)));
    List<OrganizationEntry> orgs = tx.selectDistinct(TEAMS.ORG_ID, orgNameField).from(TEAMS).where(TEAMS.TEAM_ID.in(teamIds)).fetch(e -> new OrganizationEntry(e.value1(), e.value2(), null, null, null, null));
    SelectConditionStep<Record1<String[]>> permissions = select(arrayAgg(PERMISSIONS.PERMISSION_NAME)).from(PERMISSIONS).where(PERMISSIONS.PERMISSION_ID.in(select(ROLE_PERMISSIONS.PERMISSION_ID).from(ROLE_PERMISSIONS).where(ROLE_PERMISSIONS.ROLE_ID.in(ROLES.ROLE_ID))));
    SelectConditionStep<Record1<UUID>> roleIds = select(USER_ROLES.ROLE_ID).from(USER_ROLES).where(USER_ROLES.USER_ID.eq(r.get(USERS.USER_ID)));
    List<RoleEntry> roles = tx.select(ROLES.ROLE_ID, ROLES.ROLE_NAME, isnull(permissions.asField(), new String[] {})).from(ROLES).where(ROLES.ROLE_ID.in(roleIds)).fetch(e -> new RoleEntry(e.value1(), e.value2(), new HashSet<>(Arrays.asList(e.value3()))));
    return new UserEntry(r.get(USERS.USER_ID), r.get(USERS.USERNAME), r.get(USERS.DOMAIN), r.get(USERS.DISPLAY_NAME), new HashSet<>(orgs), UserType.valueOf(r.get(USERS.USER_TYPE)), r.get(USERS.USER_EMAIL), new HashSet<>(roles), r.get(USERS.IS_DISABLED));
}
Also used : OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry)

Aggregations

OrganizationEntry (com.walmartlabs.concord.server.org.OrganizationEntry)36 ApiOperation (io.swagger.annotations.ApiOperation)12 UUID (java.util.UUID)12 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)8 UnauthorizedException (org.apache.shiro.authz.UnauthorizedException)6 GenericOperationResult (com.walmartlabs.concord.server.GenericOperationResult)5 JsonStoreEntry (com.walmartlabs.concord.server.org.jsonstore.JsonStoreEntry)5 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)5 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)3 UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)3 Validate (org.sonatype.siesta.Validate)3 Map (java.util.Map)2 OperationResult (com.walmartlabs.concord.server.OperationResult)1 AuditObject (com.walmartlabs.concord.server.audit.AuditObject)1 RawPayloadMode (com.walmartlabs.concord.server.jooq.enums.RawPayloadMode)1 ResourceAccessLevel (com.walmartlabs.concord.server.org.ResourceAccessLevel)1 ProjectEntry (com.walmartlabs.concord.server.org.project.ProjectEntry)1 MetadataFilter (com.walmartlabs.concord.server.process.queue.ProcessFilter.MetadataFilter)1 InvalidRepositoryPathException (com.walmartlabs.concord.server.repository.InvalidRepositoryPathException)1 UserEntry (com.walmartlabs.concord.server.user.UserEntry)1