java.security.KeyStore.SecretKeyEntry#com.amazonaws.util.Base64源码实例Demo

下面列出了java.security.KeyStore.SecretKeyEntry#com.amazonaws.util.Base64 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: presto   文件: TestPasswordAuthentication.java
@Test
public void test()
        throws IOException
{
    String json = new ObjectMapper().writeValueAsString(ImmutableMap.<String, Object>builder()
            .put("value", 42L)
            .build());

    client.getLowLevelClient()
            .performRequest(
                    "POST",
                    "/test/_doc?refresh",
                    ImmutableMap.of(),
                    new NStringEntity(json, ContentType.APPLICATION_JSON),
                    new BasicHeader("Authorization", format("Basic %s", Base64.encodeAsString(format("%s:%s", USER, PASSWORD).getBytes(StandardCharsets.UTF_8)))));

    assertThat(assertions.query("SELECT * FROM test"))
            .matches("VALUES BIGINT '42'");
}
 
/**
 * Calculate the secret hash to be sent along with the authentication request.
 *
 * @param userPoolClientId     : The client id of the app.
 * @param userPoolClientSecret : The secret for the userpool client id.
 * @param userName             : The username of the user trying to authenticate.
 * @return Calculated secret hash.
 */
private String calculateSecretHash(String userPoolClientId, String userPoolClientSecret, String userName) {
    final String HMAC_SHA256_ALGORITHM = "HmacSHA256";

    SecretKeySpec signingKey = new SecretKeySpec(
            userPoolClientSecret.getBytes(StandardCharsets.UTF_8),
            HMAC_SHA256_ALGORITHM);
    try {
        Mac mac = Mac.getInstance(HMAC_SHA256_ALGORITHM);
        mac.init(signingKey);
        mac.update(userName.getBytes(StandardCharsets.UTF_8));
        byte[] rawHmac = mac.doFinal(userPoolClientId.getBytes(StandardCharsets.UTF_8));
        return java.util.Base64.getEncoder().encodeToString(rawHmac);
    } catch (Exception e) {
        throw new RuntimeException("Error while calculating ");
    }
}
 
源代码3 项目: strongbox   文件: GetNewSecret.java
private SecretValue getSecretValue(ToggleGroup valueSource, String value, String generated, File file) {
    Toggle current = valueSource.getSelectedToggle();

    String secretString;
    if (current.getUserData().equals("value")) {
        secretString = value;
    } else if (current.getUserData().equals("generated")) {
        Integer numBytesToGenerate = Integer.valueOf(generated);
        // TODO: store as plain bytes?
        byte[] random = Singleton.randomGenerator.generateRandom(numBytesToGenerate);
        secretString = Base64.encodeAsString(random);
    } else {
        String path = null;
        try {
            path = file.getCanonicalPath();
            return SecretValueConverter.inferEncoding(Files.readAllBytes(Paths.get(path)), SecretType.OPAQUE);
        } catch (IOException e) {
            throw new RuntimeException("Failed to read secret from file");
        }
    }

    return new SecretValue(secretString, SecretType.OPAQUE);
}
 
源代码4 项目: bender   文件: Passwords.java
public static String decrypt(String str, Region region) throws UnsupportedEncodingException {
  if (isJUnitTest()) {
    return str;
  }

  AWSKMS kms = AWSKMSClientBuilder.standard().withRegion(region.getName()).build();

  /*
   * The KMS ciphertext is base64 encoded and must be decoded before the request is made
   */
  String cipherString = str;
  byte[] cipherBytes = Base64.decode(cipherString);

  /*
   * Create decode request and decode
   */
  ByteBuffer cipherBuffer = ByteBuffer.wrap(cipherBytes);
  DecryptRequest req = new DecryptRequest().withCiphertextBlob(cipherBuffer);
  DecryptResult resp = kms.decrypt(req);

  /*
   * Convert the response plaintext bytes to a string
   */
  return new String(resp.getPlaintext().array(), Charset.forName("UTF-8"));
}
 
源代码5 项目: snowflake-jdbc   文件: SnowflakeAzureClient.java
/**
 * Adds encryption metadata to the StorageObjectMetadata object
 */
@Override
public void addEncryptionMetadata(StorageObjectMetadata meta,
                                  MatDesc matDesc,
                                  byte[] ivData,
                                  byte[] encKeK,
                                  long contentLength)
{
  meta.addUserMetadata(getMatdescKey(),
                       matDesc.toString());
  meta.addUserMetadata(AZ_ENCRYPTIONDATAPROP, buildEncryptionMetadataJSON(
      Base64.encodeAsString(ivData),
      Base64.encodeAsString(encKeK))
  );
  meta.setContentLength(contentLength);
}
 
源代码6 项目: snowflake-jdbc   文件: StorageObjectSummary.java
private static String convertBase64ToHex(String base64String)
{
  try
  {
    byte[] bytes = Base64.decode(base64String);

    final StringBuilder builder = new StringBuilder();
    for (byte b : bytes)
    {
      builder.append(String.format("%02x", b));
    }
    return builder.toString();
    // return empty string if input is not a valid Base64 string
  }
  catch (Exception e)
  {
    return "";
  }
}
 
源代码7 项目: snowflake-jdbc   文件: SnowflakeGCSClient.java
/**
 * Adds encryption metadata to the StorageObjectMetadata object
 */
@Override
public void addEncryptionMetadata(StorageObjectMetadata meta,
                                  MatDesc matDesc,
                                  byte[] ivData,
                                  byte[] encKeK,
                                  long contentLength)
{
  meta.addUserMetadata(getMatdescKey(),
                       matDesc.toString());
  meta.addUserMetadata(GCS_ENCRYPTIONDATAPROP, buildEncryptionMetadataJSON(
      Base64.encodeAsString(ivData),
      Base64.encodeAsString(encKeK))
  );
  meta.setContentLength(contentLength);
}
 
源代码8 项目: snowflake-jdbc   文件: SnowflakeS3Client.java
/**
 * Adds encryption metadata to the StorageObjectMetadata object
 */
@Override
public void addEncryptionMetadata(StorageObjectMetadata meta,
                                  MatDesc matDesc,
                                  byte[] ivData,
                                  byte[] encKeK,
                                  long contentLength)
{
  meta.addUserMetadata(getMatdescKey(),
                       matDesc.toString());
  meta.addUserMetadata(AMZ_KEY,
                       Base64.encodeAsString(encKeK));
  meta.addUserMetadata(AMZ_IV,
                       Base64.encodeAsString(ivData));
  meta.setContentLength(contentLength);
}
 
源代码9 项目: beam   文件: S3WritableByteChannel.java
private void flush() throws IOException {
  uploadBuffer.flip();
  ByteArrayInputStream inputStream = new ByteArrayInputStream(uploadBuffer.array());

  UploadPartRequest request =
      new UploadPartRequest()
          .withBucketName(path.getBucket())
          .withKey(path.getKey())
          .withUploadId(uploadId)
          .withPartNumber(partNumber++)
          .withPartSize(uploadBuffer.remaining())
          .withMD5Digest(Base64.encodeAsString(md5.digest()))
          .withInputStream(inputStream);
  request.setSSECustomerKey(options.getSSECustomerKey());

  UploadPartResult result;
  try {
    result = amazonS3.uploadPart(request);
  } catch (AmazonClientException e) {
    throw new IOException(e);
  }
  uploadBuffer.clear();
  md5.reset();
  eTags.add(result.getPartETag());
}
 
源代码10 项目: fullstop   文件: FetchTaupageYamlImplTest.java
@Test
public void testBrokenYaml() throws Exception{
    // a yaml list is not a valid taupage format. Map is required.
    final String yamlData = "- a\n- b\n- c\n";

    when(amazonEC2ClientMock.describeInstanceAttribute(any())).thenReturn(new DescribeInstanceAttributeResult().
            withInstanceAttribute(new InstanceAttribute()
                    .withUserData(Base64.encodeAsString(yamlData.getBytes()))));

    final FetchTaupageYaml fetchTaupageYaml = new FetchTaupageYamlImpl(clientProviderMock);

    final Optional<TaupageYaml> result = fetchTaupageYaml.getTaupageYaml(INSTANCE_ID, ACCOUNT, REGION);

    assertThat(result).isEmpty();

    verify(amazonEC2ClientMock).describeInstanceAttribute(any());
}
 
源代码11 项目: fullstop   文件: TaupageYamlProviderImplTest.java
@Test
public void testApplyWithTaupageAmi() throws Exception {
    when(ec2InstanceContextMock.isTaupageAmi()).thenReturn(Optional.of(true));

    when(ec2InstanceContextMock.getInstanceId()).thenReturn(INSTANCE_ID);
    when(ec2InstanceContextMock.getClient(eq(AmazonEC2Client.class))).thenReturn(amazonEC2ClientMock);
    when(amazonEC2ClientMock.describeInstanceAttribute(any())).thenReturn(new DescribeInstanceAttributeResult().
            withInstanceAttribute(new InstanceAttribute()
                    .withUserData(Base64.encodeAsString("blub: fdsa".getBytes()))));

    final Optional<TaupageYaml> result = taupageYamlProvider.apply(ec2InstanceContextMock);

    assertThat(result).isPresent();


    verify(ec2InstanceContextMock).isTaupageAmi();
    verify(ec2InstanceContextMock).getInstanceId();
    verify(ec2InstanceContextMock).getClient(eq(AmazonEC2Client.class));
    verify(amazonEC2ClientMock).describeInstanceAttribute(any());
}
 
源代码12 项目: fullstop   文件: TaupageYamlProviderImplTest.java
@Test
public void testApplyWithVersionSimilarToNumber() throws Exception {
    when(ec2InstanceContextMock.isTaupageAmi()).thenReturn(Optional.of(true));

    when(ec2InstanceContextMock.getInstanceId()).thenReturn(INSTANCE_ID);
    when(ec2InstanceContextMock.getClient(eq(AmazonEC2Client.class))).thenReturn(amazonEC2ClientMock);
    when(amazonEC2ClientMock.describeInstanceAttribute(any())).thenReturn(new DescribeInstanceAttributeResult().
            withInstanceAttribute(new InstanceAttribute()
                    .withUserData(Base64.encodeAsString("application_id: fdsa\napplication_version: 6478e18".getBytes()))));

    final Optional<TaupageYaml> result = taupageYamlProvider.apply(ec2InstanceContextMock);

    assertThat(result).isPresent();

    assertThat(result.get().getApplicationId()).isEqualTo("fdsa");
    assertThat(result.get().getApplicationVersion()).isEqualTo("6478e18");

    verify(ec2InstanceContextMock).isTaupageAmi();
    verify(ec2InstanceContextMock).getInstanceId();
    verify(ec2InstanceContextMock).getClient(eq(AmazonEC2Client.class));
    verify(amazonEC2ClientMock).describeInstanceAttribute(any());
}
 
源代码13 项目: fullstop   文件: TaupageYamlProviderImplTest.java
@Test
public void testApplyWithVersionSimilarToNumber1() throws Exception {
    when(ec2InstanceContextMock.isTaupageAmi()).thenReturn(Optional.of(true));

    when(ec2InstanceContextMock.getInstanceId()).thenReturn(INSTANCE_ID);
    when(ec2InstanceContextMock.getClient(eq(AmazonEC2Client.class))).thenReturn(amazonEC2ClientMock);
    when(amazonEC2ClientMock.describeInstanceAttribute(any())).thenReturn(new DescribeInstanceAttributeResult().
            withInstanceAttribute(new InstanceAttribute()
                    .withUserData(Base64.encodeAsString("application_id: fdsa\napplication_version: '6478e18'".getBytes()))));

    final Optional<TaupageYaml> result = taupageYamlProvider.apply(ec2InstanceContextMock);

    assertThat(result).isPresent();

    assertThat(result.get().getApplicationId()).isEqualTo("fdsa");
    assertThat(result.get().getApplicationVersion()).isEqualTo("6478e18");

    verify(ec2InstanceContextMock).isTaupageAmi();
    verify(ec2InstanceContextMock).getInstanceId();
    verify(ec2InstanceContextMock).getClient(eq(AmazonEC2Client.class));
    verify(amazonEC2ClientMock).describeInstanceAttribute(any());
}
 
源代码14 项目: fullstop   文件: TaupageYamlProviderImplTest.java
@Test
public void testApplyWithTaupageAmiButInvalidYaml() throws Exception {
    // a yaml list is not a valid taupage format. Map is required.
    final String yamlData = "- a\n- b\n- c\n";

    when(ec2InstanceContextMock.isTaupageAmi()).thenReturn(Optional.of(true));

    when(ec2InstanceContextMock.getInstanceId()).thenReturn(INSTANCE_ID);
    when(ec2InstanceContextMock.getClient(eq(AmazonEC2Client.class))).thenReturn(amazonEC2ClientMock);
    when(amazonEC2ClientMock.describeInstanceAttribute(any())).thenReturn(new DescribeInstanceAttributeResult().
            withInstanceAttribute(new InstanceAttribute()
                    .withUserData(Base64.encodeAsString(yamlData.getBytes()))));

    final Optional<TaupageYaml> result = taupageYamlProvider.apply(ec2InstanceContextMock);

    assertThat(result).isEmpty();


    verify(ec2InstanceContextMock).isTaupageAmi();
    verify(ec2InstanceContextMock).getInstanceId();
    verify(ec2InstanceContextMock).getClient(eq(AmazonEC2Client.class));
    verify(amazonEC2ClientMock).describeInstanceAttribute(any());
}
 
private void dumpTables() {
    for (String table : client.listTables().getTableNames()) {
        ScanResult scanResult;
        Map<String, AttributeValue> lastKey = null;
        do {
            scanResult = client.scan(new ScanRequest().withTableName(table).withExclusiveStartKey(lastKey));
            lastKey = scanResult.getLastEvaluatedKey();
            for (Map<String, AttributeValue> map : scanResult.getItems()) {
                for (Map.Entry<String, AttributeValue> item : map.entrySet()) {
                    System.out.print("item.put(\"");
                    System.out.print(item.getKey());
                    System.out.print("\", b642Av(\"");
                    System.out.print(Base64.encodeAsString(AttributeValueMarshaller.marshall(item.getValue()).array()));
                    System.out.println("\"));");
                }
                System.out.print("ddb.putItem(new PutItemRequest(\"");
                System.out.print(table);
                System.out.println("\", item));");
                System.out.println("item.clear();");
                System.out.println();
            }
        } while (lastKey != null);

    }
}
 
源代码16 项目: s3-bucket-loader   文件: CompressUtil.java
public static char[] decompressAndB64DecodeUTF8Bytes(byte[] b64EncodedCompressedBytes) throws Exception {

		byte[] input = Base64.decode(b64EncodedCompressedBytes);
		
		// Compressor with highest level of compression
	    Inflater inflater = new Inflater();
	    
	    // Give the compressor the data to compress
	    inflater.setInput(input);
	    
	    ByteArrayOutputStream stream = new ByteArrayOutputStream();
	    byte[] buf = new byte[32];
	    while (!inflater.finished()) {
	        int count = inflater.inflate(buf);
	        stream.write(buf, 0, count);
	    }
	    return new String(stream.toByteArray(),"UTF-8").toCharArray();
	}
 
源代码17 项目: nifi   文件: TestPutLambda.java
@Test
public void testPutLambdaSimple() {
    runner.setProperty(PutLambda.AWS_LAMBDA_FUNCTION_NAME, "test-function");
    runner.enqueue("TestContent");

    InvokeResult invokeResult = new InvokeResult();
    invokeResult.setStatusCode(200);
    invokeResult.setLogResult(Base64.encodeAsString("test-log-result".getBytes()));
    invokeResult.setPayload(ByteBuffer.wrap("test-payload".getBytes()));
    Mockito.when(mockLambdaClient.invoke(Mockito.any(InvokeRequest.class))).thenReturn(invokeResult);

    runner.assertValid();
    runner.run(1);

    ArgumentCaptor<InvokeRequest> captureRequest = ArgumentCaptor.forClass(InvokeRequest.class);
    Mockito.verify(mockLambdaClient, Mockito.times(1)).invoke(captureRequest.capture());
    InvokeRequest request = captureRequest.getValue();
    assertEquals("test-function", request.getFunctionName());

    runner.assertAllFlowFilesTransferred(PutLambda.REL_SUCCESS, 1);
    final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(PutLambda.REL_SUCCESS);
    final MockFlowFile ff0 = flowFiles.get(0);
    ff0.assertAttributeEquals(PutLambda.AWS_LAMBDA_RESULT_STATUS_CODE, "200");
    ff0.assertAttributeEquals(PutLambda.AWS_LAMBDA_RESULT_LOG, "test-log-result");
    ff0.assertAttributeEquals(PutLambda.AWS_LAMBDA_RESULT_PAYLOAD, "test-payload");
}
 
源代码18 项目: justtestlah   文件: TestSpecFactory.java
public String createTestSpec() throws IOException {
  Scanner scanner =
      new Scanner(
          AWSTestRunner.class
              .getClassLoader()
              .getResourceAsStream("aws-devicefarm-testspec-template.yml"));
  String testSpec = scanner.useDelimiter("\\A").next();
  scanner.close();
  StringWriter justTestLahProperties = new StringWriter();
  Properties props = new Properties();
  props.putAll(properties.getProperties());

  // these settings will be overridden by the test spec execution
  props.remove("android.appPath");
  props.remove("ios.appPath");
  props.remove("cloudprovider");
  props.remove("testusers.file");
  props.store(justTestLahProperties, "justtestlah properties");

  // encode the `justtestlah.properties` into the testSpec file
  testSpec =
      testSpec.replace(
          "__JUSTTESTLAH_PROPERTIES_BASE64__",
          Base64.encodeAsString(
              justTestLahProperties.toString().replaceAll("(?m)^#.*", "").getBytes()));

  LOG.info("Test spec file: \n{}", testSpec);
  String path =
      System.getProperty("java.io.tmpdir") + File.separator + "aws-devicefarm-testspec.yml";
  Files.write(Paths.get(path), testSpec.getBytes());
  return path;
}
 
源代码19 项目: github-bucket   文件: RepositoryS3.java
private boolean walk(Iterator<S3ObjectSummary> iter, ObjectId file, String path) throws IOException {
    byte[] content;
    byte[] newHash;
    LOG.debug("Start processing file: {}", path);
    try (DigestInputStream is = new DigestInputStream(repository.open(file).openStream(), DigestUtils.getMd5Digest())) {
        // Get content
        content = IOUtils.toByteArray(is);
        // Get hash
        newHash = is.getMessageDigest().digest();
    }
    if (isUploadFile(iter, path, Hex.encodeHexString(newHash))) {
        LOG.info("Uploading file: {}", path);
        ObjectMetadata bucketMetadata = new ObjectMetadata();
        bucketMetadata.setContentMD5(Base64.encodeAsString(newHash));
        bucketMetadata.setContentLength(content.length);
        // Give Tika a few hints for the content detection
        Metadata tikaMetadata = new Metadata();
        tikaMetadata.set(Metadata.RESOURCE_NAME_KEY, FilenameUtils.getName(FilenameUtils.normalize(path)));
        // Fire!
        try (InputStream bis = TikaInputStream.get(content, tikaMetadata)) {
            bucketMetadata.setContentType(TIKA_DETECTOR.detect(bis, tikaMetadata).toString());
            s3.putObject(bucket.getName(), path, bis, bucketMetadata);
            return true;
        }
    }
    LOG.info("Skipping file (same checksum): {}", path);
    return false;
}
 
源代码20 项目: strongbox   文件: SecretModel.java
private SecretValue extractSecretValueOrThrow(boolean valueFromStdin, String generate, String valueFile) {
    String secretValue = "";
    int sum = booleanIfExists(valueFromStdin) + booleanIfExists(generate) + booleanIfExists(valueFile);

    SecretType secretType = SecretType.OPAQUE;

    if (sum == 0) {
        throw new RuntimeException("You must specify either --value-from-stdin, --value-from-file or --generate-value");
    }
    if (sum > 1) {
        throw new RuntimeException("You must specify one and only one of --value-from-stdin, --value-from-file and --generate-value");
    }

    if (generate != null) {
        secretValue = Base64.encodeAsString(randomGenerator.generateRandom(extractGenerate(generate)));
    }

    if (valueFile != null) {
        return SecretValueConverter.inferEncoding(extractValueFromFile(valueFile), secretType);
    }

    if (valueFromStdin) {
        return SecretValueConverter.inferEncoding(fromStdin(), secretType);
    }

    return new SecretValue(secretValue, secretType);
}
 
源代码21 项目: konker-platform   文件: AvatarServiceImpl.java
@Override
   public ServiceResponse<User> updateAvatar(User user) {

   	User fromStorage = userRepository.findOne(user.getEmail());

       if(!StringUtils.isEmpty(user.getAvatar())
               && user.getAvatar().contains("data:image")) {

       	String base64File = user.getAvatar();

   		String fileExt = base64File.split(",")[0].split("/")[1].split(";")[0];
   		String base64Content = base64File.split(",")[1];
   		
   		InputStream is = new ByteArrayInputStream(Base64.decode(base64Content.getBytes()));

   		ServiceResponse<InputStream> resizeResponse =  cropAndResizeAvatar(is, fileExt);
   		if (!resizeResponse.isOk()) {
               return ServiceResponseBuilder.<User>error()
                       .withMessages(resizeResponse.getResponseMessages())
                       .build();
   		}
   		
   		is = resizeResponse.getResult();
   		
           ServiceResponse<String> response = uploadService.upload(is, getUniqueFileName(), fileExt, true);
           if(!response.getStatus().equals(ServiceResponse.Status.OK)){
               return ServiceResponseBuilder.<User>error()
                       .withMessages(response.getResponseMessages())
                       .build();
           }
           user.setAvatar(response.getResult());
       } else {
           user.setAvatar(fromStorage.getAvatar());
       }

       return ServiceResponseBuilder.<User>ok()
               .withResult(user)
               .build();

}
 
源代码22 项目: konker-platform   文件: AwsUploadRepository.java
@Override
public String downloadAsBase64(String filePath) throws Exception {
    if (!Optional.ofNullable(filePath).isPresent()) {
        throw new Exception(UploadService.Validations.INVALID_PATH.getCode());
    }
    try {
        return Base64.encodeAsString(IOUtils.toByteArray(downloadFile(filePath)));
    } catch (IOException e) {
        throw new Exception(e.getMessage());
    }
}
 
源代码23 项目: zipkin-aws   文件: SQSSpanProcessor.java
private void process(final List<Message> messages) {
  if (messages.size() == 0) return;

  final List<DeleteMessageBatchRequestEntry> toDelete = new ArrayList<>();
  int count = 0;
  for (Message message : messages) {
    final String deleteId = String.valueOf(count++);
    try {
      String stringBody = message.getBody();
      if (stringBody.isEmpty() || stringBody.equals("[]")) continue;
      // allow plain-text json, but permit base64 encoded thrift or json
      byte[] serialized =
          stringBody.charAt(0) == '[' ? stringBody.getBytes(UTF_8) : Base64.decode(stringBody);
      metrics.incrementMessages();
      metrics.incrementBytes(serialized.length);
      collector.acceptSpans(
          serialized,
          new Callback<Void>() {
            @Override
            public void onSuccess(Void value) {
              toDelete.add(
                  new DeleteMessageBatchRequestEntry(deleteId, message.getReceiptHandle()));
            }

            @Override
            public void onError(Throwable t) {
              logger.log(Level.WARNING, "collector accept failed", t);
              // for cases that are not recoverable just discard the message,
              // otherwise ignore so processing can be retried.
              if (t instanceof IllegalArgumentException) {
                toDelete.add(
                    new DeleteMessageBatchRequestEntry(deleteId, message.getReceiptHandle()));
              }
            }
          });
    } catch (RuntimeException | Error e) {
      logger.log(Level.WARNING, "message decoding failed", e);
      toDelete.add(new DeleteMessageBatchRequestEntry(deleteId, message.getReceiptHandle()));
    }
  }

  if (!toDelete.isEmpty()) {
    delete(toDelete);
  }
}
 
源代码24 项目: zipkin-aws   文件: AmazonSQSRule.java
static Stream<? extends Span> decodeSpans(Message m) {
  byte[] bytes =
      m.getBody().charAt(0) == '['
          ? m.getBody().getBytes(Charset.forName("UTF-8"))
          : Base64.decode(m.getBody());
  if (bytes[0] == '[') {
    return SpanBytesDecoder.JSON_V2.decodeList(bytes).stream();
  }
  return SpanBytesDecoder.PROTO3.decodeList(bytes).stream();
}
 
源代码25 项目: zipkin-aws   文件: SQSSender.java
@Override
public Call<Void> sendSpans(List<byte[]> list) {
  if (closeCalled) throw new IllegalStateException("closed");

  byte[] encodedSpans = BytesMessageEncoder.forEncoding(encoding()).encode(list);
  String body =
      encoding() == Encoding.JSON && isAscii(encodedSpans)
          ? new String(encodedSpans, UTF_8)
          : Base64.encodeAsString(encodedSpans);

  return new SQSCall(new SendMessageRequest(queueUrl, body));
}
 
源代码26 项目: github-bucket   文件: RepositoryS3.java
private boolean walk(Iterator<S3ObjectSummary> iter, ObjectId file, String path) throws IOException {
    byte[] content;
    byte[] newHash;
    LOG.debug("Start processing file: {}", path);
    try (DigestInputStream is = new DigestInputStream(repository.open(file).openStream(), DigestUtils.getMd5Digest())) {
        // Get content
        content = IOUtils.toByteArray(is);
        // Get hash
        newHash = is.getMessageDigest().digest();
    }
    if (isUploadFile(iter, path, Hex.encodeHexString(newHash))) {
        LOG.info("Uploading file: {}", path);
        ObjectMetadata bucketMetadata = new ObjectMetadata();
        bucketMetadata.setContentMD5(Base64.encodeAsString(newHash));
        bucketMetadata.setContentLength(content.length);
        // Give Tika a few hints for the content detection
        Metadata tikaMetadata = new Metadata();
        tikaMetadata.set(Metadata.RESOURCE_NAME_KEY, FilenameUtils.getName(FilenameUtils.normalize(path)));
        // Fire!
        try (InputStream bis = TikaInputStream.get(content, tikaMetadata)) {
            bucketMetadata.setContentType(TIKA_DETECTOR.detect(bis, tikaMetadata).toString());
            s3.putObject(bucket.getName(), path, bis, bucketMetadata);
            return true;
        }
    }
    LOG.info("Skipping file (same checksum): {}", path);
    return false;
}
 
源代码27 项目: beam   文件: S3TestUtils.java
@Nullable
static String getSSECustomerKeyMd5(S3Options options) {
  SSECustomerKey sseCostumerKey = options.getSSECustomerKey();
  if (sseCostumerKey != null) {
    return Base64.encodeAsString(DigestUtils.md5(Base64.decode(sseCostumerKey.getKey())));
  }
  return null;
}
 
源代码28 项目: fullstop   文件: FetchTaupageYamlImpl.java
@Override
public Optional<TaupageYaml> getTaupageYaml(final String instanceId, final String account, final String region) {
    final AmazonEC2Client client = clientProvider.getClient(AmazonEC2Client.class,
            account,
            Region.getRegion(Regions.fromName(region)));

    try {
        final DescribeInstanceAttributeResult response = client.describeInstanceAttribute(
                new DescribeInstanceAttributeRequest()
                        .withInstanceId(instanceId)
                        .withAttribute(USER_DATA));


        return ofNullable(response)
                .map(DescribeInstanceAttributeResult::getInstanceAttribute)
                .map(InstanceAttribute::getUserData)
                .map(Base64::decode)
                .map(String::new)
                .map(TaupageYamlUtil::parseTaupageYaml);

    } catch (final AmazonClientException e) {
        log.warn("Could not get Taupage YAML for instance: " + instanceId, e);
        return empty();
    } catch (YAMLException | IllegalArgumentException s) {
        log.warn("Taupage YAML is not valid for instance: " + instanceId, s);
        return empty();
    }
}
 
源代码29 项目: fullstop   文件: FetchTaupageYamlImplTest.java
@Test
public void testGetTaupageYaml() throws Exception {
    when(amazonEC2ClientMock.describeInstanceAttribute(any())).thenReturn(new DescribeInstanceAttributeResult().
            withInstanceAttribute(new InstanceAttribute()
                    .withUserData(Base64.encodeAsString("blub: fdsa".getBytes()))));
    final FetchTaupageYaml fetchTaupageYaml = new FetchTaupageYamlImpl(clientProviderMock);

    final Optional<TaupageYaml> result = fetchTaupageYaml.getTaupageYaml(INSTANCE_ID, ACCOUNT, REGION);

    assertThat(result).isPresent();

    verify(amazonEC2ClientMock).describeInstanceAttribute(any());
}
 
源代码30 项目: fullstop   文件: S3Service.java
public String writeToS3(final String accountId, final String region, final Date instanceBootTime,
                        final String logData, final String logType, final String instanceId) {
    String fileName = null;

    final DateTime dateTime = new DateTime(instanceBootTime, UTC);

    final String keyName = Paths.get(
            accountId, region, dateTime.toString("YYYY"), dateTime.toString("MM"),
            dateTime.toString("dd"), instanceId + "-" + dateTime).toString();

    switch (LogType.valueOf(logType)) {

        case USER_DATA:
            fileName = TAUPAGE_YAML;
            break;

        case AUDIT_LOG:
            fileName = AUDIT_LOG_FILE_NAME + new DateTime(UTC) + LOG_GZ;
            break;

        default:
            log.error("Wrong logType given: " + logType);
            break;
    }

    final ObjectMetadata metadata = new ObjectMetadata();
    final byte[] decodedLogData = Base64.decode(logData);
    metadata.setContentLength(decodedLogData.length);

    final InputStream stream = new ByteArrayInputStream(decodedLogData);

    putObjectToS3(bucketName, fileName, keyName, metadata, stream);

    return Paths.get(bucketName, keyName, fileName).toString();
}