List of usage examples for com.amazonaws.auth BasicAWSCredentials BasicAWSCredentials
public BasicAWSCredentials(String accessKey, String secretKey)
From source file:com.oneops.antenna.senders.aws.EmailService.java
License:Apache License
/** * Inits the.//from www. ja v a2 s. c o m */ public void init() { if (this.awsAccessKey == null) { this.awsAccessKey = System.getenv("AWS_ACCESS_KEY"); if (this.awsAccessKey == null) { this.awsAccessKey = System.getProperty("com.oneops.aws.accesskey"); } } if (this.awsSecretKey == null) { this.awsSecretKey = System.getenv("AWS_SECRET_KEY"); if (this.awsSecretKey == null) { this.awsSecretKey = System.getProperty("com.oneops.aws.secretkey"); } } emailClient = new AmazonSimpleEmailServiceClient(new BasicAWSCredentials(awsAccessKey, awsSecretKey)); }
From source file:com.oneops.antenna.senders.aws.SNSService.java
License:Apache License
/** * Sends using the sns publisher/*w ww . j a va 2s.c o m*/ */ @Override public boolean postMessage(NotificationMessage nMsg, BasicSubscriber subscriber) { SNSSubscriber sub; if (subscriber instanceof SNSSubscriber) { sub = (SNSSubscriber) subscriber; } else { throw new ClassCastException("invalid subscriber " + subscriber.getClass().getName()); } SNSMessage msg = buildSNSMessage(nMsg); AmazonSNS sns = new AmazonSNSClient(new BasicAWSCredentials(sub.getAwsAccessKey(), sub.getAwsSecretKey())); if (sub.getSnsEndpoint() != null) { sns.setEndpoint(sub.getSnsEndpoint()); } CreateTopicRequest tRequest = new CreateTopicRequest(); tRequest.setName(msg.getTopicName()); CreateTopicResult result = sns.createTopic(tRequest); PublishRequest pr = new PublishRequest(result.getTopicArn(), msg.getTxtMessage()) .withSubject(msg.getSubject()); try { PublishResult pubresult = sns.publish(pr); logger.info("Published msg with id - " + pubresult.getMessageId()); } catch (AmazonClientException ace) { logger.error(ace.getMessage()); return false; } return true; }
From source file:com.oneops.inductor.AbstractOrderExecutor.java
License:Apache License
/** * getAuthoritativeServersByCloudService: gets dns servers * * @param cloudService CmsCISimple/* ww w. j a va 2s . co m*/ */ protected List<String> getAuthoritativeServersByCloudService(CmsCISimple cloudService) { String dnsZoneName = cloudService.getCiAttributes().get("zone"); List<String> nameservers = new ArrayList<>(); // aws use the api if (cloudService.getCiClassName().endsWith("AWS")) { AWSCredentials awsCredentials; if (cloudService.getCiAttributes().containsKey("dns_key")) { awsCredentials = new BasicAWSCredentials(cloudService.getCiAttributes().get("dns_key"), cloudService.getCiAttributes().get("dns_secret")); } else { awsCredentials = new BasicAWSCredentials(config.getDnsKey(), config.getDnsSecret()); } return getAuthoritativeServersWithAwsCreds(awsCredentials, dnsZoneName); // else use ns record } else { String dnsZone = cloudService.getCiAttributes().get("zone"); String[] digCmd = new String[] { "/usr/bin/dig", "+short", "NS", dnsZone }; ProcessResult result = procR.executeProcessRetry(digCmd, "", retryCount); if (result.getResultCode() > 0) { logger.error("dig +short NS " + dnsZone + " returned: " + result.getStdErr()); } if (!result.getStdOut().equalsIgnoreCase("")) { nameservers = Arrays.asList(result.getStdOut().split("\n")); } } return nameservers; }
From source file:com.openkm.util.backup.RepositoryS3Backup.java
License:Open Source License
/** * Performs a recursive repository content export with metadata *//* w ww .jav a 2 s .c o m*/ public static ImpExpStats backup(String token, String fldPath, String bucket, boolean metadata, Writer out, InfoDecorator deco) throws PathNotFoundException, AccessDeniedException, RepositoryException, FileNotFoundException, ParseException, NoSuchGroupException, IOException, DatabaseException, GeneralException { log.debug("backup({}, {}, {}, {}, {}, {})", new Object[] { token, fldPath, bucket, metadata, out, deco }); ImpExpStats stats = null; if (running) { throw new GeneralException("Backup in progress"); } else { running = true; try { if (!Config.AMAZON_ACCESS_KEY.equals("") && !Config.AMAZON_SECRET_KEY.equals("")) { AmazonS3 s3 = new AmazonS3Client( new BasicAWSCredentials(Config.AMAZON_ACCESS_KEY, Config.AMAZON_SECRET_KEY)); if (!s3.doesBucketExist(bucket)) { s3.createBucket(bucket, Region.EU_Ireland); } stats = backupHelper(token, fldPath, s3, bucket, metadata, out, deco); log.info("Backup finished!"); } else { throw new GeneralException("Missing Amazon Web Service keys"); } } finally { running = false; } } log.debug("exportDocuments: {}", stats); return stats; }
From source file:com.optimalbi.Controller.Containers.AmazonCredentials.java
License:Apache License
/** * This it the credentials that is used to authenticate with the AWS cloud * @param accountName The name that describes this account * @param accessKey The access key that is provided by the AWS IAM console * @param secretKey The secret key that is provided by the AWS IAM console *//*from w w w. ja v a 2s .c o m*/ public AmazonCredentials(String accountName, String accessKey, String secretKey) { this.accountName = accountName; this.accessKey = accessKey; this.secretKey = secretKey; this.credentials = new BasicAWSCredentials(accessKey, secretKey); }
From source file:com.oracle.coherence.cloud.amazon.EC2AddressProvider.java
License:Open Source License
/** * This method determines what credentials to use for EC2 authentication. * /* w w w . j a v a 2 s .c o m*/ * @return the {@link AWSCredentials} * * @throws IOException if reading the property file fails */ protected AWSCredentials determineCredentials() throws IOException { String accessKey = System.getProperty("tangosol.coherence.ec2addressprovider.accesskey"); String secretKey = System.getProperty("tangosol.coherence.ec2addressprovider.secretkey"); if ((accessKey == null) || (secretKey == null) || accessKey.equals("") || secretKey.equals("")) { if (logger.isLoggable(Level.CONFIG)) { logger.log(Level.CONFIG, "No EC2AddressProvider credential system properties provided."); } // Retrieve the credentials from a properties resource instead. String propertyResource = System.getProperty("tangosol.coherence.ec2addressprovider.propertyfile", "AwsCredentials.properties"); InputStream stream = Thread.currentThread().getContextClassLoader() .getResourceAsStream(propertyResource); if (stream != null) { return new PropertiesCredentials(stream); } else { throw new RuntimeException( "The EC2AddressProvider could not find any credentials, neither as system properties, nor as " + propertyResource + " resource"); } } else { return new BasicAWSCredentials(accessKey, secretKey); } }
From source file:com.pearson.eidetic.driver.threads.MonitorSnapshotVolumeTime.java
public AmazonEC2Client connect(Region region, String awsAccessKey, String awsSecretKey) { AmazonEC2Client ec2Client;//from w w w . ja va2s . co m String endpoint = "ec2." + region.getName() + ".amazonaws.com"; AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey); ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.setProtocol(Protocol.HTTPS); ec2Client = new AmazonEC2Client(credentials, clientConfig); ec2Client.setRegion(region); ec2Client.setEndpoint(endpoint); return ec2Client; }
From source file:com.pinterest.arcee.autoscaling.AwsAutoScalingManager.java
License:Apache License
public AwsAutoScalingManager(AwsConfigManager configManager) { if (StringUtils.isNotEmpty(configManager.getId()) && StringUtils.isNotEmpty(configManager.getKey())) { AWSCredentials awsCredentials = new BasicAWSCredentials(configManager.getId(), configManager.getKey()); this.aasClient = new AmazonAutoScalingClient(awsCredentials); } else {//from w w w . java 2 s .c o m LOG.debug( "AWS credential is missing for creating AWS client. Assuming to use role for authentication."); this.aasClient = new AmazonAutoScalingClient(); } this.ownerId = configManager.getOwnerId(); this.snsArn = configManager.getSnsArn(); this.vmKeyName = configManager.getVmKeyName(); this.defaultRole = configManager.getDefaultRole(); this.pinfoEnvironment = configManager.getPinfoEnvironment(); this.roleTemplate = configManager.getRoleTemplate(); this.userDataTemplate = configManager.getUserDataTemplate(); this.roleARN = configManager.getRoleArn(); }
From source file:com.pinterest.clusterservice.aws.AwsManagerImpl.java
License:Apache License
public AwsManagerImpl(AwsConfigManager configManager) { if (StringUtils.isNotEmpty(configManager.getId()) && StringUtils.isNotEmpty(configManager.getKey())) { AWSCredentials awsCredentials = new BasicAWSCredentials(configManager.getId(), configManager.getKey()); this.ec2Client = new AmazonEC2Client(awsCredentials); } else {//from w w w .j av a 2s . c om LOG.debug( "AWS credential is missing for creating AWS client. Assuming to use role for authentication."); this.ec2Client = new AmazonEC2Client(); } }
From source file:com.pinterest.clusterservice.cm.AwsVmManager.java
License:Apache License
public AwsVmManager(AwsConfigManager configManager) { if (StringUtils.isNotEmpty(configManager.getId()) && StringUtils.isNotEmpty(configManager.getKey())) { AWSCredentials awsCredentials = new BasicAWSCredentials(configManager.getId(), configManager.getKey()); this.aasClient = new AmazonAutoScalingClient(awsCredentials); this.ec2Client = new AmazonEC2Client(awsCredentials); } else {/*w ww . j a v a 2 s. c o m*/ LOG.debug( "AWS credential is missing for creating AWS client. Assuming to use role for authentication."); this.aasClient = new AmazonAutoScalingClient(); this.ec2Client = new AmazonEC2Client(); } this.ownerId = configManager.getOwnerId(); this.snsArn = configManager.getSnsArn(); }