diff --git a/.gitignore b/.gitignore index 4c98e9c67..6ee53c70b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ startVagrant.sh local-dev/oc minishift **/v8-* -node_modules +node_modules/ build/* !build/.gitkeep openshift diff --git a/services/api/src/dao.js b/services/api/src/dao.js index 5f0797d9f..c9b9a4d88 100644 --- a/services/api/src/dao.js +++ b/services/api/src/dao.js @@ -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'); @@ -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, diff --git a/services/api/src/schema.js b/services/api/src/schema.js index c7fc2b85a..972c25e34 100644 --- a/services/api/src/schema.js +++ b/services/api/src/schema.js @@ -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 diff --git a/services/mariadb/docker-entrypoint-initdb.d/01-procedures.sql b/services/mariadb/docker-entrypoint-initdb.d/01-procedures.sql index 76adba289..eb5efad75 100644 --- a/services/mariadb/docker-entrypoint-initdb.d/01-procedures.sql +++ b/services/mariadb/docker-entrypoint-initdb.d/01-procedures.sql @@ -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, @@ -68,6 +136,7 @@ CREATE OR REPLACE PROCEDURE END; $$ + CREATE OR REPLACE PROCEDURE CreateSshKey (