2022-10-11 13:29:23 +00:00
|
|
|
import { ensureItemDoesntExist, ensureItemExists } from './ensure';
|
2023-02-15 01:52:11 +00:00
|
|
|
import { API, Entity } from './types';
|
2022-04-28 10:35:02 +00:00
|
|
|
|
2023-02-15 01:52:11 +00:00
|
|
|
export function ensureProjectExists(api: API, projectName: string, orgId?: string) {
|
2022-10-11 13:29:23 +00:00
|
|
|
return ensureItemExists(
|
|
|
|
api,
|
|
|
|
`${api.mgmtBaseURL}/projects/_search`,
|
|
|
|
(project: any) => project.name === projectName,
|
|
|
|
`${api.mgmtBaseURL}/projects`,
|
|
|
|
{ name: projectName },
|
|
|
|
orgId,
|
|
|
|
);
|
2022-04-28 10:35:02 +00:00
|
|
|
}
|
|
|
|
|
2023-02-15 01:52:11 +00:00
|
|
|
export function ensureProjectDoesntExist(api: API, projectName: string, orgId?: string) {
|
2022-10-11 13:29:23 +00:00
|
|
|
return ensureItemDoesntExist(
|
2022-09-19 17:49:46 +00:00
|
|
|
api,
|
2022-10-11 13:29:23 +00:00
|
|
|
`${api.mgmtBaseURL}/projects/_search`,
|
2022-09-19 17:49:46 +00:00
|
|
|
(project: any) => project.name === projectName,
|
2022-10-11 13:29:23 +00:00
|
|
|
(project) => `${api.mgmtBaseURL}/projects/${project.id}`,
|
|
|
|
orgId,
|
2022-09-19 17:49:46 +00:00
|
|
|
);
|
2022-04-28 10:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class ResourceType {
|
2022-09-19 17:49:46 +00:00
|
|
|
constructor(public resourcePath: string, public compareProperty: string, public identifierProperty: string) {}
|
2022-04-28 10:35:02 +00:00
|
|
|
}
|
|
|
|
|
2022-09-19 17:49:46 +00:00
|
|
|
export const Apps = new ResourceType('apps', 'name', 'id');
|
|
|
|
export const Roles = new ResourceType('roles', 'key', 'key');
|
2022-04-28 10:35:02 +00:00
|
|
|
//export const Grants = new ResourceType('apps', 'name')
|
|
|
|
|
2022-09-19 17:49:46 +00:00
|
|
|
export function ensureProjectResourceDoesntExist(
|
2022-10-11 13:29:23 +00:00
|
|
|
api: API,
|
2023-02-15 01:52:11 +00:00
|
|
|
projectId: string,
|
2022-09-19 17:49:46 +00:00
|
|
|
resourceType: ResourceType,
|
|
|
|
resourceName: string,
|
2023-02-15 01:52:11 +00:00
|
|
|
orgId?: string,
|
2022-09-19 17:49:46 +00:00
|
|
|
): Cypress.Chainable<null> {
|
2022-10-11 13:29:23 +00:00
|
|
|
return ensureItemDoesntExist(
|
2022-09-19 17:49:46 +00:00
|
|
|
api,
|
2022-10-11 13:29:23 +00:00
|
|
|
`${api.mgmtBaseURL}/projects/${projectId}/${resourceType.resourcePath}/_search`,
|
2023-02-15 01:52:11 +00:00
|
|
|
(resource: Entity) => resource[resourceType.compareProperty] === resourceName,
|
|
|
|
(resource: Entity) =>
|
2022-10-11 13:29:23 +00:00
|
|
|
`${api.mgmtBaseURL}/projects/${projectId}/${resourceType.resourcePath}/${resource[resourceType.identifierProperty]}`,
|
|
|
|
orgId,
|
2022-09-19 17:49:46 +00:00
|
|
|
);
|
2022-04-28 10:35:02 +00:00
|
|
|
}
|
|
|
|
|
2023-02-15 01:52:11 +00:00
|
|
|
export function ensureApplicationExists(api: API, projectId: number, appName: string) {
|
2022-10-11 13:29:23 +00:00
|
|
|
return ensureItemExists(
|
2022-09-19 17:49:46 +00:00
|
|
|
api,
|
2022-10-11 13:29:23 +00:00
|
|
|
`${api.mgmtBaseURL}/projects/${projectId}/${Apps.resourcePath}/_search`,
|
2022-09-19 17:49:46 +00:00
|
|
|
(resource: any) => resource.name === appName,
|
2022-10-11 13:29:23 +00:00
|
|
|
`${api.mgmtBaseURL}/projects/${projectId}/${Apps.resourcePath}/oidc`,
|
2022-09-19 17:49:46 +00:00
|
|
|
{
|
|
|
|
name: appName,
|
|
|
|
redirectUris: ['https://e2eredirecturl.org'],
|
|
|
|
responseTypes: ['OIDC_RESPONSE_TYPE_CODE'],
|
|
|
|
grantTypes: ['OIDC_GRANT_TYPE_AUTHORIZATION_CODE'],
|
|
|
|
authMethodType: 'OIDC_AUTH_METHOD_TYPE_NONE',
|
|
|
|
postLogoutRedirectUris: ['https://e2elogoutredirecturl.org'],
|
|
|
|
},
|
|
|
|
);
|
2022-04-28 10:35:02 +00:00
|
|
|
}
|