Example usage for com.amazonaws.auth BasicAWSCredentials BasicAWSCredentials

List of usage examples for com.amazonaws.auth BasicAWSCredentials BasicAWSCredentials

Introduction

In this page you can find the example usage for com.amazonaws.auth BasicAWSCredentials BasicAWSCredentials.

Prototype

public BasicAWSCredentials(String accessKey, String secretKey) 

Source Link

Document

Constructs a new BasicAWSCredentials object, with the specified AWS access key and AWS secret key.

Usage

From source file:cloudExplorer.Put.java

License:Open Source License

public void run() {
    try {/* w w w  . ja va  2s. c  o  m*/
        AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
        AmazonS3 s3Client = new AmazonS3Client(credentials,
                new ClientConfiguration().withSignerOverride("S3SignerType"));
        s3Client.setEndpoint(endpoint);
        TransferManager tx = new TransferManager(s3Client);
        File file = new File(what);
        PutObjectRequest putRequest;
        if (!rrs) {
            putRequest = new PutObjectRequest(bucket, ObjectKey, file);
        } else {
            putRequest = new PutObjectRequest(bucket, ObjectKey, file)
                    .withStorageClass(StorageClass.ReducedRedundancy);
        }
        MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
        String mimeType = mimeTypesMap.getContentType(file);
        mimeType = mimeTypesMap.getContentType(file);
        ObjectMetadata objectMetadata = new ObjectMetadata();
        if (encrypt) {
            objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
        }
        if ((ObjectKey.contains(".html")) || ObjectKey.contains(".txt")) {
            objectMetadata.setContentType("text/html");
        } else {
            objectMetadata.setContentType(mimeType);
        }
        long t1 = System.currentTimeMillis();
        putRequest.setMetadata(objectMetadata);
        Upload myUpload = tx.upload(putRequest);
        myUpload.waitForCompletion();
        tx.shutdownNow();
        long t2 = System.currentTimeMillis();
        long diff = t2 - t1;

        if (!mainFrame.perf) {
            if (terminal) {
                System.out.print("\nUploaded object: " + ObjectKey + " in " + diff / 1000 + " second(s).\n");
            } else {
                mainFrame.jTextArea1
                        .append("\nUploaded object: " + ObjectKey + " in " + diff / 1000 + " second(s).");
            }
        }
    } catch (AmazonServiceException ase) {
        if (NewJFrame.gui) {
            mainFrame.jTextArea1.append("\n\nError Message:    " + ase.getMessage());
            mainFrame.jTextArea1.append("\nHTTP Status Code: " + ase.getStatusCode());
            mainFrame.jTextArea1.append("\nAWS Error Code:   " + ase.getErrorCode());
            mainFrame.jTextArea1.append("\nError Type:       " + ase.getErrorType());
            mainFrame.jTextArea1.append("\nRequest ID:       " + ase.getRequestId());
            calibrate();
        } else {
            System.out.print("\n\nError Message:    " + ase.getMessage());
            System.out.print("\nHTTP Status Code: " + ase.getStatusCode());
            System.out.print("\nAWS Error Code:   " + ase.getErrorCode());
            System.out.print("\nError Type:       " + ase.getErrorType());
            System.out.print("\nRequest ID:       " + ase.getRequestId());
        }
    } catch (Exception put) {
    }

    calibrate();
}

From source file:cloudExplorer.RestoreObject.java

License:Open Source License

public void run() {
    String message = null;/*from www  .  j  a  va 2s .  com*/
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    File file = new File(what);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration().withSignerOverride("S3SignerType"));
    s3Client.setEndpoint(endpoint);

    try {
        GetObjectMetadataRequest request = new GetObjectMetadataRequest(bucket, what);
        ObjectMetadata response = s3Client.getObjectMetadata(request);
        response.getOngoingRestore();

        mainFrame.jTextArea1.append("\nRestored operation ran for Object: " + what
                + ". Please examiene this window for any errors.");
        mainFrame.calibrateTextArea();

    } catch (Exception get) {
        //  mainFrame.jTextArea1.append("\n\nError Message: " + get.getMessage());
    }

    calibrate();
}

From source file:cloudExplorer.Versioning.java

License:Open Source License

void getVersions(String key, String access_key, String secret_key, String bucket, String endpoint) {
    String results = null;/* w w  w .jav a 2  s . com*/
    Boolean check_finished = false;

    try {
        mainFrame.jTextArea1.append("\nPlease wait, loading versions.");
        mainFrame.calibrateTextArea();
        AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
        AmazonS3 s3Client = new AmazonS3Client(credentials,
                new ClientConfiguration().withSignerOverride("S3SignerType"));
        s3Client.setEndpoint(endpoint);

        VersionListing vListing;
        if (key == null) {
            vListing = s3Client.listVersions(bucket, null);
        } else {
            vListing = s3Client.listVersions(bucket, key);
        }

        List<S3VersionSummary> summary = vListing.getVersionSummaries();

        if (summary.size() == 0) {
            check_finished = true;
        } else {
            check_finished = false;
        }

        for (S3VersionSummary object : summary) {
            if (!Versioning.delete) {
                mainFrame.versioning_date.add(object.getLastModified().toString());
            }
            mainFrame.versioning_id.add(object.getVersionId());
            mainFrame.versioning_name.add(object.getKey());
            System.gc();
        }

        if (Versioning.delete) {
            int i = 0;
            for (String delVer : mainFrame.versioning_name) {
                del = new Delete(delVer, mainFrame.cred.getAccess_key(), mainFrame.cred.getSecret_key(),
                        mainFrame.cred.getBucket(), mainFrame.cred.getEndpoint(),
                        mainFrame.versioning_id.get(i));
                del.startc(delVer, mainFrame.cred.getAccess_key(), mainFrame.cred.getSecret_key(),
                        mainFrame.cred.getBucket(), mainFrame.cred.getEndpoint(),
                        mainFrame.versioning_id.get(i));
                i++;
            }
            if (!check_finished) {
                getVersions(key, access_key, secret_key, bucket, endpoint);
            }
        }

        if (Versioning.delete) {
            mainFrame.jTextArea1.append(
                    "\nCompleted deleting every object. Please observe this window for any tasks that are still running.");
        } else {
            mainFrame.jTextArea1
                    .append("\nDone gathering Versions. If files are found, the first 1000 will be displayed.");
        }
        mainFrame.calibrateTextArea();
    } catch (Exception getVersions) {

    }
    if (Versioning.delete) {
        Versioning.delete = false;
        mainFrame.reloadObjects(false);
    }

}

From source file:cloudify.widget.ec2.Ec2KeyPairGenerator.java

License:Open Source License

public Data generate(String user, String apiKey) {
    logger.info("generating private key");
    final AWSCredentials credentials = new BasicAWSCredentials(user, apiKey);
    AmazonEC2 ec2 = new AmazonEC2Client(credentials);

    CreateKeyPairRequest createKeyPairRequest = new CreateKeyPairRequest();
    // setting the key name. Important: must be unique!
    String name = "cloudify-widget-" + System.currentTimeMillis();
    createKeyPairRequest.withKeyName(name);
    CreateKeyPairResult createKeyPairResult = ec2.createKeyPair(createKeyPairRequest);

    // Getting the unencrypted PEM-encoded private key
    KeyPair keyPair = createKeyPairResult.getKeyPair();
    String privateKey = keyPair.getKeyMaterial();

    Data data = new Data();
    data.setName(name);//from w w w. j ava 2 s. co  m
    data.setContent(privateKey);

    logger.info("success");
    return data;

}

From source file:cloudtrailviewer.components.S3FileChooserDialog.java

License:Open Source License

private void reloadContents() {

    List<String> tmp = new ArrayList<String>();
    this.files.setAll(tmp);

    String bucketName = PropertiesSingleton.getInstance().getProperty("Bucket");

    ListObjectsRequest listObjectsRequest = new ListObjectsRequest();
    listObjectsRequest.setBucketName(bucketName);
    listObjectsRequest.setPrefix(prefix);
    listObjectsRequest.setDelimiter("/");

    AWSCredentials credentials = new BasicAWSCredentials(PropertiesSingleton.getInstance().getProperty("Key"),
            PropertiesSingleton.getInstance().getProperty("Secret"));

    AmazonS3 s3Client = new AmazonS3Client(credentials);

    ObjectListing objectListing = s3Client.listObjects(listObjectsRequest);

    // these are directories
    List<String> directories = objectListing.getCommonPrefixes();
    for (String directory : directories) {

        tmp.add(stripPrefix(directory));
    }/*from   w w  w  . j  a  v  a  2s.  c om*/

    // these are files
    List<S3ObjectSummary> objectSummaries = objectListing.getObjectSummaries();
    for (final S3ObjectSummary objectSummary : objectSummaries) {

        tmp.add(stripPrefix(objectSummary.getKey()));
    }

    this.files.setAll(tmp);
}

From source file:cloudtrailviewer.events.EventLoader.java

License:Open Source License

private void readS3File(String key) throws IOException {

    AWSCredentials credentials = new BasicAWSCredentials(PropertiesSingleton.getInstance().getProperty("Key"),
            PropertiesSingleton.getInstance().getProperty("Secret"));

    AmazonS3 s3Client = new AmazonS3Client(credentials);
    String bucketName = PropertiesSingleton.getInstance().getProperty("Bucket");

    S3Object s3Object = s3Client.getObject(new GetObjectRequest(bucketName, key));

    GZIPInputStream gzis = new GZIPInputStream(s3Object.getObjectContent());
    BufferedReader bf = new BufferedReader(new InputStreamReader(gzis, "UTF-8"));

    String outStr = "";
    String line;/*from   w ww  .  j  av a  2s.  co m*/
    while ((line = bf.readLine()) != null) {
        outStr += line;
    }
    bf.close();
    gzis.close();

    readLogEvents(outStr);
}

From source file:co.upet.extensions.glacierbkuploader.glacier.GlacierManager.java

@Inject
public GlacierManager(Configuration conf) {
    BasicAWSCredentials awsCreds = new BasicAWSCredentials(conf.awsAccessKey(), conf.awsSecretKey());
    glacierClient = new AmazonGlacierClient(awsCreds);
    glacierClient.setEndpoint(conf.glacierEndPoint());
    transferManager = new ArchiveTransferManager(glacierClient, awsCreds);
}

From source file:com.adeptj.modules.aws.core.AwsUtil.java

License:Apache License

public static AWSCredentialsProvider getCredentialsProvider(String accessKey, String secretKey) {
    return new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey));
}

From source file:com.adobe.acs.commons.mcp.impl.processes.asset.S3AssetIngestor.java

License:Apache License

@Override
public void buildProcess(ProcessInstance instance, ResourceResolver rr)
        throws LoginException, RepositoryException {
    if (StringUtils.isNotBlank(s3BasePath) && !s3BasePath.endsWith("/")) {
        s3BasePath = s3BasePath + "/";
    }//from   w  w w .  j  a  v a2  s  .  c om
    instance.getInfo().setDescription(baseItemName + "->" + jcrBasePath);
    instance.defineCriticalAction("Create Folders", rr, this::createFolders);
    instance.defineCriticalAction("Import Assets", rr, this::importAssets);
    s3Client = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey));
    if (StringUtils.isNotBlank(endpointUrl)) {
        s3Client.setEndpoint(endpointUrl);
    }
}

From source file:com.aegeus.aws.ElasticMapReduceService.java

License:Apache License

public ElasticMapReduceService(EmrConfigObject config) {
    this.config = config;

    emr = new AmazonElasticMapReduceClient(
            new BasicAWSCredentials(config.getAccessKey(), config.getSecretKey()));
    emr.setRegion(Region.getRegion(Regions.fromName(config.getRegion())));
}