Fixing code scan issues.
This commit is contained in:
1 parent
84ed1089ce
commit
4ce8cde5b0
19 files changed
+106
-144
No files matched your search
@@ -0,0 +1,2 @@
|
||||
# See https://help.github.com/ignore-files/ for more about ignoring files.
|
||||
.scannerwork
|
||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@superalgos/operations-client",
|
||||
"version": "0.0.13",
|
||||
"version": "0.0.14",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
+1
-3
@@ -1,9 +1,7 @@
|
||||
import React, { Component } from 'react'
|
||||
import React from 'react'
|
||||
import { Route, Switch } from 'react-router-dom'
|
||||
|
||||
import { MuiPickersUtilsProvider } from 'material-ui-pickers'
|
||||
import LuxonUtils from 'material-ui-pickers/utils/luxon-utils'
|
||||
|
||||
import BrowseClones from './views/Clone/List'
|
||||
import HistoryClones from './views/Clone/History'
|
||||
import AddClone from './views/Clone/Add'
|
||||
|
||||
@@ -2,24 +2,17 @@ import React, { Component } from 'react'
|
||||
import { graphql, compose, Query } from 'react-apollo'
|
||||
import { clones, teams, keys } from '../../../GraphQL/Calls'
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
import TopBar from '../../BannerTopBar'
|
||||
|
||||
import { withStyles } from '@material-ui/core/styles'
|
||||
import classNames from 'classnames'
|
||||
import styles from './styles'
|
||||
|
||||
import { tradingStartModes, indicatorStartModes, availableMonths, processNames } from '../../../GraphQL/models'
|
||||
import { tradingStartModes, indicatorStartModes, availableMonths } from '../../../GraphQL/models'
|
||||
import { isDefined, getIndicatorYears } from '../../../utils'
|
||||
|
||||
import {
|
||||
MenuItem, Button, TextField, FormControl, InputLabel, Input, Typography,
|
||||
Paper, Dialog, DialogTitle, DialogContent, DialogContentText, DialogActions,
|
||||
Select, FormControlLabel, Checkbox, FormHelperText
|
||||
} from '@material-ui/core'
|
||||
|
||||
import NumberFormat from 'react-number-format'
|
||||
|
||||
import { DateTimePicker } from 'material-ui-pickers'
|
||||
import {
|
||||
ChevronLeft,
|
||||
|
||||
@@ -2,12 +2,8 @@ import React, { Component } from 'react'
|
||||
import { graphql } from 'react-apollo'
|
||||
import { clones } from '../../../GraphQL/Calls'
|
||||
import TopBar from '../../BannerTopBar'
|
||||
//import CloneDialog from './CloneDialog'
|
||||
import ListClones from '../List/ListClones'
|
||||
|
||||
// Material-ui
|
||||
import { Typography, Paper } from '@material-ui/core'
|
||||
|
||||
class HistoryClones extends Component {
|
||||
|
||||
constructor (props) {
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import React, { Component } from 'react'
|
||||
import AddClone from './AddClone'
|
||||
|
||||
import AddIcon from '@material-ui/icons/Add'
|
||||
import { withStyles } from '@material-ui/core/styles'
|
||||
import styles from './styles'
|
||||
|
||||
import {
|
||||
Button, Dialog, DialogContent, DialogContentText, DialogTitle, Paper, Typography
|
||||
Button, Dialog, DialogContent, DialogContentText, DialogTitle
|
||||
} from '@material-ui/core'
|
||||
|
||||
class CloneDialog extends Component {
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
import React, { Component } from 'react'
|
||||
import { graphql, compose } from 'react-apollo'
|
||||
import { clones } from '../../../GraphQL/Calls'
|
||||
import Poloniex from '../../../img/poloniex.png'
|
||||
import Binance from '../../../img/binance.png'
|
||||
|
||||
import {
|
||||
Grid, Paper, Typography, Button, TextField, Dialog, DialogContent,
|
||||
Typography, Button, TextField, Dialog, DialogContent,
|
||||
DialogContentText, DialogTitle, DialogActions,
|
||||
ExpansionPanel, ExpansionPanelDetails, ExpansionPanelSummary,
|
||||
ExpansionPanelActions, Chip, Divider
|
||||
ExpansionPanelActions, Divider
|
||||
|
||||
} from '@material-ui/core'
|
||||
import Avatar from '@material-ui/core/Avatar';
|
||||
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
|
||||
|
||||
import { tradingStartModes, indicatorStartModes } from '../../../GraphQL/models'
|
||||
import { isDefined, toLocalTime } from '../../../utils'
|
||||
import classNames from 'classnames'
|
||||
|
||||
@@ -2,12 +2,8 @@ import React, { Component } from 'react'
|
||||
import { graphql } from 'react-apollo'
|
||||
import { clones } from '../../../GraphQL/Calls'
|
||||
import TopBar from '../../BannerTopBar'
|
||||
//import CloneDialog from './CloneDialog'
|
||||
import ListClones from './ListClones'
|
||||
|
||||
// Material-ui
|
||||
import { Typography, Paper } from '@material-ui/core'
|
||||
|
||||
class BrowseClones extends Component {
|
||||
|
||||
constructor (props) {
|
||||
|
||||
@@ -32,7 +32,6 @@ const styles = theme => ({
|
||||
marginRight: theme.spacing.unit,
|
||||
},
|
||||
textArea: {
|
||||
width:'1750px',
|
||||
margin: theme.spacing.unit,
|
||||
whiteSpace: 'pre',
|
||||
width:'98%',
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Typography } from '@material-ui/core'
|
||||
import { withStyles } from '@material-ui/core/styles'
|
||||
import TopBar from './BannerTopBar'
|
||||
|
||||
class Home extends Component {
|
||||
@@ -29,9 +28,7 @@ class Home extends Component {
|
||||
</Typography>
|
||||
</div>
|
||||
<div className='column'>
|
||||
<Typography align='justify'>
|
||||
|
||||
</Typography>
|
||||
<Typography align='justify' />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import logger from '../config/logger'
|
||||
|
||||
export class AuthentificationError extends Error {
|
||||
code = 401
|
||||
message = 'Autentification not found, you have to be authentificated to perform this action.'
|
||||
|
||||
@@ -2,143 +2,142 @@ import logger from '../config/logger'
|
||||
import { toPlatformDatetime, isDefined } from '../config/utils'
|
||||
import { KubernateError } from '../errors'
|
||||
import { Client, config } from 'kubernetes-client'
|
||||
// Get base Deployment config
|
||||
import deploymentManifest from '../config/clone-deployment.json'
|
||||
import { BACKTEST, NO_TIME } from '../enums/CloneMode'
|
||||
import { TRADER, INDICATOR, EXTRACTION } from '../enums/BotTypes'
|
||||
|
||||
const createClone = async (clone) => {
|
||||
try {
|
||||
logger.debug("createClone %s", clone.id)
|
||||
logger.debug('createClone %s', clone.id)
|
||||
const client = new Client({config: config.fromKubeconfig(), version: '1.9'})
|
||||
|
||||
// Make changes to base deployment config
|
||||
deploymentManifest.metadata.name = clone.id
|
||||
|
||||
logger.debug("createClone Environment and Auth Configuration.")
|
||||
logger.debug('createClone Environment and Auth Configuration.')
|
||||
let env = []
|
||||
env.push({
|
||||
"name": "PLATFORM_ENVIRONMENT",
|
||||
"value": process.env.PLATFORM_ENVIRONMENT
|
||||
'name': 'PLATFORM_ENVIRONMENT',
|
||||
'value': process.env.PLATFORM_ENVIRONMENT
|
||||
})
|
||||
env.push({
|
||||
"name": "GATEWAY_ENDPOINT",
|
||||
"value": process.env.GATEWAY_ENDPOINT
|
||||
'name': 'GATEWAY_ENDPOINT',
|
||||
'value': process.env.GATEWAY_ENDPOINT
|
||||
})
|
||||
env.push({
|
||||
"name": "STORAGE_BASE_URL",
|
||||
"value": process.env.STORAGE_BASE_URL
|
||||
'name': 'STORAGE_BASE_URL',
|
||||
'value': process.env.STORAGE_BASE_URL
|
||||
})
|
||||
env.push({
|
||||
"name": "STORAGE_CONNECTION_STRING",
|
||||
"value": process.env.STORAGE_CONNECTION_STRING
|
||||
'name': 'STORAGE_CONNECTION_STRING',
|
||||
'value': process.env.STORAGE_CONNECTION_STRING
|
||||
})
|
||||
env.push({
|
||||
"name": "AUTH_URL",
|
||||
"value": process.env.AUTH_URL
|
||||
'name': 'AUTH_URL',
|
||||
'value': process.env.AUTH_URL
|
||||
})
|
||||
env.push({
|
||||
"name": "AUTH_CLIENT_ID",
|
||||
"value": process.env.AUTH_CLIENT_ID
|
||||
'name': 'AUTH_CLIENT_ID',
|
||||
'value': process.env.AUTH_CLIENT_ID
|
||||
})
|
||||
env.push({
|
||||
"name": "AUTH_CLIENT_SECRET",
|
||||
"value": process.env.AUTH_CLIENT_SECRET
|
||||
'name': 'AUTH_CLIENT_SECRET',
|
||||
'value': process.env.AUTH_CLIENT_SECRET
|
||||
})
|
||||
env.push({
|
||||
"name": "AUTH_AUDIENCE",
|
||||
"value": process.env.AUTH_AUDIENCE
|
||||
'name': 'AUTH_AUDIENCE',
|
||||
'value': process.env.AUTH_AUDIENCE
|
||||
})
|
||||
|
||||
logger.debug("createClone General Financial Being Configuration.")
|
||||
logger.debug('createClone General Financial Being Configuration.')
|
||||
env.push({
|
||||
"name": "DEV_TEAM",
|
||||
"value": clone.teamSlug
|
||||
'name': 'DEV_TEAM',
|
||||
'value': clone.teamSlug
|
||||
})
|
||||
env.push({
|
||||
"name": "BOT",
|
||||
"value": clone.botSlug
|
||||
'name': 'BOT',
|
||||
'value': clone.botSlug
|
||||
})
|
||||
env.push({
|
||||
"name": "TYPE",
|
||||
"value": clone.botType
|
||||
'name': 'TYPE',
|
||||
'value': clone.botType
|
||||
})
|
||||
env.push({
|
||||
"name": "CLONE_ID",
|
||||
"value": clone.id.toString()
|
||||
'name': 'CLONE_ID',
|
||||
'value': clone.id.toString()
|
||||
})
|
||||
env.push({
|
||||
"name": "START_MODE",
|
||||
"value": clone.mode
|
||||
'name': 'START_MODE',
|
||||
'value': clone.mode
|
||||
})
|
||||
env.push({
|
||||
"name": "RUN_AS_TEAM",
|
||||
"value": clone.runAsTeam.toString()
|
||||
'name': 'RUN_AS_TEAM',
|
||||
'value': clone.runAsTeam.toString()
|
||||
})
|
||||
env.push({
|
||||
"name": "USER_LOGGED_IN",
|
||||
"value": clone.userLoggedIn
|
||||
'name': 'USER_LOGGED_IN',
|
||||
'value': clone.userLoggedIn
|
||||
})
|
||||
env.push({
|
||||
"name": "PROCESS",
|
||||
"value": clone.processName
|
||||
'name': 'PROCESS',
|
||||
'value': clone.processName
|
||||
})
|
||||
|
||||
logger.debug("createClone Trading Configuration.")
|
||||
if(clone.botType === TRADER ){
|
||||
logger.debug('createClone Trading Configuration.')
|
||||
if (clone.botType === TRADER) {
|
||||
env.push({
|
||||
"name": "RESUME_EXECUTION",
|
||||
"value": clone.resumeExecution.toString()
|
||||
'name': 'RESUME_EXECUTION',
|
||||
'value': clone.resumeExecution.toString()
|
||||
})
|
||||
|
||||
if(clone.mode === BACKTEST){
|
||||
if (clone.mode === BACKTEST) {
|
||||
env.push({
|
||||
"name": "BEGIN_DATE_TIME",
|
||||
"value": toPlatformDatetime(clone.beginDatetime)
|
||||
'name': 'BEGIN_DATE_TIME',
|
||||
'value': toPlatformDatetime(clone.beginDatetime)
|
||||
})
|
||||
env.push({
|
||||
"name": "END_DATE_TIME",
|
||||
"value": toPlatformDatetime(clone.endDatetime)
|
||||
'name': 'END_DATE_TIME',
|
||||
'value': toPlatformDatetime(clone.endDatetime)
|
||||
})
|
||||
env.push({
|
||||
"name": "WAIT_TIME",
|
||||
"value": clone.waitTime.toString()
|
||||
'name': 'WAIT_TIME',
|
||||
'value': clone.waitTime.toString()
|
||||
})
|
||||
} else{
|
||||
} else {
|
||||
env.push({
|
||||
"name": "KEY_ID",
|
||||
"value": clone.keyId
|
||||
'name': 'KEY_ID',
|
||||
'value': clone.keyId
|
||||
})
|
||||
}
|
||||
} else if (clone.botType === INDICATOR || clone.botType === EXTRACTION) {
|
||||
if (clone.mode !== NO_TIME) {
|
||||
env.push({
|
||||
'name': 'MIN_YEAR',
|
||||
'value': isDefined(clone.startYear) ? clone.startYear.toString() : ''
|
||||
})
|
||||
env.push({
|
||||
'name': 'MAX_YEAR',
|
||||
'value': isDefined(clone.endYear) ? clone.endYear.toString() : ''
|
||||
})
|
||||
env.push({
|
||||
'name': 'MONTH',
|
||||
'value': isDefined(clone.month) ? clone.month.toString() : ''
|
||||
})
|
||||
env.push({
|
||||
'name': 'INTERVAL',
|
||||
'value': isDefined(clone.interval) ? clone.interval.toString() : ''
|
||||
})
|
||||
}
|
||||
} else if(clone.botType === INDICATOR || clone.botType === EXTRACTION ){
|
||||
if(clone.mode !== NO_TIME){
|
||||
env.push({
|
||||
"name": "MIN_YEAR",
|
||||
"value": isDefined(clone.startYear) ? clone.startYear.toString() : ''
|
||||
})
|
||||
env.push({
|
||||
"name": "MAX_YEAR",
|
||||
"value": isDefined(clone.endYear) ? clone.endYear.toString() : ''
|
||||
})
|
||||
env.push({
|
||||
"name": "MONTH",
|
||||
"value": isDefined(clone.month) ? clone.month.toString() : ''
|
||||
})
|
||||
env.push({
|
||||
"name": "INTERVAL",
|
||||
"value": isDefined(clone.interval) ? clone.interval.toString() : ''
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
deploymentManifest.spec.template.spec.containers[0].env = env
|
||||
|
||||
const create = await client.apis.batch.v1.namespaces('default').jobs.post(
|
||||
await client.apis.batch.v1.namespaces('default').jobs.post(
|
||||
{ body: deploymentManifest })
|
||||
|
||||
logger.debug("createClone %s on Kubernates success.", clone.id)
|
||||
logger.debug('createClone %s on Kubernates success.', clone.id)
|
||||
} catch (err) {
|
||||
throw new KubernateError(err)
|
||||
throw new KubernateError(err)
|
||||
}
|
||||
}
|
||||
export default createClone
|
||||
@@ -4,25 +4,23 @@ import { Client, config } from 'kubernetes-client'
|
||||
|
||||
const removeClone = async (clone) => {
|
||||
try {
|
||||
logger.debug("removeClone %s", clone.id)
|
||||
logger.debug('removeClone %s', clone.id)
|
||||
const client = new Client({config: config.fromKubeconfig(), version: '1.9'})
|
||||
|
||||
let query = {
|
||||
"qs":{
|
||||
"labelSelector": "job-name=" + clone.id
|
||||
'qs': {
|
||||
'labelSelector': 'job-name=' + clone.id
|
||||
}
|
||||
}
|
||||
|
||||
const removed = await client.apis.batch.v1.namespaces('default').jobs(
|
||||
clone.id).delete()
|
||||
await client.apis.batch.v1.namespaces('default').jobs(clone.id).delete()
|
||||
|
||||
const pod = await client.api.v1.namespaces('default').pods.get(query)
|
||||
const podRemoved = await client.api.v1.namespaces('default')
|
||||
.pods(pod.body.items[0].metadata.name).delete()
|
||||
await client.api.v1.namespaces('default').pods(pod.body.items[0].metadata.name).delete()
|
||||
|
||||
logger.debug("removeClone %s on kubernates succesful", clone.id)
|
||||
logger.debug('removeClone %s on kubernates succesful', clone.id)
|
||||
} catch (err) {
|
||||
throw new KubernateError(err)
|
||||
throw new KubernateError(err)
|
||||
}
|
||||
}
|
||||
export default removeClone
|
||||
@@ -73,7 +73,7 @@ const resolve = async(parent, { clone }, context) => {
|
||||
}
|
||||
}
|
||||
|
||||
const mutation = {
|
||||
const AddCloneMutation = {
|
||||
addClone: {
|
||||
type: CloneType,
|
||||
args,
|
||||
@@ -81,4 +81,4 @@ const mutation = {
|
||||
}
|
||||
}
|
||||
|
||||
export default mutation
|
||||
export default AddCloneMutation
|
||||
@@ -64,7 +64,7 @@ const resolve = async (parent, { id }, context) => {
|
||||
})
|
||||
}
|
||||
|
||||
const mutation = {
|
||||
const RemoveCloneMutation = {
|
||||
removeClone: {
|
||||
type: GraphQLString,
|
||||
args,
|
||||
@@ -72,4 +72,4 @@ const mutation = {
|
||||
}
|
||||
}
|
||||
|
||||
export default mutation
|
||||
export default RemoveCloneMutation
|
||||
@@ -5,17 +5,13 @@ import {
|
||||
GraphQLInt,
|
||||
GraphQLFloat
|
||||
} from 'graphql'
|
||||
|
||||
import {
|
||||
OperationsError
|
||||
} from '../../errors'
|
||||
|
||||
import { Clone } from '../../models'
|
||||
import logger from '../../config/logger'
|
||||
import teamQuery from '../../graphQLCalls/teamQuery'
|
||||
import authorizeClone from '../../graphQLCalls/authorizeClone'
|
||||
import cloneDetails from '../cloneDetails'
|
||||
import removeKuberneteClone from '../../kubernetes/removeClone'
|
||||
import { isDefined } from '../../config/utils'
|
||||
|
||||
const args = {
|
||||
@@ -34,23 +30,22 @@ const resolve = async (parent,
|
||||
{ id, summaryDate, buyAverage, sellAverage, marketRate, combinedProfitsA,
|
||||
combinedProfitsB, assetA, assetB
|
||||
}, context) => {
|
||||
|
||||
logger.debug('UpdateExecutionSummary -> Entering Function.')
|
||||
|
||||
if (!context.userId) {
|
||||
throw new AuthentificationError()
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
let sucessful
|
||||
|
||||
let clone = await Clone.findOne( {
|
||||
let clone = await Clone.findOne({
|
||||
_id: id,
|
||||
active: true
|
||||
})
|
||||
|
||||
if(!isDefined(clone)){
|
||||
return "Clone not found."
|
||||
if (!isDefined(clone)) {
|
||||
return 'Clone not found.'
|
||||
}
|
||||
|
||||
let team = await teamQuery(context.authorization, clone.teamId)
|
||||
@@ -72,7 +67,7 @@ const resolve = async (parent,
|
||||
|
||||
logger.debug('UpdateExecutionSummary -> Updating clone on database.')
|
||||
await Clone.update(query, update, options, (err, clone) => {
|
||||
if (err){
|
||||
if (err) {
|
||||
logger.error('Error updating execution summary on the database. %s', err.stack)
|
||||
throw err
|
||||
} else {
|
||||
@@ -81,16 +76,16 @@ const resolve = async (parent,
|
||||
}
|
||||
})
|
||||
|
||||
if(sucessful)
|
||||
if (sucessful) {
|
||||
return 'Execution summary updated.'
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error('Error updating the execution summary. %s', error.stack)
|
||||
throw new OperationsError(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
const mutation = {
|
||||
const UpdateExecutionSummary = {
|
||||
updateExecutionSummary: {
|
||||
type: GraphQLString,
|
||||
args,
|
||||
@@ -98,4 +93,4 @@ const mutation = {
|
||||
}
|
||||
}
|
||||
|
||||
export default mutation
|
||||
export default UpdateExecutionSummary
|
||||
@@ -53,7 +53,7 @@ const resolve = async(parent, { cloneIdList }, context) => {
|
||||
}
|
||||
}
|
||||
|
||||
const query = {
|
||||
const GetClones = {
|
||||
getClones: {
|
||||
type: new GraphQLList(GetClonesType),
|
||||
args,
|
||||
@@ -61,4 +61,4 @@ const query = {
|
||||
}
|
||||
}
|
||||
|
||||
export default query
|
||||
export default GetClones
|
||||
@@ -10,8 +10,6 @@ import {
|
||||
import { CloneType } from '../types'
|
||||
import { Clone } from '../../models'
|
||||
import logger from '../../config/logger'
|
||||
import getKuberneteClonePodStatus from '../../kubernetes/getClonePodStatus'
|
||||
import getKuberneteClonePodLogs from '../../kubernetes/getClonePodLogs'
|
||||
import cloneDetails from '../cloneDetails'
|
||||
import teamQuery from '../../graphQLCalls/teamQuery'
|
||||
|
||||
@@ -42,7 +40,7 @@ const resolve = async(parent, args, context) => {
|
||||
}
|
||||
}
|
||||
|
||||
const query = {
|
||||
const HistoryClones = {
|
||||
historyClones: {
|
||||
type: new GraphQLList(CloneType),
|
||||
args,
|
||||
@@ -50,4 +48,4 @@ const query = {
|
||||
}
|
||||
}
|
||||
|
||||
export default query
|
||||
export default HistoryClones
|
||||
@@ -45,7 +45,7 @@ const resolve = async(parent, args, context) => {
|
||||
}
|
||||
}
|
||||
|
||||
const query = {
|
||||
const ListClones = {
|
||||
clones: {
|
||||
type: new GraphQLList(CloneType),
|
||||
args,
|
||||
@@ -53,4 +53,4 @@ const query = {
|
||||
}
|
||||
}
|
||||
|
||||
export default query
|
||||
export default ListClones
|
||||
Reference in new issue
Block a user