@Override public BucketTaggingConfiguration getBucketTaggingConfiguration(GetBucketTaggingConfigurationRequest getBucketTaggingConfigurationRequest) { getBucketTaggingConfigurationRequest = beforeClientExecution(getBucketTaggingConfigurationRequest); rejectNull(getBucketTaggingConfigurationRequest, "The request object parameter getBucketTaggingConfigurationRequest must be specifed."); String bucketName = getBucketTaggingConfigurationRequest.getBucketName(); rejectNull(bucketName, "The bucket name must be specified when retrieving the bucket tagging configuration."); Request<GetBucketTaggingConfigurationRequest> request = createRequest(bucketName, null, getBucketTaggingConfigurationRequest, HttpMethodName.GET); request.addParameter("tagging", null); try { return invoke(request, new Unmarshallers.BucketTaggingConfigurationUnmarshaller(), bucketName, null); } catch (AmazonServiceException ase) { switch (ase.getStatusCode()) { case 404: return null; default: throw ase; } } }
public Bucket createBucketForInstance(String instanceId, ServiceDefinition service, String planId, String organizationGuid, String spaceGuid) { String bucketName = getBucketNameForInstance(instanceId); logger.info("Creating bucket '{}' for serviceInstanceId '{}'", bucketName, instanceId); Bucket bucket = s3.createBucket(bucketName, Region.fromValue(region)); // TODO allow for additional, custom tagging options BucketTaggingConfiguration bucketTaggingConfiguration = new BucketTaggingConfiguration(); TagSet tagSet = new TagSet(); tagSet.setTag("serviceInstanceId", instanceId); tagSet.setTag("serviceDefinitionId", service.getId()); tagSet.setTag("planId", planId); tagSet.setTag("organizationGuid", organizationGuid); tagSet.setTag("spaceGuid", spaceGuid); bucketTaggingConfiguration.withTagSets(tagSet); s3.setBucketTaggingConfiguration(bucket.getName(), bucketTaggingConfiguration); return bucket; }
private ServiceInstance createServiceInstance(BucketTaggingConfiguration taggingConfiguration) { // While the Java API has multiple TagSets, it would appear from // http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUTtagging.html // that only one TagSet is supported. TagSet tagSet = taggingConfiguration.getTagSet(); String serviceInstanceId = tagSet.getTag("serviceInstanceId"); if (serviceInstanceId == null) { // could occur if someone used this broker AWS ID to a bucket // outside of the broker process return null; } String serviceDefinitionId = tagSet.getTag("serviceDefinitionId"); String planId = tagSet.getTag("planId"); String organizationGuid = tagSet.getTag("organizationGuid"); String spaceGuid = tagSet.getTag("spaceGuid"); ServiceInstance serviceInstance = new ServiceInstance(serviceInstanceId, serviceDefinitionId, planId, organizationGuid, spaceGuid, null); return serviceInstance; }
@Override public void setBucketTaggingConfiguration( SetBucketTaggingConfigurationRequest setBucketTaggingConfigurationRequest) { setBucketTaggingConfigurationRequest = beforeClientExecution(setBucketTaggingConfigurationRequest); rejectNull(setBucketTaggingConfigurationRequest, "The set bucket tagging configuration request object must be specified."); String bucketName = setBucketTaggingConfigurationRequest.getBucketName(); BucketTaggingConfiguration bucketTaggingConfiguration = setBucketTaggingConfigurationRequest.getTaggingConfiguration(); rejectNull(bucketName, "The bucket name parameter must be specified when setting bucket tagging configuration."); rejectNull(bucketTaggingConfiguration, "The tagging configuration parameter must be specified when setting bucket tagging configuration."); Request<SetBucketTaggingConfigurationRequest> request = createRequest(bucketName, null, setBucketTaggingConfigurationRequest, HttpMethodName.PUT); request.addParameter("tagging", null); byte[] content = new BucketConfigurationXmlFactory().convertToXmlByteArray(bucketTaggingConfiguration); request.addHeader("Content-Length", String.valueOf(content.length)); request.addHeader("Content-Type", "application/xml"); request.setContent(new ByteArrayInputStream(content)); try { byte[] md5 = Md5Utils.computeMD5Hash(content); String md5Base64 = BinaryUtils.toBase64(md5); request.addHeader("Content-MD5", md5Base64); } catch ( Exception e ) { throw new SdkClientException("Couldn't compute md5 sum", e); } invoke(request, voidResponseHandler, bucketName, null); }
/** * Converts the specified {@link BucketTaggingConfiguration} object to an XML fragment that * can be sent to Amazon S3. * * @param config * The {@link BucketTaggingConfiguration} */ /* * <Tagging> <TagSet> <Tag> <Key>Project</Key> <Value>Foo</Value> </Tag> <Tag> <Key>User</Key> <Value>nschnarr</Value> </Tag> </TagSet> </Tagging> */ public byte[] convertToXmlByteArray(BucketTaggingConfiguration config) throws SdkClientException { XmlWriter xml = new XmlWriter(); xml.start("Tagging"); for (TagSet tagset : config.getAllTagSets()) { writeRule(xml, tagset); } xml.end(); return xml.getBytes(); }
private void createS3BucketAndTags(Map<String, String> tags) { this.s3Client.createBucket(TEST_BUCKET_NAME); TagSet tagSet = new TagSet(tags); BucketTaggingConfiguration bucketTaggingConfiguration = new BucketTaggingConfiguration(Collections.singletonList(tagSet)); this.s3Client.setBucketTaggingConfiguration(TEST_BUCKET_NAME, bucketTaggingConfiguration); }
public ServiceInstance findServiceInstance(String instanceId) { String bucketName = getBucketNameForInstance(instanceId); if (s3.doesBucketExist(bucketName)) { BucketTaggingConfiguration taggingConfiguration = s3.getBucketTaggingConfiguration(bucketName); return createServiceInstance(taggingConfiguration); } return null; }
public List<ServiceInstance> getAllServiceInstances() { List<ServiceInstance> serviceInstances = Lists.newArrayList(); for (Bucket bucket : s3.listBuckets()) { BucketTaggingConfiguration taggingConfiguration = s3.getBucketTaggingConfiguration(bucket.getName()); ServiceInstance serviceInstance = createServiceInstance(taggingConfiguration); serviceInstances.add(serviceInstance); } return serviceInstances; }
@Override public BucketTaggingConfiguration getBucketTaggingConfiguration(String bucketName) { return delegate.getBucketTaggingConfiguration(bucketName); }
@Override public void setBucketTaggingConfiguration(String bucketName, BucketTaggingConfiguration bucketTaggingConfiguration) { delegate.setBucketTaggingConfiguration(bucketName, bucketTaggingConfiguration); }
@Override public BucketTaggingConfiguration getBucketTaggingConfiguration(GetBucketTaggingConfigurationRequest getBucketTaggingConfigurationRequest) { return delegate.getBucketTaggingConfiguration(getBucketTaggingConfigurationRequest); }
@Override public BucketTaggingConfiguration getBucketTaggingConfiguration(String bucketName) { return getBucketTaggingConfiguration(new GetBucketTaggingConfigurationRequest(bucketName)); }
@Override public void setBucketTaggingConfiguration(String bucketName, BucketTaggingConfiguration bucketTaggingConfiguration) { setBucketTaggingConfiguration(new SetBucketTaggingConfigurationRequest(bucketName, bucketTaggingConfiguration)); }
@Override public BucketTaggingConfiguration getBucketTaggingConfiguration(String bucketName) { return call(() -> getDelegate().getBucketTaggingConfiguration(bucketName)); }
@Override public BucketTaggingConfiguration getBucketTaggingConfiguration(GetBucketTaggingConfigurationRequest getBucketTaggingConfigurationRequest) { return call(() -> getDelegate().getBucketTaggingConfiguration(getBucketTaggingConfigurationRequest)); }
@Override public void setBucketTaggingConfiguration(String bucketName, BucketTaggingConfiguration bucketTaggingConfiguration) { run(() -> getDelegate().setBucketTaggingConfiguration(bucketName, bucketTaggingConfiguration)); }
@Override public BucketTaggingConfiguration getBucketTaggingConfiguration(String bucketName) { return null; }
@Override public void setBucketTaggingConfiguration(String bucketName, BucketTaggingConfiguration bucketTaggingConfiguration) { }
public void createTags(String bucketName, TagSet tags) { logger.info("tag s3 bucket, bucketName={}", bucketName); s3.setBucketTaggingConfiguration(bucketName, new BucketTaggingConfiguration().withTagSets(tags)); }
@Override public BucketTaggingConfiguration getBucketTaggingConfiguration(String bucketName) { // TODO Auto-generated method stub return null; }
@Override public void setBucketTaggingConfiguration(String bucketName, BucketTaggingConfiguration bucketTaggingConfiguration) { // TODO Auto-generated method stub }