Skip to content

Commit

Permalink
refactor: use separate functions for different policy types
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Oct 14, 2024
1 parent d4fd21a commit 6b3dce4
Show file tree
Hide file tree
Showing 10 changed files with 497 additions and 413 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,92 +128,78 @@ mutation PopulateApi {
id
}

RetPol1: createRetentionPolicy(input:{
RetPol1: createHarborRetentionPolicy(input:{
name: "harbor-policy"
type: HARBOR
harbor: {
enabled: true
rules: [
{
name: "all branches, excluding pullrequests"
pattern: "[^pr-]*/*"
latestPulled: 3
},
{
name: "pullrequests"
pattern: "pr-*"
latestPulled: 1
}
]
schedule: "3 * * * *"
}
enabled: true
rules: [
{
name: "all branches, excluding pullrequests"
pattern: "[^pr-]*/*"
latestPulled: 3
},
{
name: "pullrequests"
pattern: "pr-*"
latestPulled: 1
}
]
schedule: "3 * * * *"
}) {
id
name
configuration {
... on HarborRetentionPolicy {
enabled
rules {
name
pattern
latestPulled
}
schedule
enabled
rules {
name
pattern
latestPulled
}
schedule
}
type
created
updated
}

RetPol2: createRetentionPolicy(input:{
RetPol2: createHistoryRetentionPolicy(input:{
name: "history-policy"
type: HISTORY
history: {
enabled: true
deploymentHistory: 5
deploymentType: COUNT
taskHistory: 10
taskType: COUNT
}
enabled: true
deploymentHistory: 5
deploymentType: COUNT
taskHistory: 10
taskType: COUNT
}) {
id
name
configuration {
... on HistoryRetentionPolicy {
enabled
deploymentHistory
deploymentType
taskHistory
taskType
}
enabled
deploymentHistory
deploymentType
taskHistory
taskType
}
type
created
updated
}

RetPolLink1: addRetentionPolicyLink(input:{
id: 1
RetPolLink1: addHarborRetentionPolicyLink(input:{
name: "harbor-policy"
scope: GLOBAL
scopeName: "global",
}) {
id
name
type
source
created
updated
}

RetPolLink2: addRetentionPolicyLink(input:{
id: 2
RetPolLink2: addHistoryRetentionPolicyLink(input:{
name: "history-policy"
scope: GLOBAL
scopeName: "global",
}) {
id
name
type
source
created
updated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ exports.up = async function(knex) {
return knex.schema
.createTable('retention_policy', function (table) {
table.increments('id').notNullable().primary();
table.string('name', 300).unique({indexName: 'name'});
table.string('name', 300);
table.enu('type',['harbor','history']).notNullable();
table.text('configuration');
table.timestamp('updated').notNullable().defaultTo(knex.fn.now());
table.timestamp('created').notNullable().defaultTo(knex.fn.now());
table.unique(['name', 'type'], {indexName: 'retention_policy'});
})
.createTable('retention_policy_reference', function (table) {
table.integer('retention_policy');
Expand Down
102 changes: 0 additions & 102 deletions services/api/src/models/retentionpolicy.ts

This file was deleted.

67 changes: 34 additions & 33 deletions services/api/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,22 @@ const {
} = require('./resources/backup/resolvers');

const {
createRetentionPolicy,
updateRetentionPolicy,
deleteRetentionPolicy,
getRetentionPoliciesByProjectId,
getRetentionPoliciesByOrganizationId,
listRetentionPolicies,
addRetentionPolicyLink,
removeRetentionPolicyLink,
createHarborRetentionPolicy,
updateHarborRetentionPolicy,
createHistoryRetentionPolicy,
updateHistoryRetentionPolicy,
deleteHarborRetentionPolicy,
deleteHistoryRetentionPolicy,
getHarborRetentionPoliciesByProjectId,
getHarborRetentionPoliciesByOrganizationId,
getHistoryRetentionPoliciesByProjectId,
getHistoryRetentionPoliciesByOrganizationId,
listHarborRetentionPolicies,
listHistoryRetentionPolicies,
addHarborRetentionPolicyLink,
addHistoryRetentionPolicyLink,
removeHarborRetentionPolicyLink,
removeHistoryRetentionPolicyLink,
} = require('./resources/retentionpolicy/resolvers');

const {
Expand Down Expand Up @@ -387,10 +395,6 @@ const resolvers = {
ACTIVE: 'active',
SUCCEEDED: 'succeeded',
},
RetentionPolicyType: {
HARBOR: 'harbor',
HISTORY: 'history',
},
RetentionPolicyScope: {
GLOBAL: 'global',
ORGANIZATION: 'organization',
Expand Down Expand Up @@ -423,7 +427,8 @@ const resolvers = {
groups: getGroupsByProjectId,
privateKey: getPrivateKey,
publicKey: getProjectDeployKey,
retentionPolicies: getRetentionPoliciesByProjectId,
harborRetentionPolicies: getHarborRetentionPoliciesByProjectId,
historyRetentionPolicies: getHistoryRetentionPoliciesByProjectId,
},
GroupInterface: {
__resolveType(group) {
Expand Down Expand Up @@ -475,13 +480,15 @@ const resolvers = {
owners: getOwnersByOrganizationId,
deployTargets: getDeployTargetsByOrganizationId,
notifications: getNotificationsByOrganizationId,
retentionPolicies: getRetentionPoliciesByOrganizationId
harborRetentionPolicies: getHarborRetentionPoliciesByOrganizationId,
historyRetentionPolicies: getHistoryRetentionPoliciesByOrganizationId
},
OrgProject: {
groups: getGroupsByOrganizationsProject,
groupCount: getGroupCountByOrganizationProject,
notifications: getNotificationsForOrganizationProjectId,
retentionPolicies: getRetentionPoliciesByProjectId,
harborRetentionPolicies: getHarborRetentionPoliciesByProjectId,
historyRetentionPolicies: getHistoryRetentionPoliciesByProjectId,
},
OrgEnvironment: {
project: getProjectById,
Expand Down Expand Up @@ -529,18 +536,6 @@ const resolvers = {
}
}
},
RetentionPolicyConfiguration: {
__resolveType(obj) {
switch (obj.type) {
case 'harbor':
return 'HarborRetentionPolicy';
case 'history':
return 'HistoryRetentionPolicy';
default:
return null;
}
}
},
AdvancedTaskDefinition: {
__resolveType (obj) {
switch(obj.type) {
Expand Down Expand Up @@ -622,7 +617,8 @@ const resolvers = {
getProjectGroupOrganizationAssociation,
getEnvVariablesByProjectEnvironmentName,
checkBulkImportProjectsAndGroupsToOrganization,
listRetentionPolicies
listHarborRetentionPolicies,
listHistoryRetentionPolicies
},
Mutation: {
addProblem,
Expand Down Expand Up @@ -747,11 +743,16 @@ const resolvers = {
bulkImportProjectsAndGroupsToOrganization,
addOrUpdateEnvironmentService,
deleteEnvironmentService,
createRetentionPolicy,
updateRetentionPolicy,
deleteRetentionPolicy,
addRetentionPolicyLink,
removeRetentionPolicyLink
createHarborRetentionPolicy,
updateHarborRetentionPolicy,
deleteHarborRetentionPolicy,
addHarborRetentionPolicyLink,
removeHarborRetentionPolicyLink,
createHistoryRetentionPolicy,
updateHistoryRetentionPolicy,
deleteHistoryRetentionPolicy,
addHistoryRetentionPolicyLink,
removeHistoryRetentionPolicyLink,
},
Subscription: {
backupChanged: backupSubscriber,
Expand Down
Loading

0 comments on commit 6b3dce4

Please sign in to comment.