Skip to content

Commit

Permalink
fix(cli): fix seeder to handle empty data (#42)
Browse files Browse the repository at this point in the history
* fix(cli): fix seeder to handle empty data (#41)

fix(cli): fix seeder to handle empty values

* chore(cli): cleanup

* fix(cli): azure pipeline
  • Loading branch information
nnorbert authored Jun 26, 2024
1 parent ce792ab commit 9b91d9f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 28 deletions.
4 changes: 4 additions & 0 deletions azure_pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ stages:
awsServiceConnection: ${{ variables.awsServiceConnection }}
awsRegion: ${{ variables.awsRegion }}
serviceName: logto
- stage: Deploy_Logto_Admin
displayName: Deploy to ECS - logto Admin
dependsOn: Push_Logto
jobs:
- template: pipeline-templates/deploy_ecs.yml
parameters:
awsServiceConnection: ${{ variables.awsServiceConnection }}
Expand Down
20 changes: 10 additions & 10 deletions packages/cli/src/commands/database/ogcio/ogcio-seeder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
export type OgcioTenantSeeder = Record<string, OgcioSeeder>;

export type OgcioSeeder = {
organizations: OrganizationSeeder[];
organization_permissions: OrganizationPermissionSeeder[];
organization_roles: OrganizationRoleSeeder[];
applications: ApplicationSeeder[];
resources: ResourceSeeder[];
connectors: ConnectorSeeder[];
webhooks: WebhookSeeder[];
sign_in_experiences: SignInExperienceSeeder[];
resource_permissions: ResourcePermissionSeeder[];
resource_roles: ResourceRoleSeeder[];
organizations?: OrganizationSeeder[];
organization_permissions?: OrganizationPermissionSeeder[];
organization_roles?: OrganizationRoleSeeder[];
applications?: ApplicationSeeder[];
resources?: ResourceSeeder[];
connectors?: ConnectorSeeder[];
webhooks?: WebhookSeeder[];
sign_in_experiences?: SignInExperienceSeeder[];
resource_permissions?: ResourcePermissionSeeder[];
resource_roles?: ResourceRoleSeeder[];
};

export type OrganizationSeeder = {
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/commands/database/ogcio/ogcio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const createDataForTenant = async (
tenantId: string,
tenantData: OgcioSeeder
) => {
if (tenantData.organizations.length > 0) {
if (tenantData.organizations?.length) {
const organizations = await createOrganizations({
transaction,
tenantId,
Expand All @@ -33,15 +33,15 @@ const createDataForTenant = async (
toSeed: tenantData,
});

if (tenantData.applications.length > 0) {
if (tenantData.applications?.length) {
const applications = await seedApplications({
transaction,
tenantId,
applications: tenantData.applications,
});
}

if (tenantData.resources.length > 0) {
if (tenantData.resources?.length) {
const resources = await seedResources({
transaction,
tenantId,
Expand All @@ -56,23 +56,23 @@ const createDataForTenant = async (
});
}

if (tenantData.connectors.length > 0) {
if (tenantData.connectors?.length) {
const connectors = await seedConnectors({
transaction,
tenantId,
connectors: tenantData.connectors,
});
}

if (tenantData.sign_in_experiences.length > 0) {
if (tenantData.sign_in_experiences?.length) {
const signInExperiences = await seedSignInExperiences({
transaction,
tenantId,
experiences: tenantData.sign_in_experiences,
});
}

if (tenantData.webhooks.length > 0) {
if (tenantData.webhooks?.length) {
const webhooks = await seedWebhooks({
transaction,
tenantId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ export const seedOrganizationRbacData = async (params: {
transaction: DatabaseTransactionConnection;
tenantId: string;
toSeed: {
organization_permissions: OrganizationPermissionSeeder[];
organization_roles: OrganizationRoleSeeder[];
organization_permissions?: OrganizationPermissionSeeder[];
organization_roles?: OrganizationRoleSeeder[];
};
}): Promise<{
scopes: OrganizationScopesLists;
roles: Record<string, OrganizationSeedingRole>;
relations: SeedingRelation[];
}> => {
if (params.toSeed.organization_permissions.length > 0) {
if (params.toSeed.organization_permissions?.length && params.toSeed.organization_roles?.length) {
const createdScopes = await createScopes({
transaction: params.transaction,
tenantId: params.tenantId,
Expand Down
18 changes: 9 additions & 9 deletions packages/cli/src/commands/database/ogcio/resources-rbac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ const createRelations = async (params: {
const replaceWithResourceIdFromDatabase = (
seededResources: Record<string, SeedingResource>,
toSeed: {
resource_permissions: ResourcePermissionSeeder[];
resource_roles: ResourceRoleSeeder[];
resource_permissions?: ResourcePermissionSeeder[];
resource_roles?: ResourceRoleSeeder[];
}
): {
resource_permissions: ResourcePermissionSeeder[];
resource_roles: ResourceRoleSeeder[];
resource_permissions?: ResourcePermissionSeeder[];
resource_roles?: ResourceRoleSeeder[];
} => {
if (toSeed.resource_permissions.length > 0) {
if (toSeed.resource_permissions?.length) {
for (const permission of toSeed.resource_permissions) {
const toSetResourceIds = [];
for (const resourceId of permission.for_resource_ids) {
Expand All @@ -112,7 +112,7 @@ const replaceWithResourceIdFromDatabase = (
}
}

if (toSeed.resource_roles.length > 0) {
if (toSeed.resource_roles?.length) {
for (const roles of toSeed.resource_roles) {
const toSetResourceIds = [];
for (const permissionGroup of roles.permissions) {
Expand All @@ -137,16 +137,16 @@ export const seedResourceRbacData = async (params: {
tenantId: string;
seededResources: Record<string, SeedingResource>;
toSeed: {
resource_permissions: ResourcePermissionSeeder[];
resource_roles: ResourceRoleSeeder[];
resource_permissions?: ResourcePermissionSeeder[];
resource_roles?: ResourceRoleSeeder[];
};
}): Promise<{
scopes: ResourceScopesLists;
roles: Record<string, ResourceSeedingRole>;
relations: SeedingRelation[];
}> => {
params.toSeed = replaceWithResourceIdFromDatabase(params.seededResources, params.toSeed);
if (params.toSeed.resource_permissions.length > 0) {
if (params.toSeed.resource_permissions?.length && params.toSeed.resource_roles?.length) {
const createdScopes = await createScopes({
transaction: params.transaction,
tenantId: params.tenantId,
Expand Down

0 comments on commit 9b91d9f

Please sign in to comment.