Structure args, return inflated ent
Signed-off-by: Tim Hansen <timbonicus@gmail.com>
This commit is contained in:
@@ -118,10 +118,10 @@ describe('CatalogIdentityClient', () => {
|
||||
tokenIssuer,
|
||||
});
|
||||
|
||||
const claims = await client.resolveCatalogMemberClaims('inigom', [
|
||||
'User:default/imontoya',
|
||||
'User:reality/mpatinkin',
|
||||
]);
|
||||
const claims = await client.resolveCatalogMemberClaims({
|
||||
sub: 'inigom',
|
||||
ent: ['User:default/imontoya', 'User:reality/mpatinkin'],
|
||||
});
|
||||
|
||||
expect(catalogApi.getEntities).toHaveBeenCalledWith({
|
||||
filter: [
|
||||
@@ -143,16 +143,11 @@ describe('CatalogIdentityClient', () => {
|
||||
],
|
||||
});
|
||||
|
||||
expect(claims).toMatchObject({
|
||||
claims: {
|
||||
sub: 'inigom',
|
||||
ent: [
|
||||
'user:default/imontoya',
|
||||
'user:reality/mpatinkin',
|
||||
'group:default/team-a',
|
||||
'group:reality/screen-actors-guild',
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(claims).toMatchObject([
|
||||
'user:default/imontoya',
|
||||
'user:reality/mpatinkin',
|
||||
'group:default/team-a',
|
||||
'group:reality/screen-actors-guild',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -24,12 +24,18 @@ import {
|
||||
stringifyEntityRef,
|
||||
UserEntity,
|
||||
} from '@backstage/catalog-model';
|
||||
import { TokenIssuer, TokenParams } from '../../identity';
|
||||
import { TokenIssuer } from '../../identity';
|
||||
|
||||
type UserQuery = {
|
||||
annotations: Record<string, string>;
|
||||
};
|
||||
|
||||
type MemberClaimQuery = {
|
||||
sub: string;
|
||||
ent: string[];
|
||||
logger?: Logger;
|
||||
};
|
||||
|
||||
/**
|
||||
* A catalog client tailored for reading out identity data from the catalog.
|
||||
*/
|
||||
@@ -78,14 +84,13 @@ export class CatalogIdentityClient {
|
||||
* provided, but group membership and transient group membership lean on imported catalog
|
||||
* relations.
|
||||
*
|
||||
* Returns a claim structure that can be passed directly to `issueToken`, with the same sub and a
|
||||
* superset of `ent` claims.
|
||||
* Returns a superset of the `ent` argument that can be passed directly to `issueToken` as `ent`.
|
||||
*/
|
||||
async resolveCatalogMemberClaims(
|
||||
sub: string,
|
||||
ent: string[],
|
||||
logger?: Logger,
|
||||
): Promise<TokenParams> {
|
||||
async resolveCatalogMemberClaims({
|
||||
sub,
|
||||
ent,
|
||||
logger,
|
||||
}: MemberClaimQuery): Promise<string[]> {
|
||||
const subRef: EntityName = parseEntityRef(sub, {
|
||||
defaultKind: 'user',
|
||||
defaultNamespace: 'default',
|
||||
@@ -139,11 +144,6 @@ export class CatalogIdentityClient {
|
||||
);
|
||||
|
||||
logger?.debug(`Found claims for ${sub} in the catalog: ${newEnt.join()}`);
|
||||
return {
|
||||
claims: {
|
||||
sub,
|
||||
ent: newEnt,
|
||||
},
|
||||
};
|
||||
return newEnt;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user