Skip to content

Commit

Permalink
Merge pull request #2929 from uselagoon/2755-fix-addKubernetes-no-id
Browse files Browse the repository at this point in the history
  • Loading branch information
tobybellwood authored Nov 29, 2021
2 parents 04fc9b8 + 9bfb3a7 commit 378bb8f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 73 deletions.
54 changes: 1 addition & 53 deletions services/api-db/docker-entrypoint-initdb.d/03-procedures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -284,59 +284,7 @@ CREATE OR REPLACE PROCEDURE
END;
$$

CREATE OR REPLACE PROCEDURE
CreateOpenshift
(
IN id int,
IN name varchar(50),
IN console_url varchar(300),
IN token varchar(2000),
IN router_pattern varchar(300),
IN project_user varchar(100),
IN ssh_host varchar(300),
IN ssh_port varchar(50),
IN monitoring_config varchar(2048)
)
BEGIN
DECLARE new_oid int;

IF (id IS NULL) THEN
SET id = 0;
END IF;

INSERT INTO openshift (
id,
name,
console_url,
token,
router_pattern,
project_user,
ssh_host,
ssh_port,
monitoring_config
) VALUES (
id,
name,
console_url,
token,
router_pattern,
project_user,
ssh_host,
ssh_port,
monitoring_config
);

IF (id = 0) THEN
SET new_oid = LAST_INSERT_ID();
ELSE
SET new_oid = id;
END IF;

SELECT
o.*
FROM openshift o
WHERE o.id = new_oid;
END;
DROP PROCEDURE IF EXISTS CreateOpenshift;
$$

CREATE OR REPLACE PROCEDURE
Expand Down
24 changes: 5 additions & 19 deletions services/api/src/resources/openshift/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,10 @@ export const addOpenshift: ResolverFn = async (
) => {
await hasPermission('openshift', 'add');

const rows = await query(
sqlClientPool,
`CALL CreateOpenshift(
:id,
:name,
:console_url,
${input.token ? ':token' : 'NULL'},
${input.routerPattern ? ':router_pattern' : 'NULL'},
${input.projectUser ? ':project_user' : 'NULL'},
${input.sshHost ? ':ssh_host' : 'NULL'},
${input.sshPort ? ':ssh_port' : 'NULL'},
${input.monitoringConfig ? ':monitoring_config' : 'NULL'}
);`,
input
);
const openshift = R.path([0, 0], rows);
const { insertId } = await query(sqlClientPool, Sql.insertOpenshift(input));

return openshift;
const rows = await query(sqlClientPool, Sql.selectOpenshift(insertId));
return R.prop(0, rows);
};

export const deleteOpenshift: ResolverFn = async (
Expand Down Expand Up @@ -68,7 +54,7 @@ export const getOpenshiftByProjectId: ResolverFn = async (
{ sqlClientPool, hasPermission }
) => {
await hasPermission('openshift', 'view', {
project: pid,
project: pid
});

const rows = await query(
Expand Down Expand Up @@ -105,7 +91,7 @@ export const getOpenshiftByDeployTargetId: ResolverFn = async (

// check permissions on the project
await hasPermission('openshift', 'view', {
project: projectrows[0].project,
project: projectrows[0].project
});

const rows = await query(
Expand Down
42 changes: 41 additions & 1 deletion services/api/src/resources/openshift/sql.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,47 @@
import { knex } from '../../util/db';

export const Sql = {
updateOpenshift: ({ id, patch }: { id: number; patch: { [key: string]: any } }) =>
insertOpenshift: ({
id,
name,
consoleUrl,
token,
routerPattern,
projectUser,
sshHost,
sshPort,
monitoringConfig
}: {
id?: number;
name: string;
consoleUrl: string;
token?: string;
routerPattern?: string;
projectUser?: string;
sshHost?: string;
sshPort?: string;
monitoringConfig?: JSON;
}) =>
knex('openshift')
.insert({
id,
name,
consoleUrl,
token,
routerPattern,
projectUser,
sshHost,
sshPort,
monitoringConfig
})
.toString(),
updateOpenshift: ({
id,
patch
}: {
id: number;
patch: { [key: string]: any };
}) =>
knex('openshift')
.where('id', '=', id)
.update(patch)
Expand Down

0 comments on commit 378bb8f

Please sign in to comment.