Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mark repos soft delete #276

Merged
merged 8 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,39 @@ jobs:
# Deploy Helm Chart
cd charts/pubcode
helm dependency update
helm upgrade --install --wait --atomic pubcode-${{ github.event.number }} --values values-pr.yaml --set-string global.repository=${{ github.repository }} --set-string api.containers[0].tag="${{ github.sha }}" --set-string frontend.containers[0].tag="${{ github.sha }}" --set-string global.secrets.emailRecipients="${{ secrets.EMAIL_RECIPIENTS }}" --set-string global.secrets.chesTokenURL="${{ secrets.CHES_TOKEN_URL }}" --set-string global.secrets.chesClientID="${{ secrets.CHES_CLIENT_ID }}" --set-string global.secrets.chesClientSecret="${{ secrets.CHES_CLIENT_SECRET }}" --set-string global.secrets.chesAPIURL="${{ secrets.CHES_API_URL }}" --set-string global.secrets.databaseAdminPassword="${{ secrets.DB_PWD }}" --set-string global.env.VITE_SCHEMA_BRANCH=${{ github.event.pull_request.head.ref }} --set-string namespace="${{ vars.oc_namespace }}" --timeout 5m .
helm upgrade --install --wait --atomic pubcode-${{ github.event.number }} \
--set-string global.repository=${{ github.repository }} \
--set-string api.containers[0].tag="${{ github.sha }}" \
--set-string api.containers[0].resources.limits.cpu="250m" \
--set-string api.containers[0].resources.limits.memory="250Mi" \
--set-string api.containers[0].resources.requests.cpu="100m" \
--set-string api.containers[0].resources.requests.memory="150Mi" \
--set api.autoscaling.minReplicas=1 \
--set api.autoscaling.maxReplicas=1 \
--set frontend.autoscaling.minReplicas=1 \
--set frontend.autoscaling.maxReplicas=1 \
--set-string frontend.containers[0].tag="${{ github.sha }}" \
--set-string frontend.containers[0].resources.limits.cpu="200m" \
--set-string frontend.containers[0].resources.limits.memory="150Mi" \
--set-string frontend.containers[0].resources.requests.cpu="100m" \
--set-string frontend.containers[0].resources.requests.memory="50Mi" \
--set-string database.containers[0].resources.limits.cpu="500m" \
--set-string database.containers[0].resources.limits.memory="450Mi" \
--set-string database.containers[0].resources.requests.cpu="100m" \
--set-string database.containers[0].resources.requests.memory="150Mi" \
--set-string database.initContainers[0].resources.limits.cpu="500m" \
--set-string database.initContainers[0].resources.limits.memory="450Mi" \
--set-string database.initContainers[0].resources.requests.cpu="100m" \
--set-string database.initContainers[0].resources.requests.memory="150Mi" \
--set-string database.pvc.size="350Mi" \
--set-string global.secrets.emailRecipients="${{ secrets.EMAIL_RECIPIENTS }}" \
--set-string global.secrets.chesTokenURL="${{ secrets.CHES_TOKEN_URL }}" \
--set-string global.secrets.chesClientID="${{ secrets.CHES_CLIENT_ID }}" \
--set-string global.secrets.chesClientSecret="${{ secrets.CHES_CLIENT_SECRET }}" \
--set-string global.secrets.chesAPIURL="${{ secrets.CHES_API_URL }}" \
--set-string global.secrets.databaseAdminPassword="${{ secrets.DB_PWD }}" \
--set-string global.env.VITE_SCHEMA_BRANCH=${{ github.event.pull_request.head.ref }} \
--set-string namespace="${{ vars.oc_namespace }}" -f values.yaml --timeout 5m .

cypress-e2e:
name: Cypress end to end test
Expand Down
4 changes: 4 additions & 0 deletions api/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,9 @@ app.get("/", (req, res, next) => {
});
app.use(/(\/api)?/, apiRouter);
apiRouter.use("/pub-code", pubcodeRouter);
app.use((req, res, next) => {
res.status(404).send(
"<h1>Not Found.</h1>");
});

module.exports = app;
15 changes: 8 additions & 7 deletions api/src/email/ches-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ChesService {
});
return { data, status };
} catch (e) {
console.log(SERVICE, e);
console.error(SERVICE, e);
}
}

Expand All @@ -52,7 +52,7 @@ class ChesService {
return { data, status };
}
} catch (e) {
console.log(SERVICE, e);
console.error(SERVICE, e);
}
}

Expand Down Expand Up @@ -81,7 +81,7 @@ class ChesService {
return { data, status };
}
} catch (e) {
console.log(SERVICE, e);
console.error(SERVICE, e);
}
}

Expand All @@ -100,7 +100,8 @@ class ChesService {
);
return { data, status };
} catch (e) {
console.log(SERVICE, e?.config?.data?.errors);
console.error(e);
console.error(SERVICE, e?.config?.data?.errors);
}
}

Expand All @@ -119,7 +120,7 @@ class ChesService {
);
return { data, status };
} catch (e) {
console.log(SERVICE, e);
console.error(SERVICE, e);
}
}

Expand All @@ -138,7 +139,7 @@ class ChesService {
);
return { data, status };
} catch (e) {
console.log(SERVICE, e);
console.error(SERVICE, e);
}
}

Expand Down Expand Up @@ -167,7 +168,7 @@ class ChesService {
return { data, status };
}
} catch (e) {
console.log(SERVICE, e);
console.error(SERVICE, e);
}
}

Expand Down
14 changes: 11 additions & 3 deletions api/src/routes/pubcode-router.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const express = require("express");
const router = express.Router();
const { bulkLoad, readAll, findById, health } = require("../services/pub-code-service");
const { bulkLoad, readAll, findById, health, softDeleteRepo } = require("../services/pub-code-service");

router.get("/ip/trace", (request, response) => response.send(request.ip));
router.get("/health", health);
Expand All @@ -11,8 +11,16 @@ router.post("/bulk-load", (req, res, next) => {
res.status(401).json({ message: "Unauthorized" });
}
}, bulkLoad);

/**
* This method allows for patching the objects with soft
*/
router.delete("/:repo_name", (req, res, next) => {
if (req.header("X-API-KEY") && req.header("X-API-KEY") === process.env.API_KEY) {
next();
} else {
res.status(401).json({ message: "Unauthorized" });
}
}, softDeleteRepo);
router.get("/", readAll);
router.get("/:id", findById);

module.exports = router;
16 changes: 15 additions & 1 deletion api/src/services/pub-code-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,24 @@ const health = async (req, res) => {
res.status(500).json(error);
}
};
const softDeleteRepo = async (req, res) => {
try{
const pubcodeEntityFromDB = await pubcodeEntity.findOne({ repo_name: req.params.repo_name }).exec();
if(!pubcodeEntityFromDB){
res.status(404).json({message: "Repo Not Found"});
}else{
await pubcodeEntityFromDB.updateOne({isDeleted: true});
res.status(200).json({message: "Repo Marked as soft deleted."});
}
}catch (e) {
console.error(e);
}

}
module.exports = {
bulkLoad,
readAll,
findById,
health
health,
softDeleteRepo
};
6 changes: 3 additions & 3 deletions charts/pubcode/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ dependencies:

- name: component
condition: api.enabled
version: 0.0.11
version: 0.0.13
repository: https://bcgov.github.io/helm-service/
alias: api

- name: component
condition: frontend.enabled
version: 0.0.11
version: 0.0.13
repository: https://bcgov.github.io/helm-service/
alias: frontend

- name: component
condition: database.enabled
version: 0.0.11
version: 0.0.13
repository: https://bcgov.github.io/helm-service/
alias: database
Loading