本文整理汇总了Java中com.hazelcast.config.AwsConfig类的典型用法代码示例。如果您正苦于以下问题:Java AwsConfig类的具体用法?Java AwsConfig怎么用?Java AwsConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AwsConfig类属于com.hazelcast.config包,在下文中一共展示了AwsConfig类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: reviewConfiguration
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
private void reviewConfiguration(AwsConfig config) {
if (StringUtil.isNullOrEmptyAfterTrim(config.getSecretKey())
|| StringUtil.isNullOrEmptyAfterTrim(config.getAccessKey())) {
if (!StringUtil.isNullOrEmptyAfterTrim(config.getIamRole())) {
getLogger().info("Describe instances will be queried with iam-role, "
+ "please make sure given iam-role have ec2:DescribeInstances policy attached.");
} else {
getLogger().warning("Describe instances will be queried with iam-role assigned to EC2 instance, "
+ "please make sure given iam-role have ec2:DescribeInstances policy attached.");
}
} else {
if (!StringUtil.isNullOrEmptyAfterTrim(config.getIamRole())) {
getLogger().info("No need to define iam-role, when access and secret keys are configured!");
}
}
}
开发者ID:hazelcast,项目名称:hazelcast-aws,代码行数:18,代码来源:AwsDiscoveryStrategy.java
示例2: testSigning
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@Test
public void testSigning() throws NoSuchFieldException, IllegalAccessException, IOException {
AwsConfig awsConfig = new AwsConfig();
awsConfig.setRegion(TEST_REGION).
setHostHeader(TEST_HOST).
setAccessKey(TEST_ACCESS_KEY).
setSecretKey(TEST_SECRET_KEY);
DescribeInstances di = new DescribeInstances(awsConfig, TEST_HOST);
di.getRequestSigner();
Field attributesField = di.getClass().getDeclaredField("attributes");
attributesField.setAccessible(true);
Map<String, String> attributes = (Map<String, String>) attributesField.get(di);
attributes.put("X-Amz-Date", TEST_REQUEST_DATE);
EC2RequestSigner actual = new EC2RequestSigner(awsConfig, TEST_REQUEST_DATE, TEST_HOST);
attributes.put("X-Amz-Credential", actual.createFormattedCredential());
String signature = actual.sign(TEST_SERVICE, attributes);
assertEquals(TEST_SIGNATURE_EXPECTED, signature);
}
开发者ID:hazelcast,项目名称:hazelcast-aws,代码行数:23,代码来源:EC2RequestSignerTest.java
示例3: testIamRole
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@Test
public void testIamRole() throws IOException {
String s = "{\n"
+ " \"Code\" : \"Success\",\n"
+ " \"LastUpdated\" : \"2015-09-06T21:17:26Z\",\n"
+ " \"Type\" : \"AWS-HMAC\",\n"
+ " \"AccessKeyId\" : \"ASIAIEXAMPLEOXYDA\",\n"
+ " \"SecretAccessKey\" : \"hOCVge3EXAMPLExSJ+B\",\n"
+ " \"Token\" : \"AQoDYXdzEE4EXAMPLE2UGAFshkTsyw7gojLdiEXAMPLE+1SfSRTfLR\",\n"
+ " \"Expiration\" : \"2015-09-07T03:19:56Z\"\n}";
StringReader sr = new StringReader(s);
BufferedReader br = new BufferedReader(sr);
AwsConfig awsConfig1 = new AwsConfig();
awsConfig1.setAccessKey("some-access-key");
awsConfig1.setSecretKey("some-secret-key");
awsConfig1.setSecurityGroupName("hazelcast");
DescribeInstances describeInstances = new DescribeInstances(awsConfig, "");
Map map = describeInstances.parseIamRole(br);
assertEquals("Success", map.get("Code"));
assertEquals("2015-09-06T21:17:26Z", map.get("LastUpdated"));
assertEquals("AWS-HMAC", map.get("Type"));
assertEquals("ASIAIEXAMPLEOXYDA", map.get("AccessKeyId"));
assertEquals("hOCVge3EXAMPLExSJ+B", map.get("SecretAccessKey"));
assertEquals("AQoDYXdzEE4EXAMPLE2UGAFshkTsyw7gojLdiEXAMPLE+1SfSRTfLR", map.get("Token"));
}
开发者ID:hazelcast,项目名称:hazelcast-aws,代码行数:27,代码来源:CloudyUtilityTest.java
示例4: getAwsConfig
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
private AwsConfig getAwsConfig() throws IllegalArgumentException {
final AwsConfig config = new AwsConfig()
.setEnabled(true)
.setSecurityGroupName(getOrNull(SECURITY_GROUP_NAME))
.setTagKey(getOrNull(TAG_KEY))
.setTagValue(getOrNull(TAG_VALUE))
.setIamRole(getOrNull(IAM_ROLE));
String property = getOrNull(ACCESS_KEY);
if (property != null) {
config.setAccessKey(property);
}
property = getOrNull(SECRET_KEY);
if (property != null) {
config.setSecretKey(property);
}
final Integer timeout = getOrDefault(CONNECTION_TIMEOUT_SECONDS.getDefinition(), 10);
config.setConnectionTimeoutSeconds(timeout);
final String region = getOrNull(REGION);
if (region != null) {
config.setRegion(region);
}
final String hostHeader = getOrNull(HOST_HEADER);
if (hostHeader != null) {
config.setHostHeader(hostHeader);
}
reviewConfiguration(config);
return config;
}
开发者ID:hazelcast,项目名称:hazelcast-aws,代码行数:35,代码来源:AwsDiscoveryStrategy.java
示例5: AWSClient
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
public AWSClient(AwsConfig awsConfig) {
if (awsConfig == null) {
throw new IllegalArgumentException("AwsConfig is required!");
}
this.awsConfig = awsConfig;
this.endpoint = awsConfig.getHostHeader();
if (awsConfig.getRegion() != null && awsConfig.getRegion().length() > 0) {
if (!awsConfig.getHostHeader().startsWith("ec2.")) {
throw new InvalidConfigurationException("HostHeader should start with \"ec2.\" prefix");
}
setEndpoint(awsConfig.getHostHeader().replace("ec2.", "ec2." + awsConfig.getRegion() + "."));
}
}
开发者ID:hazelcast,项目名称:hazelcast-aws,代码行数:14,代码来源:AWSClient.java
示例6: TcpIpJoinerOverAWS
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
public TcpIpJoinerOverAWS(Node node) {
super(node);
logger = node.getLogger(getClass());
AwsConfig awsConfig = node.getConfig().getNetworkConfig().getJoin().getAwsConfig();
aws = new AWSClient(awsConfig);
}
开发者ID:hazelcast,项目名称:hazelcast-aws,代码行数:8,代码来源:TcpIpJoinerOverAWS.java
示例7: deriveSigningKeyTest
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@Test
public void deriveSigningKeyTest() throws Exception {
// this is from http://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html
AwsConfig awsConfig = new AwsConfig();
awsConfig.setRegion(TEST_REGION).
setHostHeader(TEST_HOST).
setAccessKey(TEST_ACCESS_KEY).
setSecretKey(TEST_SECRET_KEY);
DescribeInstances di = new DescribeInstances(awsConfig, TEST_HOST);
// Override the attributes map. We need to change values. Not pretty, but
// no real alternative, and in this case : testing only
Field field = di.getClass().getDeclaredField("attributes");
field.setAccessible(true);
Map<String, String> attributes = (Map<String, String>) field.get(di);
attributes.put("X-Amz-Date", TEST_REQUEST_DATE);
field.set(di, attributes);
// Override private method
EC2RequestSigner rs = new EC2RequestSigner(awsConfig, TEST_REQUEST_DATE, TEST_HOST);
field = rs.getClass().getDeclaredField("service");
field.setAccessible(true);
field.set(rs, "ec2");
Method method = rs.getClass().getDeclaredMethod("deriveSigningKey", null);
method.setAccessible(true);
byte[] derivedKey = (byte[]) method.invoke(rs);
assertEquals(TEST_DERIVED_EXPECTED, bytesToHex(derivedKey));
}
开发者ID:hazelcast,项目名称:hazelcast-aws,代码行数:32,代码来源:EC2RequestSignerTest.java
示例8: testLocalMetaData
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@Test
public void testLocalMetaData() {
AWSClient mockClient = spy(new AWSClient(new AwsConfig()));
doReturn("us-east-1a").when(mockClient).getAvailabilityZone();
AwsDiscoveryStrategy awsDiscoveryStrategy
= new AwsDiscoveryStrategy(Collections.<String, Comparable>emptyMap(), mockClient);
Map<String, Object> localMetaData = awsDiscoveryStrategy.discoverLocalMetadata();
String zone = (String) localMetaData.get(PARTITION_GROUP_ZONE);
assertEquals("us-east-1a", zone);
}
开发者ID:hazelcast,项目名称:hazelcast-aws,代码行数:11,代码来源:AwsDiscoveryStrategyTest.java
示例9: setup
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@Before
public void setup() {
awsConfig = new AwsConfig();
awsConfig.setAccessKey("some-access-key");
awsConfig.setSecretKey("some-secret-key");
awsConfig.setSecurityGroupName("hazelcast");
}
开发者ID:hazelcast,项目名称:hazelcast-aws,代码行数:8,代码来源:CloudyUtilityTest.java
示例10: testUnmarshalling
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@Test
public void testUnmarshalling() throws IOException {
InputStream is = new ByteArrayInputStream(xml.getBytes());
AwsConfig awsConfig1 = new AwsConfig();
awsConfig1.setAccessKey("some-access-key");
awsConfig1.setSecretKey("some-secret-key");
Map<String, String> result = CloudyUtility.unmarshalTheResponse(is);
assertEquals(2, result.size());
}
开发者ID:hazelcast,项目名称:hazelcast-aws,代码行数:11,代码来源:CloudyUtilityTest.java
示例11: testAwsClient_getEndPoint
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@Test
public void testAwsClient_getEndPoint() {
AwsConfig awsConfig = new AwsConfig();
awsConfig.setIamRole("test");
AWSClient awsClient = new AWSClient(awsConfig);
assertEquals("ec2.us-east-1.amazonaws.com", awsClient.getEndpoint());
}
开发者ID:hazelcast,项目名称:hazelcast-aws,代码行数:8,代码来源:AwsClientTest.java
示例12: testAwsClient_withDifferentHostHeader
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@Test
public void testAwsClient_withDifferentHostHeader() {
AwsConfig awsConfig = new AwsConfig();
awsConfig.setIamRole("test");
awsConfig.setHostHeader("ec2.amazonaws.com.cn");
awsConfig.setRegion("cn-north-1");
AWSClient awsClient = new AWSClient(awsConfig);
assertEquals("ec2.cn-north-1.amazonaws.com.cn", awsClient.getEndpoint());
}
开发者ID:hazelcast,项目名称:hazelcast-aws,代码行数:10,代码来源:AwsClientTest.java
示例13: testAwsClient_withInvalidHostHeader
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@Test(expected = InvalidConfigurationException.class)
public void testAwsClient_withInvalidHostHeader() {
AwsConfig awsConfig = new AwsConfig();
awsConfig.setIamRole("test");
awsConfig.setHostHeader("ec3.amazonaws.com.cn");
new AWSClient(awsConfig);
}
开发者ID:hazelcast,项目名称:hazelcast-aws,代码行数:8,代码来源:AwsClientTest.java
示例14: test_whenAccessKey_And_IamRole_And_IamTaskRoleEnvVar_Null_With_No_DefaultRole
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void test_whenAccessKey_And_IamRole_And_IamTaskRoleEnvVar_Null_With_No_DefaultRole() throws IOException {
Environment mockedEnv = mock(Environment.class);
when(mockedEnv.getEnvVar(Constants.ECS_CREDENTIALS_ENV_VAR_NAME)).thenReturn(null);
final String uri = INSTANCE_METADATA_URI + IAM_SECURITY_CREDENTIALS_URI;
DescribeInstances descriptor = spy(new DescribeInstances(new AwsConfig()));
doReturn("").when(descriptor).retrieveRoleFromURI(uri);
doReturn(mockedEnv).when(descriptor).getEnvironment();
descriptor.fillKeysFromIamRoles();
}
开发者ID:hazelcast,项目名称:hazelcast-aws,代码行数:13,代码来源:DescribeInstancesTest.java
示例15: test_whenAccessKeyExistsInConfig
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@Test
public void test_whenAccessKeyExistsInConfig() throws IOException {
AwsConfig awsConfig = new AwsConfig();
awsConfig.setAccessKey("accesskey");
awsConfig.setSecretKey("secretkey");
new DescribeInstances(awsConfig, "endpoint");
}
开发者ID:hazelcast,项目名称:hazelcast-aws,代码行数:8,代码来源:DescribeInstancesTest.java
示例16: test_whenIamRoleExistsInConfig
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@Test
public void test_whenIamRoleExistsInConfig() throws IOException {
final String someRole = "someRole";
final String uri = INSTANCE_METADATA_URI + IAM_SECURITY_CREDENTIALS_URI + someRole;
// some dummy creds. Look real, but they aren't.
final String accessKeyId = "ASIAJDOR231233BVE7GQ";
final String secretAccessKey = "QU5mTd40xnAbC5Mz2T3Fy7afQVrow+/tYq5GXMf7";
final String token = "FQoDYXdzEKX//////////wEaDN2Xh+ekVbV1KJrCqCK3A/Quuw8xCdZZbOPjzKLNc89n72z61BLt96hzlxTV6Vx1hDXLQNWRIx07hZVgmgGzzyr0DzYAcqKq7s2GUznWlaXhGHxhyo4nJUeBFbLyYPjbDAcnl84HItjy5bvtQ6fbDM7h2ZGuJrHi51KAhxWN/uEHyBKAIJd5RdXxVH4UTNxJFiqEw8GdaXDGK07186TfqSFCdlG+rhL35bN7WcJZuykIpynbeQpPeY4rJ0WJGoSJwt/RSkGwP+JRcYmv8Y7L1uSD2spJWO6etFeyyU63y0BL42MXWL38SQypxjLz+s1PozSDrV7zxsp4DQONn+adbSyAoveskD3xtDYsip1Ra0UCSYNKzmmh2XXF4fBBb6EPRixc1fnCIVDp0rfyCGO0VMuIloF5nWP9XsaRcR1mbJ7K/TuWgugduRBgyV2s1KgJuPni5cZ6ptEkPBb2b+92DjxEdQCAi6+WAdWliFiJ/P3T+qSJGLaxAeu0P0yb8E2xfCjEH6qOH3EM0KfgyJM5WJbXlYZTOZZXHaj26rlhe2k3wdL+UXf4geAzczphyOyp4QIGqaxe0xj08BKvSqngQb5X44oVR40oi7fOvwU=";
final String someDummyIamRole =
" {\n" +
" \"Code\" : \"Success\",\n" +
" \"LastUpdated\" : \"2016-10-04T12:08:24Z\",\n" +
" \"Type\" : \"AWS-HMAC\",\n" +
" \"AccessKeyId\" : \"" + accessKeyId + "\",\n" +
" \"SecretAccessKey\" : \"" + secretAccessKey + "\",\n" +
" \"Token\" : \"" + token + "\",\n" +
" \"Expiration\" : \"2016-10-04T18:19:39Z\"\n" +
" }\n";
AwsConfig awsConfig = new AwsConfig();
awsConfig.setIamRole(someRole);
DescribeInstances descriptor = spy(new DescribeInstances(awsConfig));
doReturn(someDummyIamRole).when(descriptor).retrieveRoleFromURI(uri);
descriptor.fillKeysFromIamRoles();
Assert.assertEquals("Could not parse access key from IAM role", accessKeyId, awsConfig.getAccessKey());
Assert.assertEquals("Could not parse secret key from IAM role", secretAccessKey, awsConfig.getSecretKey());
}
开发者ID:hazelcast,项目名称:hazelcast-aws,代码行数:34,代码来源:DescribeInstancesTest.java
示例17: test_when_Empty_IamRole_And_DefaultIamRole_But_IamTaskRoleEnvVar_Exists
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@Test
public void test_when_Empty_IamRole_And_DefaultIamRole_But_IamTaskRoleEnvVar_Exists() throws IOException {
final String accessKeyId = "ASIAJZ6Y3MXO7SRJ1234";
final String secretAccessKey = "p00VnhQ//HeT7W7V123f7BgYZaBlPZTxj9mcvSlc";
final String token = "FQoDYXdzEKX//////////wEaDDS1irrM7Wkt1VxNUyKoAxdXWEDQJUXpIGmBG4qCCiNLOXkF5mak8ZDVqS2PV+X7nsRF9C4mZwqMkGfRmxpZzGc+QTRfbncdZzEOeHcBea38mM7kJUJyNagWfNpwgzimgJzLqn5tNirs7+MXVw5rfblWCjngzjrovlsl6+q0K9LZM0W5OTRSKmEZQnJFjZh9w+BZHo5pair1ZqrxhfOcW6UaMpfOfRH/VI1n3u+De7YCqdq5jhmaDzWxewxccfH/BI2SRHaC1OEq0L3kMhwj1JrLjrOTJn4nBwjGZAlODFhoMec1cUW0GdIJN6+KZDbt8TuKlqDutKMDe1CNIH/697J0lLPMC8tgbgu3MrLSVxtQkMPdDMzJWNPXNQhQa+Nvw5w7gV7+27s9oat+dJBp3lLmTe4PZ810IQGa2NLZHKrv7kqGncLu5mURj+UVZHlueyYyPBWhVdHn4tCJ/cX2RaeqiVTbMILrduZePw7wTS8+19RnnPxA9wp45OZE5otSvNegJ9XhEJiU7RyJPhdSezMVoGsnzvgbCnBUAzHAe4ZuQZo7iIBWNXkcKBsCAU0MY8ym6NVn5VQohKrOvwU=";
// Note the below role is different from the regular IAM role, in that it doesn't contain new lines.
final String someDummyIamTaskRole =
"{" +
" \"RoleArn\":\"arn:aws:iam::123456789012:role/hazelcastIamTaskRole\"," +
" \"AccessKeyId\":\"" + accessKeyId + "\"," +
" \"SecretAccessKey\":\"" + secretAccessKey + "\"," +
" \"Token\":\"" + token + "\"," +
" \"Expiration\":\"2016-10-04T17:39:48Z\"" +
" }";
final String ecsEnvVarCredsUri = "someURL";
final String uri = DescribeInstances.IAM_TASK_ROLE_ENDPOINT + ecsEnvVarCredsUri;
final String defaultRoleUri = INSTANCE_METADATA_URI + IAM_SECURITY_CREDENTIALS_URI;
Environment mockedEnv = mock(Environment.class);
when(mockedEnv.getEnvVar(Constants.ECS_CREDENTIALS_ENV_VAR_NAME)).thenReturn(ecsEnvVarCredsUri);
AwsConfig awsConfig = new AwsConfig();
// test when default role is null
DescribeInstances descriptor = spy(new DescribeInstances(awsConfig));
doReturn(someDummyIamTaskRole).when(descriptor).retrieveRoleFromURI(uri);
doReturn("").when(descriptor).retrieveRoleFromURI(defaultRoleUri);
doReturn(mockedEnv).when(descriptor).getEnvironment();
descriptor.fillKeysFromIamRoles();
Assert.assertEquals("Could not parse access key from IAM task role", accessKeyId, awsConfig.getAccessKey());
Assert.assertEquals("Could not parse secret key from IAM task role", secretAccessKey, awsConfig.getSecretKey());
}
开发者ID:hazelcast,项目名称:hazelcast-aws,代码行数:40,代码来源:DescribeInstancesTest.java
示例18: test_DescribeInstances_SecurityGroup
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@Test
public void test_DescribeInstances_SecurityGroup()
throws Exception {
AwsConfig awsConfig = new AwsConfig();
awsConfig.setEnabled(true).setAccessKey(System.getenv("AWS_ACCESS_KEY_ID"))
.setSecretKey(System.getenv("AWS_SECRET_ACCESS_KEY")).setSecurityGroupName("launch-wizard-147");
getInstancesAndVerify(awsConfig);
}
开发者ID:hazelcast,项目名称:hazelcast-aws,代码行数:10,代码来源:DescribeInstancesTest.java
示例19: test_DescribeInstances_when_Tag_and_Value_Set
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@Test
public void test_DescribeInstances_when_Tag_and_Value_Set()
throws Exception {
AwsConfig awsConfig = new AwsConfig();
awsConfig.setEnabled(true).setAccessKey(System.getenv("AWS_ACCESS_KEY_ID"))
.setSecretKey(System.getenv("AWS_SECRET_ACCESS_KEY")).setTagKey("aws-test-tag").setTagValue("aws-tag-value-1");
getInstancesAndVerify(awsConfig);
}
开发者ID:hazelcast,项目名称:hazelcast-aws,代码行数:10,代码来源:DescribeInstancesTest.java
示例20: test_DescribeInstances_when_Only_TagKey_Set
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@Test
public void test_DescribeInstances_when_Only_TagKey_Set()
throws Exception {
AwsConfig awsConfig = new AwsConfig();
awsConfig.setEnabled(true).setAccessKey(System.getenv("AWS_ACCESS_KEY_ID"))
.setSecretKey(System.getenv("AWS_SECRET_ACCESS_KEY")).setTagKey("aws-test-tag");
getInstancesAndVerify(awsConfig);
}
开发者ID:hazelcast,项目名称:hazelcast-aws,代码行数:10,代码来源:DescribeInstancesTest.java
注:本文中的com.hazelcast.config.AwsConfig类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论