Skip to content

Commit

Permalink
Merge pull request #2837 from justinlevi/feature/LAGOON-23-Migrate-Bi…
Browse files Browse the repository at this point in the history
…lling-Code-From-API
  • Loading branch information
tobybellwood authored Jan 26, 2022
2 parents edf467d + 9d4fedf commit b42cc58
Show file tree
Hide file tree
Showing 38 changed files with 128 additions and 51,644 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,19 +311,6 @@ mutation PopulateApi {
) {
id
}
UIBillingGroup1: addBillingGroup(
input: { name: "High Cotton Billing Group", currency: USD }
) {
id
}
UIProject1BillingGroup1: addProjectToBillingGroup(
input: {
project: { name: "high-cotton" }
group: { name: "High Cotton Billing Group" }
}
) {
id
}
UIProject1Group5: addGroupsToProject(
input: {
project: {
Expand Down
14 changes: 0 additions & 14 deletions node-packages/commons/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1155,20 +1155,6 @@ export const getOpenShiftInfoForEnvironment = (environment: number): Promise<any
}
`);

export const getBillingGroupForProject = (project: string): Promise<any> =>
graphqlapi.query(`
{
project:projectByName(name: "${project}"){
groups {
... on BillingGroup {
type
uptimeRobotStatusPageId
}
}
}
}
`);

interface GetEnvironentsForProjectEnvironmentResult {
name: string;
id: number;
Expand Down
7 changes: 0 additions & 7 deletions node-packages/commons/src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
getOpenShiftInfoForProject,
getOpenShiftInfoForEnvironment,
getDeployTargetConfigsForProject,
getBillingGroupForProject,
addOrUpdateEnvironment,
getEnvironmentByName,
addDeployment
Expand Down Expand Up @@ -281,8 +280,6 @@ export const getControllerBuildData = async function(deployData: any) {

const result = await getOpenShiftInfoForProject(projectName);
const lagoonProjectData = result.project
const billingGroupResult = await getBillingGroupForProject(projectName);
const projectBillingGroup = billingGroupResult.project

var overlength = 58 - projectName.length;
if ( environmentName.length > overlength ) {
Expand Down Expand Up @@ -332,10 +329,6 @@ export const getControllerBuildData = async function(deployData: any) {
alertContact = "unconfigured"
}

const billingGroup = projectBillingGroup.groups.find(i => i.type == "billing" ) || ""
if (billingGroup.uptimeRobotStatusPageId && billingGroup.uptimeRobotStatusPageId != "null" && !R.isEmpty(billingGroup.uptimeRobotStatusPageId)){
uptimeRobotStatusPageIds.push(billingGroup.uptimeRobotStatusPageId)
}
var uptimeRobotStatusPageId = uptimeRobotStatusPageIds.join('-')

var pullrequestData: any = {};
Expand Down
16 changes: 0 additions & 16 deletions services/api-db/docker-entrypoint-initdb.d/00-tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,6 @@ CREATE TABLE IF NOT EXISTS project (
private_key varchar(5000)
);

CREATE TABLE IF NOT EXISTS billing_modifier (
id int NOT NULL auto_increment PRIMARY KEY,
group_id varchar(36),
weight int NOT NULL DEFAULT 0,
start_date datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
end_date datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
discount_fixed DECIMAL NULL DEFAULT 0,
discount_percentage FLOAT NULL DEFAULT 0,
extra_fixed DECIMAL NULL DEFAULT 0,
extra_percentage FLOAT NULL DEFAULT 0,
min FLOAT NULL DEFAULT 0,
max FLOAT NULL DEFAULT 0,
customer_comments text,
admin_comments text
);

CREATE TABLE IF NOT EXISTS environment (
id int NOT NULL auto_increment PRIMARY KEY,
name varchar(100),
Expand Down
29 changes: 9 additions & 20 deletions services/api-db/docker-entrypoint-initdb.d/01-migrations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1235,25 +1235,6 @@ CREATE OR REPLACE PROCEDURE
END;
$$

CREATE OR REPLACE PROCEDURE
add_min_max_to_billing_modifier()

BEGIN
IF NOT EXISTS (
SELECT NULL
FROM INFORMATION_SCHEMA.COLUMNS
WHERE
table_name = 'billing_modifier'
AND table_schema = 'infrastructure'
AND column_name = 'min'
) THEN
ALTER TABLE `billing_modifier`
ADD `min` FLOAT DEFAULT 0,
ADD `max` FLOAT DEFAULT 0;
END IF;
END;
$$

CREATE OR REPLACE PROCEDURE
convert_project_production_routes_to_text()

Expand Down Expand Up @@ -1479,6 +1460,14 @@ CREATE OR REPLACE PROCEDURE
END;
$$

CREATE OR REPLACE PROCEDURE
drop_billing_data()

BEGIN
DROP TABLE IF EXISTS billing_modifier;
END;
$$

DELIMITER ;

-- If adding new procedures, add them to the bottom of this list
Expand Down Expand Up @@ -1537,7 +1526,6 @@ CALL add_fact_type_to_environment_fact();
CALL add_fact_category_to_environment_fact();
CALL add_fact_key_to_environment_fact();
CALL add_metadata_to_project();
CALL add_min_max_to_billing_modifier();
CALL add_content_type_to_project_notification();
CALL convert_project_production_routes_to_text();
CALL convert_project_standby_routes_to_text();
Expand All @@ -1551,6 +1539,7 @@ CALL add_openshift_project_pattern_to_environment();
CALL add_deployments_disabled_to_project();
CALL update_openshift_varchar_length();
CALL migrate_project_openshift_to_environment();
CALL drop_billing_data();

-- Drop legacy SSH key procedures
DROP PROCEDURE IF EXISTS CreateProjectSshKey;
Expand Down
3 changes: 0 additions & 3 deletions services/api/src/apolloServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const resolvers = require('./resolvers');

const User = require('./models/user');
const Group = require('./models/group');
const BillingModel = require('./models/billing');
const ProjectModel = require('./models/project');
const EnvironmentModel = require('./models/environment');

Expand Down Expand Up @@ -117,7 +116,6 @@ const apolloServer = new ApolloServer({
models: {
UserModel: User.User(modelClients),
GroupModel: Group.Group(modelClients),
BillingModel: BillingModel.BillingModel(modelClients),
ProjectModel: ProjectModel.ProjectModel(modelClients),
EnvironmentModel: EnvironmentModel.EnvironmentModel(modelClients)
}
Expand Down Expand Up @@ -175,7 +173,6 @@ const apolloServer = new ApolloServer({
models: {
UserModel: User.User(modelClients),
GroupModel: Group.Group(modelClients),
BillingModel: BillingModel.BillingModel(modelClients),
ProjectModel: ProjectModel.ProjectModel(modelClients),
EnvironmentModel: EnvironmentModel.EnvironmentModel(modelClients)
}
Expand Down
2 changes: 1 addition & 1 deletion services/api/src/fragmentTypes.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"__schema":{"types":[{"kind":"INTERFACE","name":"GroupInterface","possibleTypes":[{"name":"BillingGroup"},{"name":"Group"}]},{"kind":"UNION","name":"Notification","possibleTypes":[{"name":"NotificationRocketChat"},{"name":"NotificationSlack"},{"name":"NotificationMicrosoftTeams"},{"name":"NotificationEmail"}]}]}}
{"__schema":{"types":[{"kind":"INTERFACE","name":"GroupInterface","possibleTypes":[{"name":"Group"}]},{"kind":"UNION","name":"Notification","possibleTypes":[{"name":"NotificationRocketChat"},{"name":"NotificationSlack"},{"name":"NotificationMicrosoftTeams"},{"name":"NotificationEmail"}]}]}}
146 changes: 0 additions & 146 deletions services/api/src/helpers/billingGroups.ts

This file was deleted.

24 changes: 9 additions & 15 deletions services/api/src/helpers/sync-groups-opendistro-security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,12 @@ import { getKeycloakAdminClient } from '../clients/keycloak-admin';

const allGroups = await GroupModel.loadAllGroups();

// This filters out Billing Groups that we don't need to create in Opendistro/Kibana
const userGroups = allGroups.filter(
({ type }) => type !== 'billing' && type !== 'billing-poly'
);

let groupsQueue = (userGroups as Group[]).map(group => ({
let groupsQueue = (allGroups as Group[]).map(group => ({
group,
retries: 0
}));

logger.info(`Syncing ${userGroups.length} groups`);
logger.info(`Syncing ${allGroups.length} groups`);

while (groupsQueue.length > 0) {
const { group, retries } = groupsQueue.shift();
Expand All @@ -50,20 +45,19 @@ import { getKeycloakAdminClient } from '../clients/keycloak-admin';
const projectIds = R.join(',')(projectIdsArray);

let roleName = group.name;
if(group.type && group.type == 'project-default-group') {
roleName = "p" + projectIds;
if (group.type && group.type == 'project-default-group') {
roleName = 'p' + projectIds;
}

let tenantName = group.name;
if(group.type && group.type == 'project-default-group') {
if (group.type && group.type == 'project-default-group') {
tenantName = 'global_tenant';
}

await OpendistroSecurityOperations(sqlClientPool, GroupModel).syncGroupWithSpecificTenant(
roleName,
tenantName,
projectIds
);
await OpendistroSecurityOperations(
sqlClientPool,
GroupModel
).syncGroupWithSpecificTenant(roleName, tenantName, projectIds);
} catch (err) {
if (retries < 3) {
logger.warn(`Error syncing, adding to end of queue: ${err.message}`);
Expand Down
Loading

0 comments on commit b42cc58

Please sign in to comment.