@Test public void credentialGetterFunctionLenientTest() throws Exception{ Gson gson = new GsonBuilder().setPrettyPrinting().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .registerTypeAdapterFactory(new CaseInsensitiveEnumTypeAdapterFactory()) .create(); FileOutputStream fos = new FileOutputStream(new File(this.credentialsFilePath)); String s = gson.toJson(this.account0); fos.write(s.getBytes()); fos.write("\n".getBytes()); fos.write("\n".getBytes()); fos.write("\n".getBytes()); s = gson.toJson(this.account1); fos.write(s.getBytes()); fos.write("\n".getBytes()); fos.write("\n".getBytes()); fos.close(); CredentialGetterFunction cgf = new CredentialGetterFunction(AuthType.AWSV4, new File(this.credentialsFilePath), Api.S3); HashMap<String, String> hashMap = new LinkedHashMap<String, String>(); hashMap.put(Context.X_OG_CONTAINER_NAME, "container0"); Credential credential = cgf.apply(hashMap); assertThat(credential.getUsername(), is("gS2nuzatdztkeRhOm8kl")); assertThat(credential.getPassword(), is("ikGuemK3Q3HpeyAh72Ny47dH6ygGf3BhaMRwPZRx")); hashMap.put(Context.X_OG_CONTAINER_NAME, "container3"); credential = cgf.apply(hashMap); assertThat(credential.getUsername(), is("gS2nuzatdztkeRhOm8kk")); assertThat(credential.getPassword(), is("ikGuemK3Q3HpeyAh72Ny47dH6ygGf3BhaMRwPZRy")); }
@Override public Credential apply(final Map<String, String> context) { String containerName = context.get(Context.X_OG_CONTAINER_NAME); String accountName = containerAccountMap.get(containerName); if (accountName == null) { accountName = cyclicAccountsIterator.next().getKey(); } Account account = accountsMap.get(accountName); checkNotNull(account); Credential credential = null; if (AuthType.KEYSTONE == authType) { credential = new Credential(null, null, account.getToken(), null, accountName); } else if (AuthType.IAM == authType) { credential = new Credential(null, null, null, account.getToken(), null); } else if (AuthType.AWSV2 == authType || AuthType.AWSV4 == authType) { if (api == Api.OPENSTACK) { credential = new Credential(account.getAccessKey(), account.getSecretKey(), null, null, accountName); } else { credential = new Credential(account.getAccessKey(), account.getSecretKey(), null, null, null); } } else if (AuthType.BASIC == authType) { credential = new Credential(account.getBasicAuthUsername(), account.getBasicAuthPassword(), null, null, accountName); } return credential; }
CredentialGetterFunction implements Function<Map<String, String>, Credential> { @Override public Credential apply(final Map<String, String> context) { String containerName = context.get(Context.X_OG_CONTAINER_NAME); String accountName = containerAccountMap.get(containerName); if (accountName == null) { accountName = cyclicAccountsIterator.next().getKey(); } Account account = accountsMap.get(accountName); checkNotNull(account); Credential credential = null; if (AuthType.KEYSTONE == authType) { credential = new Credential(null, null, account.getToken(), null, accountName); } else if (AuthType.IAM == authType) { credential = new Credential(null, null, null, account.getToken(), null); } else if (AuthType.AWSV2 == authType || AuthType.AWSV4 == authType) { if (api == Api.OPENSTACK) { credential = new Credential(account.getAccessKey(), account.getSecretKey(), null, null, accountName); } else { credential = new Credential(account.getAccessKey(), account.getSecretKey(), null, null, null); } } else if (AuthType.BASIC == authType) { credential = new Credential(account.getBasicAuthUsername(), account.getBasicAuthPassword(), null, null, accountName); } return credential; } }
CredentialGetterFunction implements Function<Map<String, String>, Credential> { @Override public Credential apply(final Map<String, String> context) { String containerName = context.get(Context.X_OG_CONTAINER_NAME); String accountName = containerAccountMap.get(containerName); if (accountName == null) { accountName = cyclicAccountsIterator.next().getKey(); } Account account = accountsMap.get(accountName); checkNotNull(account); Credential credential = null; if (AuthType.KEYSTONE == authType) { credential = new Credential(null, null, account.getToken(), null, accountName); } else if (AuthType.IAM == authType) { credential = new Credential(null, null, null, account.getToken(), null); } else if (AuthType.AWSV2 == authType || AuthType.AWSV4 == authType) { if (api == Api.OPENSTACK) { credential = new Credential(account.getAccessKey(), account.getSecretKey(), null, null, accountName); } else { credential = new Credential(account.getAccessKey(), account.getSecretKey(), null, null, null); } } else if (AuthType.BASIC == authType) { credential = new Credential(account.getBasicAuthUsername(), account.getBasicAuthPassword(), null, null, accountName); } return credential; } CredentialGetterFunction(AuthType authType, File credentialFile, final Api api); }
CredentialGetterFunction implements Function<Map<String, String>, Credential> { @Override public Credential apply(final Map<String, String> context) { String containerName = context.get(Context.X_OG_CONTAINER_NAME); String accountName = containerAccountMap.get(containerName); if (accountName == null) { accountName = cyclicAccountsIterator.next().getKey(); } Account account = accountsMap.get(accountName); checkNotNull(account); Credential credential = null; if (AuthType.KEYSTONE == authType) { credential = new Credential(null, null, account.getToken(), null, accountName); } else if (AuthType.IAM == authType) { credential = new Credential(null, null, null, account.getToken(), null); } else if (AuthType.AWSV2 == authType || AuthType.AWSV4 == authType) { if (api == Api.OPENSTACK) { credential = new Credential(account.getAccessKey(), account.getSecretKey(), null, null, accountName); } else { credential = new Credential(account.getAccessKey(), account.getSecretKey(), null, null, null); } } else if (AuthType.BASIC == authType) { credential = new Credential(account.getBasicAuthUsername(), account.getBasicAuthPassword(), null, null, accountName); } return credential; } CredentialGetterFunction(AuthType authType, File credentialFile, final Api api); @Override Credential apply(final Map<String, String> context); }
CredentialGetterFunction implements Function<Map<String, String>, Credential> { @Override public Credential apply(final Map<String, String> context) { String containerName = context.get(Context.X_OG_CONTAINER_NAME); String accountName = containerAccountMap.get(containerName); if (accountName == null) { accountName = cyclicAccountsIterator.next().getKey(); } Account account = accountsMap.get(accountName); checkNotNull(account); Credential credential = null; if (AuthType.KEYSTONE == authType) { credential = new Credential(null, null, account.getToken(), null, accountName); } else if (AuthType.IAM == authType) { credential = new Credential(null, null, null, account.getToken(), null); } else if (AuthType.AWSV2 == authType || AuthType.AWSV4 == authType) { if (api == Api.OPENSTACK) { credential = new Credential(account.getAccessKey(), account.getSecretKey(), null, null, accountName); } else { credential = new Credential(account.getAccessKey(), account.getSecretKey(), null, null, null); } } else if (AuthType.BASIC == authType) { credential = new Credential(account.getBasicAuthUsername(), account.getBasicAuthPassword(), null, null, accountName); } return credential; } CredentialGetterFunction(AuthType authType, File credentialFile, final Api api); @Override Credential apply(final Map<String, String> context);  }