1 package org.kuali.common.devops.archive.sweep.test; 2 3 import static com.google.common.collect.Lists.newArrayList; 4 import static java.lang.String.format; 5 import static java.util.Arrays.asList; 6 import static org.kuali.common.util.encrypt.Encryption.getDefaultEncryptor; 7 import static org.kuali.common.util.log.LoggerUtils.logTable; 8 import static org.kuali.common.util.log.Loggers.newLogger; 9 10 import java.util.List; 11 import java.util.Map; 12 13 import org.junit.Test; 14 import org.kuali.common.aws.model.ImmutableAWSCredentials; 15 import org.kuali.common.aws.s3.DefaultS3Service; 16 import org.kuali.common.aws.s3.S3Service; 17 import org.kuali.common.aws.s3.model.ObjectMetadata; 18 import org.kuali.common.util.encrypt.Encryptor; 19 import org.slf4j.Logger; 20 21 import com.amazonaws.auth.AWSCredentials; 22 import com.google.common.collect.Ordering; 23 24 public class ShowMetadataTest { 25 26 private static final Logger logger = newLogger(); 27 28 @Test 29 public void test() { 30 try { 31 String bucket = "archive.kuali.org"; 32 List<String> keys = asList("org/"); 33 S3Service s3 = DefaultS3Service.build(getFoundation()); 34 for (String key : keys) { 35 ObjectMetadata omd = s3.getMetadata(bucket, key); 36 show(key, omd.getUserMetadata()); 37 } 38 } catch (Throwable e) { 39 e.printStackTrace(); 40 } 41 } 42 43 private void show(String key, Map<String, ?> map) { 44 List<String> columns = asList("key", "value"); 45 List<Object[]> rows = newArrayList(); 46 List<String> keys = Ordering.natural().immutableSortedCopy(map.keySet()); 47 for (String element : keys) { 48 rows.add(new Object[] { element, map.get(element) }); 49 } 50 logTable(key, columns, rows); 51 } 52 53 private static AWSCredentials getFoundation() { 54 Encryptor enc = getDefaultEncryptor(); 55 String accessKey = enc.decrypt("U2FsdGVkX19A2e6dN/ipVfb/9n0DROCPIrLK6H8PvvPmt0h6cBqccGaJW0NSoX3S"); 56 String secretKey = enc.decrypt("U2FsdGVkX19Y9SZ5GAU82/X5Z0xZdeQf7DFuVDW07R9lfyHK4VaOj5R7pviRBKmIyn7jrVT2lv8Edeu7098k1A=="); 57 return new ImmutableAWSCredentials(accessKey, secretKey); 58 } 59 60 protected void info(String msg, Object... args) { 61 logger.info((args == null || args.length == 0) ? msg : format(msg, args)); 62 } 63 64 }