[CORL-750] SSO Migration Script Bug (#2715)

* fix: fixed bug with sso migration script

* feat: refactored sso schema

* fix: resolved issue with data race and migration/install ordering
This commit is contained in:
Wyatt Johnson
2019-11-18 23:11:20 +00:00
committed by GitHub
parent 9e9c016f4b
commit aa9dcb4e04
13 changed files with 331 additions and 122 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ export async function createInvite(
};
// Insert it into the database. This may throw an error.
await collection(mongo).insert(invite);
await collection(mongo).insertOne(invite);
return invite;
}
+9 -12
View File
@@ -1,4 +1,4 @@
import { Omit, RequireProperty } from "coral-common/types";
import { Omit } from "coral-common/types";
import {
GQLAuth,
@@ -46,30 +46,27 @@ export interface SSOKey {
kid: string;
/**
* secret is the actual underlying secret used to verify the tokens with. When
* this is not available, it indicates that the token secret was deleted.
* secret is the actual underlying secret used to verify the tokens with.
*/
secret?: string;
secret: string;
/**
* createdAt is the time that this key was created at.
* createdAt is the date that the key was created at.
*/
createdAt: Date;
/**
* deprecateAt when provided is the time that the token should no longer be
* valid at.
* rotatedAt is the time that the token was rotated out.
*/
deprecateAt?: Date;
rotatedAt?: Date;
/**
* deletedAt is the timestamp that the token was revoked.
* inactiveAt is the date that the token can no longer be used to validate
* tokens.
*/
deletedAt?: Date;
inactiveAt?: Date;
}
export type RequiredSSOKey = RequireProperty<SSOKey, "secret">;
export interface SSOAuthIntegration {
enabled: boolean;
allowRegistration: boolean;
+6 -4
View File
@@ -199,7 +199,7 @@ export async function createTenant(
};
// Insert the Tenant into the database.
await collection(mongo).insert(tenant);
await collection(mongo).insertOne(tenant);
return tenant;
}
@@ -306,18 +306,20 @@ export async function createTenantSSOKey(mongo: Db, id: string, now: Date) {
return result.value || null;
}
export async function deprecateTenantSSOKey(
export async function rotateTenantSSOKey(
mongo: Db,
id: string,
kid: string,
deprecateAt: Date
inactiveAt: Date,
now: Date
) {
// Update the tenant.
const result = await collection(mongo).findOneAndUpdate(
{ id },
{
$set: {
"auth.integrations.sso.keys.$[keys].deprecateAt": deprecateAt,
"auth.integrations.sso.keys.$[keys].inactiveAt": inactiveAt,
"auth.integrations.sso.keys.$[keys].rotatedAt": now,
},
},
{