Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ryyppy authored and Schnitzel committed Nov 30, 2017
1 parent d33ce74 commit 65957b6
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ startVagrant.sh
local-dev/oc
minishift
**/v8-*
node_modules
node_modules/
build/*
!build/.gitkeep
openshift
Expand Down
35 changes: 35 additions & 0 deletions services/api/src/dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,36 @@
const R = require('ramda');
const promisify = require('util').promisify;

const updateProject = sqlClient => async (cred, input) => {
if (cred.role !== 'admin') {
throw new Error('Unauthorized');
}

return new Promise((res, rej) => {
// const prep = sqlClient.prepare(`
// CALL UpdateProject(
// :name,
// :customer,
// :git_url,
// :openshift,
// ${input.active_systems_deploy ? ':active_systems_deploy' : '"lagoon_openshiftBuildDeploy"'},
// ${input.active_systems_remove ? ':active_systems_remove' : '"lagoon_openshiftRemove"'},
// ${input.branches ? ':branches' : '"true"'},
// ${input.pullrequests ? 'IF(STRCMP(:pullrequests, \'true\'), 1, 0)' : 'NULL'},
// '${input.sshKeys ? input.sshKeys.join(',') : ''}'
// );
// `);

sqlClient.query(prep(input), (err, rows) => {
if (err) {
rej(err);
}

res(rows);
});
});
}

const getCustomerSshKeys = sqlClient => async cred => {
if (cred.role !== 'admin') {
throw new Error('Unauthorized');
Expand Down Expand Up @@ -473,8 +503,13 @@ const truncateTable = sqlClient => async (cred, args) => {
});
};

<<<<<<< HEAD:services/api/src/dao.js
const daoFns = {
getCustomerSshKeys,
=======
module.exports = {
updateProject,
>>>>>>> WIP:services/api-next/src/dao.js
getAllCustomers,
getOpenshiftByProjectId,
getProjectByGitUrl,
Expand Down
13 changes: 13 additions & 0 deletions services/api/src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,20 @@ const typeDefs = `
notificationName: String!
}
input ProjectUpdateInput {
name: String
customer: String
git_url: String
openshift: String
active_systems_deploy: String
active_systems_remove: String
branches: String
pullrequests: Boolean
sshKeys: [String]
}
type Mutation {
updateProject(input: ProjectUpdateInput!): Project
addProject(input: ProjectInput!): Project
addSshKey(input: SshKeyInput!): SshKey
addCustomer(input: CustomerInput!): Customer
Expand Down
71 changes: 70 additions & 1 deletion services/mariadb/docker-entrypoint-initdb.d/01-procedures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,75 @@ CREATE OR REPLACE PROCEDURE
IN ssh_key_names text
)
BEGIN
DECLARE new_pid int;
INSERT INTO project (
name,
customer,
git_url,
active_systems_deploy,
active_systems_remove,
branches,
pullrequests,
openshift
)
SELECT
name,
c.id,
git_url,
active_systems_deploy,
active_systems_remove,
branches,
pullrequests,
os.id
FROM
openshift AS os,
customer AS c
WHERE
os.name = openshift AND
c.name = customer;

-- Now add the ssh-key relation to the newly created project
SET new_pid = LAST_INSERT_ID();

INSERT INTO project_ssh_key (pid, skid)
SELECT
new_pid,
id
FROM ssh_key
WHERE FIND_IN_SET(ssh_key.name, ssh_key_names) > 0;

-- Return the constructed project
SELECT
p.id,
p.name,
p.customer,
p.git_url,
p.active_systems_deploy,
p.active_systems_remove,
p.branches,
p.pullrequests,
p.openshift
FROM project p
WHERE id = new_pid;
END;
$$

CREATE OR REPLACE PROCEDURE
UpdateProject
(
IN name varchar(100),
IN customer varchar(50),
IN git_url varchar(300),
IN openshift varchar(50),
IN active_systems_deploy varchar(300),
IN active_systems_remove varchar(300),
IN branches varchar(300),
IN pullrequests boolean,
IN ssh_key_names text
)
BEGIN
DECLARE pid int;

SELECT id INTO pid FROM project p WHERE p.name = name;

INSERT INTO project (
name,
Expand Down Expand Up @@ -68,6 +136,7 @@ CREATE OR REPLACE PROCEDURE
END;
$$


CREATE OR REPLACE PROCEDURE
CreateSshKey
(
Expand Down

0 comments on commit 65957b6

Please sign in to comment.