Search in sources :

Example 1 with DataPutBucketTagging

use of com.pspace.ifs.ksan.gw.data.DataPutBucketTagging in project ksan by infinistor.

the class PutBucketTagging method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_PUT_BUCKET_TAGGING_START);
    String bucket = s3Parameter.getBucketName();
    initBucketInfo(bucket);
    S3Bucket s3Bucket = new S3Bucket();
    s3Bucket.setCors(getBucketInfo().getCors());
    s3Bucket.setAccess(getBucketInfo().getAccess());
    s3Parameter.setBucket(s3Bucket);
    GWUtils.checkCors(s3Parameter);
    if (s3Parameter.isPublicAccess() && GWUtils.isIgnorePublicAcls(s3Parameter)) {
        throw new GWException(GWErrorCode.ACCESS_DENIED, s3Parameter);
    }
    checkGrantBucketOwner(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_WRITE_ACP);
    DataPutBucketTagging dataPutBucketTagging = new DataPutBucketTagging(s3Parameter);
    dataPutBucketTagging.extract();
    String taggingXml = dataPutBucketTagging.getTaggingXml();
    logger.debug(GWConstants.LOG_PUT_BUCKET_TAGGING, taggingXml);
    try {
        Tagging tagging = new XmlMapper().readValue(taggingXml, Tagging.class);
        // 중복 지우기 item이 10개 미만이기 때문에 for loop가 빠름
        if (tagging != null) {
            if (tagging.tagset != null && tagging.tagset.tags != null) {
                for (Tag t : tagging.tagset.tags) {
                    // key, value 길이 체크
                    if (t.key.length() > 128) {
                        throw new GWException(GWErrorCode.INVALID_TAG, s3Parameter);
                    }
                    if (t.value.length() > 256) {
                        throw new GWException(GWErrorCode.INVALID_TAG, s3Parameter);
                    }
                }
            }
            if (tagging.tagset != null && tagging.tagset.tags != null) {
                if (tagging.tagset.tags.size() > 10) {
                    throw new GWException(GWErrorCode.BAD_REQUEST, s3Parameter);
                }
            }
        }
    } catch (IOException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    }
    updateBucketTagging(bucket, taggingXml);
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Also used : S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) DataPutBucketTagging(com.pspace.ifs.ksan.gw.data.DataPutBucketTagging) Tagging(com.pspace.ifs.ksan.gw.format.Tagging) DataPutBucketTagging(com.pspace.ifs.ksan.gw.data.DataPutBucketTagging) GWException(com.pspace.ifs.ksan.gw.exception.GWException) Tag(com.pspace.ifs.ksan.gw.format.Tagging.TagSet.Tag) IOException(java.io.IOException) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Aggregations

XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1 DataPutBucketTagging (com.pspace.ifs.ksan.gw.data.DataPutBucketTagging)1 GWException (com.pspace.ifs.ksan.gw.exception.GWException)1 Tagging (com.pspace.ifs.ksan.gw.format.Tagging)1 Tag (com.pspace.ifs.ksan.gw.format.Tagging.TagSet.Tag)1 S3Bucket (com.pspace.ifs.ksan.gw.identity.S3Bucket)1 IOException (java.io.IOException)1