Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion auth/src/main/java/org/gorpipe/gor/auth/AuthConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public interface AuthConfig extends Config {

@Documentation("")
@Key(PLATFORM_USER_KEY)
@DefaultValue("email")
@DefaultValue("preferred_username")
String getPlatformUserKey();

String UPDATE_AUTH_INFO_POLICY = "UPDATE_AUTH_INFO_POLICY";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
public class CredentialsHelperMain {
static class Options {
public String forProject;
public String forUser;
public String forUsername;
public String forUserid;
public String forService;
public String lookupKey;
public boolean base64;
Expand Down Expand Up @@ -90,9 +91,10 @@ public static Options processArgs(String[] args) {
public static void help(String message) {
if (message != null) System.err.println(message);
System.err.println(
"\nUsage: cred_helper --for-project projectName [--for-user userId] [--for-service service] [--lookup-key lookupKey] [--base64 | --sec] [--api-url apiUrl] [--api-user apiUser] [--api-password apiPassword] \n\n" +
"\nUsage: cred_helper --for-project projectName [--for-userName userName] [--for-userId userId] [--for-service service] [--lookup-key lookupKey] [--base64 | --sec] [--api-url apiUrl] [--api-user apiUser] [--api-password apiPassword] \n\n" +
"Fetches credentials from credentials service and prints (default as json object)\n" +
"projectName: internal project name of project to query\n" +
"userName: internal user name\n" +
"userId: id (numeric) of user to get credentials for\n" +
"service: restrict to service (e.g. dx or s3)\n" +
"lookupKey: provide a lookup key (e.g. bucket or dna nexus project id)\n" +
Expand Down Expand Up @@ -143,7 +145,7 @@ public String getPassword() {
}
};
CsaCredentialService service = new CsaCredentialService(config, null, new CredentialsParser(), null);
BundledCredentials bundle = service.getCredentialsBundle(options.forProject, options.forUser, options.forService, options.lookupKey);
BundledCredentials bundle = service.getCredentialsBundle(options.forProject, options.forUsername, options.forUserid, options.forService, options.lookupKey);
if (options.sec) {
System.out.println("cred_bundle=" + bundle.toBase64String());
} else if (options.base64) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private BundledCredentials getCredentialsBundleFromCache(String projectName, Str
try {
return credentialsCache.get(key, (k) -> {
try {
return getCredentialsBundle(projectName, userId);
return getCredentialsBundle(projectName, userName, userId);
} catch (IOException e) {
throw new UncheckedExecutionException(e);
}
Expand All @@ -72,18 +72,21 @@ private BundledCredentials getCredentialsBundleFromCache(String projectName, Str
}
}

private BundledCredentials getCredentialsBundle(String projectName, String userId) throws IOException {
return getCredentialsBundle(projectName, userId, null, null);
private BundledCredentials getCredentialsBundle(String projectName, String userName, String userId) throws IOException {
return getCredentialsBundle(projectName, userName, userId, null, null);
}

public BundledCredentials getCredentialsBundle(String projectName, String userId, String service, String lookupKey) throws IOException {
public BundledCredentials getCredentialsBundle(String projectName, String userName, String userId, String service, String lookupKey) throws IOException {
log.debug("get credentials for project: {}, user {}", projectName, userId);
if (!isConfigured()) {
log.info("No configuration - returning empty credentials list");
return BundledCredentials.emptyCredentials();
}
initAuth();
String parms = String.format("find[project_key]=%s", projectName);
if (!Strings.isNullOrEmpty(userName)) {
parms = parms + String.format("&find[preferred_username]=%s", userName);
}
if (!Strings.isNullOrEmpty(userId)) {
parms = parms + String.format("&find[user_id]=%s", userId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,40 @@ public String getenv(String env) {


@Test
public void testForUserOption() {
public void testForUserIdOption() {
List<String> unparsed = new ArrayList<>();
CredentialsHelperMain.Options options;

options = CredentialsHelperMain.Options.parse( new String[]{"--for-user", "123"}, unparsed);
Assert.assertEquals("123", options.forUser);
options = CredentialsHelperMain.Options.parse( new String[]{"--for-userId", "123"}, unparsed);
Assert.assertEquals("123", options.forUserid);

options = CredentialsHelperMain.Options.parse( new String[]{"--for-user", "abc"}, unparsed);
Assert.assertEquals("abc", options.forUser);
options = CredentialsHelperMain.Options.parse( new String[]{"--for-userId", "abc"}, unparsed);
Assert.assertEquals("abc", options.forUserid);

options = CredentialsHelperMain.Options.parse( new String[]{}, unparsed);
Assert.assertEquals(null, options.forUser);
Assert.assertEquals(null, options.forUserid);
}

@Test
public void testInvalidForUserOption() {
public void testForUserNameOption() {
List<String> unparsed = new ArrayList<>();
CredentialsHelperMain.Options options;

options = CredentialsHelperMain.Options.parse( new String[]{"--for-userName", "123"}, unparsed);
Assert.assertEquals("123", options.forUsername);

options = CredentialsHelperMain.Options.parse( new String[]{"--for-userName", "abc"}, unparsed);
Assert.assertEquals("abc", options.forUsername);

options = CredentialsHelperMain.Options.parse( new String[]{}, unparsed);
Assert.assertEquals(null, options.forUsername);
}

@Test
public void testInvalidForUserIdOption() {
List<String> unparsed = new ArrayList<>();
exit.expectSystemExitWithStatus(-1);
CredentialsHelperMain.Options.parse(new String[]{"--for-user"}, unparsed);
CredentialsHelperMain.Options.parse(new String[]{"--for-userId"}, unparsed);
}

@Test
Expand Down
Loading