Skip to content

Commit f2064a0

Browse files
committed
trying to fix bug
1 parent 8f8249e commit f2064a0

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

wrongsecrets-balancer/src/kubernetes.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,10 @@ const getJuiceShopInstanceForTeamname = (teamname) => {
13041304
.readNamespacedDeployment(`t-${teamname}-wrongsecrets`, `t-${teamname}`)
13051305
.then((res) => {
13061306
logger.info(JSON.stringify(res));
1307-
if(res.body.hasOwnProperty('metadata') && res.body.metadata.hasOwnProperty('annotations') ){
1307+
if (
1308+
Object.prototype.hasOwnProperty.call(res.body, 'metadata') &&
1309+
Object.prototype.hasOwnProperty.call(res.body.metadata, 'annotations')
1310+
) {
13081311
return {
13091312
readyReplicas: res.body.status.readyReplicas,
13101313
availableReplicas: res.body.status.availableReplicas,

wrongsecrets-balancer/src/teams/teams.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ async function joinIfTeamAlreadyExists(req, res, next) {
174174
message: 'Team requires authentication to join',
175175
});
176176
} catch (error) {
177-
if (error.message.includes(`deployments.apps "t-${team}-wrongsecrets" not found`) || error.message==="Cannot destructure property 'passcodeHash' of '(intermediate value)' as it is undefined.") {
177+
if (
178+
error.message.includes(`deployments.apps "t-${team}-wrongsecrets" not found`) ||
179+
error.message ===
180+
"Cannot destructure property 'passcodeHash' of '(intermediate value)' as it is undefined."
181+
) {
178182
logger.info(`Team ${team} doesn't have a WrongSecrets deployment yet`);
179183
return next();
180184
} else {
@@ -194,7 +198,7 @@ async function joinIfTeamAlreadyExists(req, res, next) {
194198
* @param {import("express").NextFunction} next
195199
*/
196200
async function checkIfMaxJuiceShopInstancesIsReached(req, res, next) {
197-
logger.info("checking for max instances");
201+
logger.info('checking for max instances');
198202
const maxInstances = get('maxJuiceShopInstances');
199203

200204
// If max instances is set to negative numbers it's not capped
@@ -236,7 +240,7 @@ async function generatePasscode() {
236240
*/
237241
async function createTeam(req, res) {
238242
const { team } = req.params;
239-
logger.info(`creating new team for team '${team}'`)
243+
logger.info(`creating new team for team '${team}'`);
240244
if (k8sEnv === 'aws') {
241245
logger.info(
242246
'We will create an AWS deployment see the helm chart/deployment for setting this to k8s'
@@ -246,7 +250,7 @@ async function createTeam(req, res) {
246250
logger.info(
247251
'We will create a K8s deployment see the helm chart/deployment for setting this to aws'
248252
);
249-
253+
250254
const { passcode, hash } = await generatePasscode();
251255
try {
252256
logger.info(`Creating Namespace for team '${team}'`);
@@ -523,9 +527,8 @@ async function awaitReadiness(req, res) {
523527
const { team } = req.params;
524528

525529
logger.info(`Awaiting readiness of wrongsecrets Deployment for team '${team}'`);
526-
527-
try {
528-
for (let i = 0; i < 180; i++) {
530+
for (let i = 0; i < 180; i++) {
531+
try {
529532
const { readyReplicas } = await getJuiceShopInstanceForTeamname(team);
530533

531534
if (readyReplicas === 1) {
@@ -535,14 +538,14 @@ async function awaitReadiness(req, res) {
535538
}
536539

537540
await sleep(1000);
538-
}
539541

540-
logger.error(`Waiting for deployment of team '${team}' timed out`);
541-
res.status(500).send({ message: 'Waiting for Deployment Readiness Timed Out' });
542-
} catch (error) {
543-
logger.error(`Failed to wait for teams '${team}' deployment to get ready: ${error}`);
544-
logger.error(error);
545-
res.status(500).send({ message: 'Failed to Wait For Deployment Readiness' });
542+
logger.error(`Waiting for deployment of team '${team}' timed out`);
543+
res.status(500).send({ message: 'Waiting for Deployment Readiness Timed Out' });
544+
} catch (error) {
545+
logger.error(`Failed to wait for teams '${team}' deployment to get ready: ${error}`);
546+
logger.error(error);
547+
res.status(500).send({ message: 'Failed to Wait For Deployment Readiness' });
548+
}
546549
}
547550
}
548551

0 commit comments

Comments
 (0)