Example usage for com.amazonaws.auth EnvironmentVariableCredentialsProvider EnvironmentVariableCredentialsProvider

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

Introduction

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

Prototype

EnvironmentVariableCredentialsProvider

Source Link

Usage

From source file:CustomCredentialsProviderChain.java

License:Open Source License

public CustomCredentialsProviderChain() {
    super(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(),
            new ClasspathPropertiesFileCredentialsProvider(), new InstanceProfileCredentialsProvider());
}

From source file:chatbot.LambdaFunctionHandler.java

License:Open Source License

@Override
public String handleRequest(SlackData input, Context context) {
    String sResponse = ", Welcome to Service Bot";
    try {/*from w  w  w . ja  v a  2 s . com*/
        //context.getLogger().log(input);
        context.getLogger().log("Input Code: " + input.getCode());
        context.getLogger().log("Input State: " + input.getState());
        Env objEnv = input.getEnv();
        String sURL = "https://slack.com/api/oauth.access";
        List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
        urlParameters.add(new BasicNameValuePair("client_id", objEnv.getClientId()));
        urlParameters.add(new BasicNameValuePair("client_secret", objEnv.getSlackClientSecret()));
        urlParameters.add(new BasicNameValuePair("code", input.getCode()));
        urlParameters.add(new BasicNameValuePair("redirect_uri", objEnv.getSlackRedirectUrl()));
        String jsonInString = invokeSlackAPI(sURL, urlParameters, context);
        ObjectMapper mapper = new ObjectMapper();
        //JSON from String to Object
        SlackAuth objSlackAuth = mapper.readValue(jsonInString, SlackAuth.class);
        sResponse = objSlackAuth.getTeam_name() + sResponse;
        sURL = "https://slack.com/api/channels.list";
        urlParameters = new ArrayList<NameValuePair>();
        urlParameters.add(new BasicNameValuePair("token", objSlackAuth.getAccess_token()));
        jsonInString = invokeSlackAPI(sURL, urlParameters, context);
        //JSON from String to Object
        SlackChannels objSlackChannels = mapper.readValue(jsonInString, SlackChannels.class);
        System.out.println("Channels " + objSlackChannels.getChannels());
        String sSiteChannel_ID = null;
        String sBuyersChannel_ID = null;
        String sManagers_ID = null;
        for (Channel objChannel : objSlackChannels.getChannels()) {
            if (objChannel.getName().equals("site-engineers")) {
                sSiteChannel_ID = objChannel.getId();
            }
            if (objChannel.getName().equals("buyers")) {
                sBuyersChannel_ID = objChannel.getId();
            }
            if (objChannel.getName().equals("operations-managers")) {
                sManagers_ID = objChannel.getId();
            }
        }
        sURL = "https://slack.com/api/channels.create";
        if (sSiteChannel_ID == null) {
            urlParameters = new ArrayList<NameValuePair>();
            urlParameters.add(new BasicNameValuePair("token", objSlackAuth.getAccess_token()));
            urlParameters.add(new BasicNameValuePair("name", "site-engineers"));
            jsonInString = invokeSlackAPI(sURL, urlParameters, context);
            ChannelAddResponse objChannelAddResponse = mapper.readValue(jsonInString, ChannelAddResponse.class);
            sSiteChannel_ID = (objChannelAddResponse.getChannel()).getId();
        }
        if (sBuyersChannel_ID == null) {
            urlParameters = new ArrayList<NameValuePair>();
            urlParameters.add(new BasicNameValuePair("token", objSlackAuth.getAccess_token()));
            urlParameters.add(new BasicNameValuePair("name", "buyers"));
            jsonInString = invokeSlackAPI(sURL, urlParameters, context);
            ChannelAddResponse objChannelAddResponse = mapper.readValue(jsonInString, ChannelAddResponse.class);
            sBuyersChannel_ID = (objChannelAddResponse.getChannel()).getId();
        }
        if (sManagers_ID == null) {
            urlParameters = new ArrayList<NameValuePair>();
            urlParameters.add(new BasicNameValuePair("token", objSlackAuth.getAccess_token()));
            urlParameters.add(new BasicNameValuePair("name", "operations-managers"));
            jsonInString = invokeSlackAPI(sURL, urlParameters, context);
            ChannelAddResponse objChannelAddResponse = mapper.readValue(jsonInString, ChannelAddResponse.class);
            sManagers_ID = (objChannelAddResponse.getChannel()).getId();
        }
        AmazonDynamoDBClient objClient = new AmazonDynamoDBClient(new EnvironmentVariableCredentialsProvider());
        DynamoDB dynamoDB = new DynamoDB(objClient);
        //Get all data set status inactive
        Item objNewTeam = new Item().withPrimaryKey("TEAM_ID", objSlackAuth.getTeam_id())
                .withString("TEAM_NAME", objSlackAuth.getTeam_name()).withString("CHANNEL_1", sSiteChannel_ID)
                .withString("CHANNEL_2", sBuyersChannel_ID).withString("CHANNEL_3", sManagers_ID)
                .withString("ACCESS_TOKEN", objSlackAuth.getAccess_token());
        Table tableCases = dynamoDB.getTable("ENTITY");
        tableCases.putItem(objNewTeam);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return sResponse;
}

From source file:chatbot.ServiceAlertHandler.java

License:Open Source License

@Override
public String handleRequest(ServiceData input, Context context) {
    String message_response = "_Hello";
    try {/*  ww  w  .j  av a2s.c o  m*/
        context.getLogger().log("Input: " + input.getTemperature());
        int Min = 3000;
        int Max = 8000;
        int ID = 0;
        while (true) {
            ID = Min + (int) (Math.random() * ((Max - Min) + 1));
            if (objIDList.containsKey(new Integer(ID))) {
                continue;
            } else
                break;
        }
        AmazonDynamoDBClient objClient = new AmazonDynamoDBClient(new EnvironmentVariableCredentialsProvider());
        DynamoDB dynamoDB = new DynamoDB(objClient);
        //Get all data set status inactive
        DynamoDBMapper mapper = new DynamoDBMapper(objClient);
        FindCasesActive(mapper, input.getTeam_id());
        Item objNewCase = new Item().withPrimaryKey("CASE_ID", ID).withString("USER", "unassigned")
                .withString("DESCRIPTION", "Blah").withString("STAGE", "0")
                .withString("TEAM_ID", input.getTeam_id()).withString("CASE_STATE", "ACTIVE");
        Table tableCases = dynamoDB.getTable("CASES");
        tableCases.putItem(objNewCase);

        message_response = "Service Alert : Priority - High";
        String sURL = "https://slack.com/api/chat.postMessage";
        HttpClient httpClient = HttpClients.createDefault();
        String sTeamId = input.getTeam_id();
        Entity objEntity = EntityHelper.getEntityObject(sTeamId);
        String sAuthToken = objEntity.getAccess_token();
        List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
        urlParameters.add(new BasicNameValuePair("token", sAuthToken));
        urlParameters.add(new BasicNameValuePair("channel", objEntity.getChannel_1()));
        urlParameters.add(new BasicNameValuePair("text", message_response));
        String sAttachment1 = "[\r\n        {\r\n            \"fallback\": \"Required plain-text summary of the attachment.\",\r\n             \"color\": \"#F35A00\",\r\n            \r\n            \"author_name\": \"Excavator System\",\r\n            \"author_link\": \"http://flickr.com/bobby/\",\r\n            \"author_icon\": \"http://flickr.com/icons/bobby.jpg\",\r\n            \"title\": \"Hydraulic Oil Temperature Alert\",\r\n            \"title_link\": \"https://api.slack.com/\",\r\n            \"text\": \"System detected abnormal rise in hydarulic oil temperature.\",\r\n            \"fields\": [                \r\n                {\r\n                    \"title\": \"Maximum\",\r\n                    \"value\": \"28\\u00B0 C\",\r\n                    \"short\": true\r\n                },\r\n                {\r\n                    \"title\": \"Recorded \",\r\n                    \"value\": \"";
        sAttachment1 += input.getTemperature();
        String sAttachment2 = "\\u00B0 C\",\r\n                    \"short\": true\r\n                }\r\n            ],\r\n            \"image_url\": \"http://servicebot.valueinnovation.co.in/slackhack/tempTrend1.jpg\",\r\n            \"thumb_url\": \"http://noamusic.fr/wp-content/rising-sea-levels-graph-7411.gif\",\r\n            \"footer\": \"MODEL 7830 L | SERIAL Number 8923901-23\",\r\n            \"footer_icon\": \"http://www.freeiconspng.com/uploads/alert-storm-warning-weather-icon--icon-search-engine-0.png\",\r\n            \"ts\":";
        long unixTime = System.currentTimeMillis() / 1000L;
        sAttachment2 += unixTime;
        String sAttachment3 = "\r\n        }\r\n    ]";
        urlParameters.add(new BasicNameValuePair("attachments", sAttachment1 + sAttachment2 + sAttachment3));
        HttpPost httpPost = new HttpPost(sURL);
        httpPost.setEntity(new UrlEncodedFormEntity(urlParameters));
        HttpResponse httpResponse = httpClient.execute(httpPost);
        System.out.println("POST Response Status:: " + httpResponse.getStatusLine().getStatusCode());
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(httpResponse.getEntity().getContent()));
        String inputLine;
        StringBuffer response = new StringBuffer();
        while ((inputLine = reader.readLine()) != null) {
            response.append(inputLine);
        }
        reader.close();
        List<NameValuePair> urlParameters1 = new ArrayList<NameValuePair>();
        urlParameters1.add(new BasicNameValuePair("token", sAuthToken));
        urlParameters1.add(new BasicNameValuePair("channel", objEntity.getChannel_1()));
        try {
            Thread.sleep(4000);
        } catch (Exception e) {
        }
        urlParameters1.add(new BasicNameValuePair("text",
                "I recommend, we order a new coolant pump. Do you wish to see vendor parts?"));
        httpPost.setEntity(new UrlEncodedFormEntity(urlParameters1));
        httpResponse = httpClient.execute(httpPost);
        System.out.println("POST Response Status:: " + httpResponse.getStatusLine().getStatusCode());
        // print result
        System.out.println(response.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
    // TODO: implement your handler
    return "Hello " + input.getTemperature();
}

From source file:com.amazon.kinesis.streaming.agent.AgentAWSCredentialsProviderChain.java

License:Open Source License

public AgentAWSCredentialsProviderChain(AgentConfiguration config) {
    super(new AgentAWSCredentialsProvider(config), new EnvironmentVariableCredentialsProvider(),
            new SystemPropertiesCredentialsProvider(), new ContainerCredentialsProvider(),
            new ProfileCredentialsProvider(), new InstanceProfileCredentialsProvider());
}

From source file:com.amediamanager.config.S3ConfigurationProvider.java

License:Apache License

@Override
public void loadProperties() {
    this.properties = null;

    // Load properties if there is a bucket and key
    if (bucket != null && key != null) {
        AWSCredentialsProvider creds = new AWSCredentialsProviderChain(new InstanceProfileCredentialsProvider(),
                new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider());
        AmazonS3 s3Client = new AmazonS3Client(creds);
        try {/*w w  w.  ja  va2  s . c o  m*/
            S3Object object = s3Client.getObject(this.bucket, this.key);
            if (object != null) {
                this.properties = new Properties();
                try {
                    this.properties.load(object.getObjectContent());
                } catch (IOException e) {
                    this.properties = null;
                    LOG.warn("Found configuration file in S3 but failed to load properties (s3://{}/{})",
                            new Object[] { this.bucket, this.key, e });
                } finally {
                    try {
                        object.close();
                    } catch (IOException e) {
                        // Don't care
                    }
                }
            }
        } catch (AmazonS3Exception ase) {
            LOG.error("Error loading config from s3://{}/{}", new Object[] { this.bucket, this.key, ase });
        }
    }
}

From source file:com.amediamanager.springconfig.ServerConfig.java

License:Apache License

@Bean
@Scope(WebApplicationContext.SCOPE_APPLICATION)
public AWSCredentialsProvider credentials() {
    return new AWSCredentialsProviderChain(new InstanceProfileCredentialsProvider(),
            new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider());
}

From source file:com.aws.credentials.AWSCredentialsProvider.java

License:Open Source License

public AWSCredentialsProvider() {

    super(new ClasspathPropertiesFileCredentialsProvider(), new InstanceProfileCredentialsProvider(),
            new SystemPropertiesCredentialsProvider(), new EnvironmentVariableCredentialsProvider());
}

From source file:com.dssmp.agent.AgentAWSCredentialsProviderChain.java

License:Apache License

public AgentAWSCredentialsProviderChain(AgentConfiguration config) {
    super(new AgentAWSCredentialsProvider(config), new EnvironmentVariableCredentialsProvider(),
            new SystemPropertiesCredentialsProvider(), new ProfileCredentialsProvider(),
            new InstanceProfileCredentialsProvider());
}

From source file:com.exorath.service.lobbymsg.impl.DynamoDBProvider.java

License:Apache License

public DynamoDB getDB() {
    AWSCredentials credentials = new EnvironmentVariableCredentialsProvider().getCredentials();
    return new DynamoDB(new AmazonDynamoDBClient(credentials).withRegion(Regions.EU_CENTRAL_1));
}

From source file:com.github.scizeron.logback.appender.SqsAppender.java

License:Apache License

/**
 * //  w  ww.  j  av a 2s.c  o  m
 * @return
 */
private AWSCredentialsProvider getCredentials() {
    return new AWSCredentialsProviderChain(new StaticCredentialsProvider(new AppenderCredentials()),
            new SystemPropertiesCredentialsProvider(), new EnvironmentVariableCredentialsProvider(),
            new ProfileCredentialsProvider(), new InstanceProfileCredentialsProvider());
}