-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2955 from uselagoon/workflows/taskDefinitionResol…
…vers updating advanced task resolver and permissions
- Loading branch information
Showing
15 changed files
with
643 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
services/api/src/resources/task/models/advancedTaskDefinitionArgument.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { query } from '../../../util/db'; | ||
import * as R from 'ramda'; | ||
|
||
export class ArgumentBase { | ||
async validateInput(input): Promise<boolean> { | ||
return true; | ||
} | ||
|
||
public static typeName() { | ||
return "BASE"; | ||
} | ||
|
||
public async getArgumentRange() { | ||
return []; | ||
} | ||
|
||
} | ||
|
||
export class EnvironmentSourceArgument extends ArgumentBase { | ||
|
||
protected sqlClientPool; | ||
protected environmentId; | ||
protected environmentNameList = []; | ||
|
||
constructor(sqlClientPool, environmentId) { | ||
super(); | ||
this.sqlClientPool = sqlClientPool; | ||
this.environmentId = environmentId; | ||
} | ||
|
||
public static typeName() { | ||
return "ENVIRONMENT_SOURCE_NAME"; | ||
} | ||
|
||
public async getArgumentRange() { | ||
await this.loadEnvNames(); | ||
return this.environmentNameList; | ||
} | ||
|
||
protected async loadEnvNames() { | ||
const rows = await query( | ||
this.sqlClientPool, | ||
`select e.name as name from environment as e inner join environment as p on e.project = p.project where p.id = ${this.environmentId}` | ||
); | ||
this.environmentNameList = R.pluck('name')(rows); | ||
} | ||
|
||
/** | ||
* | ||
* @param input Environment name | ||
* @returns boolean | ||
*/ | ||
async validateInput(input): Promise<boolean> { | ||
await this.loadEnvNames(); | ||
return this.environmentNameList.includes(input); | ||
} | ||
} | ||
|
||
export class StringArgument extends ArgumentBase { | ||
|
||
public static typeName() { | ||
return "STRING"; | ||
} | ||
|
||
async validateInput(input): Promise<boolean> { | ||
return true; | ||
} | ||
|
||
public async getArgumentRange() { | ||
return null; | ||
} | ||
} | ||
|
||
|
||
export class NumberArgument { | ||
|
||
public static typeName() { | ||
return "NUMBER"; | ||
} | ||
|
||
async validateInput(input): Promise<boolean> { | ||
return true; | ||
} | ||
|
||
public async getArgumentRange() { | ||
return null; | ||
} | ||
} | ||
|
||
|
||
|
||
/** | ||
* This function will match a | ||
* | ||
* @param name The name of the advancedTaskDefinition type (stored in field) | ||
*/ | ||
export const advancedTaskDefinitionTypeFactory = (sqlClientPool, task, environment) => (name) => { | ||
switch(name) { | ||
case(EnvironmentSourceArgument.typeName()): | ||
return new EnvironmentSourceArgument(sqlClientPool, environment); | ||
break; | ||
case(StringArgument.typeName()): | ||
return new StringArgument(); | ||
break; | ||
case(NumberArgument.typeName()): | ||
return new NumberArgument(); | ||
break; | ||
default: | ||
throw new Error(`Unable to find AdvancedTaskDefinitionType ${name}`); | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.