Skip to content

Commit

Permalink
Merge pull request #3341 from bomoko/fix/sensible_error_userbyssh
Browse files Browse the repository at this point in the history
closes #1549
  • Loading branch information
tobybellwood authored Nov 24, 2022
2 parents e6ffbd1 + 4bd37bf commit 42db581
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions services/api/src/resources/user/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ export const getMe: ResolverFn = async (_root, args, { models, keycloakGrant: gr
return models.UserModel.loadUserById(currentUserId);
}

class SearchInputError extends Error {
constructor(message: string) {
super(message);
this.name = 'SearchInputError';
}
}


export const getUserBySshKey: ResolverFn = async (
_root,
{ sshKey },
Expand All @@ -21,6 +29,10 @@ export const getUserBySshKey: ResolverFn = async (
// @ts-ignore
)(sshKey);

if(!keyType || !keyValue) {
throw new SearchInputError("Malformed ssh key provided. Should begin with key-type (eg. ssh-rsa|ssh-ed25519|etc.), then a space, then the key's value");
}

const rows = await query(
sqlClientPool,
Sql.selectUserIdBySshKey({ keyType, keyValue }),
Expand Down

0 comments on commit 42db581

Please sign in to comment.