Search in sources :

Example 1 with ConcordKey

use of com.walmartlabs.concord.common.validation.ConcordKey in project concord by walmartlabs.

the class SecretResource method getData.

@POST
@ApiOperation(value = "Get an existing secret's data", response = File.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = File.class, responseHeaders = @ResponseHeader(name = "X-Concord-SecretType", description = "Secret type", response = String.class)) })
@Path("/{orgName}/secret/{secretName}/data")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@WithTimer
public Response getData(@ApiParam @PathParam("orgName") @ConcordKey String orgName, @ApiParam @PathParam("secretName") @ConcordKey String secretName, @ApiParam MultipartInput input) {
    OrganizationEntry org = orgManager.assertAccess(orgName, false);
    String password = MultipartUtils.getString(input, Constants.Multipart.STORE_PASSWORD);
    SecretDao.SecretDataEntry entry;
    try {
        entry = secretManager.getRaw(SecretManager.AccessScope.apiRequest(), org.getId(), secretName, password);
        if (entry == null) {
            throw new WebApplicationException("Secret not found: " + secretName, Status.NOT_FOUND);
        }
    } catch (SecurityException e) {
        log.warn("fetchSecret -> error: {}", e.getMessage());
        throw new SecretException("Error while fetching a secret '" + secretName + "': " + e.getMessage());
    } catch (ValidationErrorsException e) {
        log.warn("fetchSecret -> error: {}", e.getMessage());
        return null;
    }
    try {
        return Response.ok((StreamingOutput) output -> output.write(entry.getData()), MediaType.APPLICATION_OCTET_STREAM).header(Constants.Headers.SECRET_TYPE, entry.getType().name()).build();
    } catch (Exception e) {
        log.error("fetchSecret ['{}'] -> error while fetching a secret", secretName, e);
        throw new ConcordApplicationException("Error while fetching a secret '" + secretName + "': " + e.getMessage());
    }
}
Also used : Resource(org.sonatype.siesta.Resource) ConcordKey(com.walmartlabs.concord.common.validation.ConcordKey) UserType(com.walmartlabs.concord.server.user.UserType) LoggerFactory(org.slf4j.LoggerFactory) MultipartInput(org.jboss.resteasy.plugins.providers.multipart.MultipartInput) GenericOperationResult(com.walmartlabs.concord.server.GenericOperationResult) DecryptedKeyPair(com.walmartlabs.concord.server.org.secret.SecretManager.DecryptedKeyPair) Singleton(javax.inject.Singleton) Inject(javax.inject.Inject) Valid(javax.validation.Valid) MultipartUtils(com.walmartlabs.concord.server.MultipartUtils) OperationResult(com.walmartlabs.concord.server.OperationResult) MediaType(javax.ws.rs.core.MediaType) Constants(com.walmartlabs.concord.sdk.Constants) ByteArrayInputStream(java.io.ByteArrayInputStream) TeamDao(com.walmartlabs.concord.server.org.team.TeamDao) DecryptedUsernamePassword(com.walmartlabs.concord.server.org.secret.SecretManager.DecryptedUsernamePassword) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) io.swagger.annotations(io.swagger.annotations) Named(javax.inject.Named) Status(javax.ws.rs.core.Response.Status) UserManager(com.walmartlabs.concord.server.user.UserManager) Logger(org.slf4j.Logger) Collection(java.util.Collection) Validate(org.sonatype.siesta.Validate) StreamingOutput(javax.ws.rs.core.StreamingOutput) IOException(java.io.IOException) UUID(java.util.UUID) com.walmartlabs.concord.server.org(com.walmartlabs.concord.server.org) File(java.io.File) DecryptedBinaryData(com.walmartlabs.concord.server.org.secret.SecretManager.DecryptedBinaryData) Objects(java.util.Objects) ProjectDao(com.walmartlabs.concord.server.org.project.ProjectDao) List(java.util.List) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) InputStream(java.io.InputStream) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException) IOException(java.io.IOException) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Aggregations

ConcordKey (com.walmartlabs.concord.common.validation.ConcordKey)1 Constants (com.walmartlabs.concord.sdk.Constants)1 GenericOperationResult (com.walmartlabs.concord.server.GenericOperationResult)1 MultipartUtils (com.walmartlabs.concord.server.MultipartUtils)1 OperationResult (com.walmartlabs.concord.server.OperationResult)1 com.walmartlabs.concord.server.org (com.walmartlabs.concord.server.org)1 ProjectDao (com.walmartlabs.concord.server.org.project.ProjectDao)1 DecryptedBinaryData (com.walmartlabs.concord.server.org.secret.SecretManager.DecryptedBinaryData)1 DecryptedKeyPair (com.walmartlabs.concord.server.org.secret.SecretManager.DecryptedKeyPair)1 DecryptedUsernamePassword (com.walmartlabs.concord.server.org.secret.SecretManager.DecryptedUsernamePassword)1 TeamDao (com.walmartlabs.concord.server.org.team.TeamDao)1 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)1 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)1 UserManager (com.walmartlabs.concord.server.user.UserManager)1 UserType (com.walmartlabs.concord.server.user.UserType)1 io.swagger.annotations (io.swagger.annotations)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1