23 files changed
+819
-517
No files matched your search
Generated
+30
-15
@@ -36,12 +36,12 @@
|
||||
"integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw=="
|
||||
},
|
||||
"axios": {
|
||||
"version": "0.18.0",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.18.0.tgz",
|
||||
"integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
|
||||
"version": "0.19.0",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.0.tgz",
|
||||
"integrity": "sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==",
|
||||
"requires": {
|
||||
"follow-redirects": "^1.3.0",
|
||||
"is-buffer": "^1.1.5"
|
||||
"follow-redirects": "1.5.10",
|
||||
"is-buffer": "^2.0.2"
|
||||
}
|
||||
},
|
||||
"balanced-match": {
|
||||
@@ -186,9 +186,9 @@
|
||||
"integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA=="
|
||||
},
|
||||
"dotenv": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-7.0.0.tgz",
|
||||
"integrity": "sha512-M3NhsLbV1i6HuGzBUH8vXrtxOk+tWmzWKDMbAVSUp3Zsjm7ywFeuwrUXhmhQyRK1q5B5GGy7hcXPbj3bnfZg2g=="
|
||||
"version": "8.0.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.0.0.tgz",
|
||||
"integrity": "sha512-30xVGqjLjiUOArT4+M5q9sYdvuR4riM6yK9wMcas9Vbp6zZa+ocC9dp6QoftuhTPhFAiLK/0C5Ni2nou/Bk8lg=="
|
||||
},
|
||||
"emoji-regex": {
|
||||
"version": "7.0.3",
|
||||
@@ -274,11 +274,26 @@
|
||||
}
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.7.0.tgz",
|
||||
"integrity": "sha512-m/pZQy4Gj287eNy94nivy5wchN3Kp+Q5WgUPNy5lJSZ3sgkVKSYV/ZChMAQVIgx1SqfZ2zBZtPA2YlXIWxxJOQ==",
|
||||
"version": "1.5.10",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
|
||||
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
|
||||
"requires": {
|
||||
"debug": "^3.2.6"
|
||||
"debug": "=3.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
}
|
||||
}
|
||||
},
|
||||
"fs.realpath": {
|
||||
@@ -370,9 +385,9 @@
|
||||
"integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA=="
|
||||
},
|
||||
"is-buffer": {
|
||||
"version": "1.1.6",
|
||||
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
|
||||
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz",
|
||||
"integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw=="
|
||||
},
|
||||
"is-callable": {
|
||||
"version": "1.1.4",
|
||||
|
||||
+2
-2
@@ -9,9 +9,9 @@
|
||||
"author": "Superalgos, ltd.",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"axios": "0.18.0",
|
||||
"axios": "0.19.0",
|
||||
"chai": "^4.2.0",
|
||||
"dotenv": "^7.0.0",
|
||||
"dotenv": "8.0.0",
|
||||
"mocha": "^6.1.4"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
# Ignore files to be uploaded to the image
|
||||
.env*
|
||||
.git
|
||||
.gitignore
|
||||
Dockerfile
|
||||
Dockerfile.prod
|
||||
README.md
|
||||
CODE_OF_CONDUCT.md
|
||||
CONTRIBUTING.md
|
||||
+1
-8
@@ -4,16 +4,9 @@ PORT=4003
|
||||
# Database configuration
|
||||
MONGO_URL=mongodb://mongo/operations
|
||||
|
||||
GATEWAY_ENDPOINT=http://master-app-api:4100/graphql
|
||||
GATEWAY_ENDPOINT=http://docker.for.win.localhost:4100/graphql
|
||||
OPERATIONS_API_PRESHARED=clones_key
|
||||
|
||||
# Clone Executor Integration
|
||||
PLATFORM_ENVIRONMENT=Develop
|
||||
|
||||
|
||||
# Storage Config
|
||||
STORAGE_PROVIDER=Azure
|
||||
|
||||
# Temporary restriction on asset balances
|
||||
ACCESS_CODE=access_code
|
||||
DEFAULT_BALANCE_ASSET_A=0
|
||||
|
||||
+1
-3
@@ -4,15 +4,13 @@ FROM mhart/alpine-node:12
|
||||
ARG API_DIR=/usr/src/clones-api
|
||||
|
||||
# Prepare required directories
|
||||
RUN mkdir -p ${API_DIR} && \
|
||||
mkdir -p /root/.kube
|
||||
RUN mkdir -p ${API_DIR}
|
||||
|
||||
# Use app directory as current workdir
|
||||
WORKDIR ${API_DIR}
|
||||
|
||||
# Copy package.json to workdir
|
||||
COPY . ${API_DIR}/
|
||||
COPY ./config /root/.kube
|
||||
|
||||
# Install dependencies
|
||||
RUN npm install --production
|
||||
|
||||
Generated
+552
-395
File diff suppressed because it is too large.
Load diff
+4
-4
@@ -21,15 +21,15 @@
|
||||
"nodemon": "1.18.10"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "0.18.0",
|
||||
"axios": "0.19.0",
|
||||
"cors": "2.8.4",
|
||||
"dotenv": "6.0.0",
|
||||
"dotenv": "8.0.0",
|
||||
"express": "4.16.3",
|
||||
"express-graphql": "0.6.12",
|
||||
"graphql": "14.0.0",
|
||||
"kubernetes-client": "6.5.1",
|
||||
"kubernetes-client": "8.2.0",
|
||||
"luxon": "^1.13.2",
|
||||
"mongoose": "5.2.12",
|
||||
"winston": "3.1.0"
|
||||
"winston": "3.2.1"
|
||||
}
|
||||
}
|
||||
@@ -14,12 +14,14 @@
|
||||
"containers": [
|
||||
{
|
||||
"name": "clone-executor",
|
||||
"image": "superalgos/clone-executor:1.0.11",
|
||||
"image": "superalgos/clone-executor:1.0.12",
|
||||
"command": ["node", "Run.js"],
|
||||
"env": [
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"hostNetwork": true,
|
||||
"dnsPolicy": "ClusterFirstWithHostNet"
|
||||
},
|
||||
"metadata": {
|
||||
"labels": {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export class AuthentificationError extends Error {
|
||||
export class AuthenticationError extends Error {
|
||||
code = 401
|
||||
message = 'Autentification not found, you have to be authentificated to perform this action.'
|
||||
constructor(){
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import logger from '../config/logger'
|
||||
import axios from 'axios'
|
||||
|
||||
const authorizeClon = (authorization, keyId, cloneId, releaseClon) => {
|
||||
logger.debug('authorizeClon -> Entering function.')
|
||||
const authorizeKey = (authorization, keyId, cloneId, releaseClon) => {
|
||||
logger.debug('authorizeKey -> Entering function.')
|
||||
|
||||
return axios({
|
||||
url: process.env.GATEWAY_ENDPOINT,
|
||||
@@ -25,4 +25,4 @@ const authorizeClon = (authorization, keyId, cloneId, releaseClon) => {
|
||||
})
|
||||
}
|
||||
|
||||
export default authorizeClon
|
||||
export default authorizeKey
|
||||
@@ -0,0 +1,28 @@
|
||||
import logger from '../config/logger'
|
||||
import axios from 'axios'
|
||||
|
||||
const authorizeStrategy = (authorization, fbSlug, cloneId, release) => {
|
||||
logger.debug('authorizeStrategy -> Entering function.')
|
||||
|
||||
return axios({
|
||||
url: process.env.GATEWAY_ENDPOINT,
|
||||
method: 'post',
|
||||
data: {
|
||||
query: `
|
||||
mutation strategizer_AuthorizeStrategy($fbSlug: String!, $cloneId: String!, $release: Boolean!){
|
||||
strategizer_AuthorizeStrategy(fbSlug: $fbSlug, cloneId: $cloneId, release:$release)
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
fbSlug,
|
||||
cloneId,
|
||||
release
|
||||
}
|
||||
},
|
||||
headers: {
|
||||
authorization: authorization
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default authorizeStrategy
|
||||
@@ -0,0 +1,40 @@
|
||||
import logger from '../config/logger'
|
||||
import axios from 'axios'
|
||||
|
||||
const ecosystemQuery = async (authorization) => {
|
||||
logger.debug('ecosystemQuery -> Entering function')
|
||||
|
||||
let response = await axios({
|
||||
url: process.env.GATEWAY_ENDPOINT,
|
||||
method: 'post',
|
||||
data: {
|
||||
query: `
|
||||
query {
|
||||
web_GetEcosystem {
|
||||
devTeams {
|
||||
codeName
|
||||
displayName
|
||||
host {
|
||||
url
|
||||
storage
|
||||
container
|
||||
accessKey
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
},
|
||||
headers: {
|
||||
authorization: authorization
|
||||
}
|
||||
})
|
||||
|
||||
if (response.data.errors) {
|
||||
throw error
|
||||
}
|
||||
|
||||
return response.data.data.web_GetEcosystem
|
||||
}
|
||||
|
||||
export default ecosystemQuery
|
||||
@@ -5,75 +5,42 @@ import { Client, config } from 'kubernetes-client'
|
||||
import deploymentManifest from '../config/clone-deployment.json'
|
||||
import { BACKTEST, COMPETITION, LIVE, NO_TIME } from '../enums/CloneMode'
|
||||
import { Trading, Indicator, Sensor } from '../enums/BotTypes'
|
||||
import kubeconfig from './kubeConfig'
|
||||
|
||||
const createClone = async (clone) => {
|
||||
try {
|
||||
logger.debug('createClone %s', clone.id)
|
||||
const client = new Client({ config: config.fromKubeconfig(), version: '1.9' })
|
||||
deploymentManifest.metadata.name = clone.id
|
||||
|
||||
logger.debug('createClone Environment and Auth Configuration.')
|
||||
const Request = require('kubernetes-client/backends/request')
|
||||
const backend = new Request(Request.config.fromKubeconfig(kubeconfig()))
|
||||
const client = new Client({ backend, version: '1.9' })
|
||||
|
||||
deploymentManifest.metadata.name = clone.id
|
||||
deploymentManifest.spec.template.spec.containers[0].image = process.env.CLONE_EXECUTOR_IMAGE
|
||||
|
||||
logger.debug('createClone Environment and Storage Configuration.')
|
||||
let env = []
|
||||
env.push({
|
||||
'name': 'PLATFORM_ENVIRONMENT',
|
||||
'value': process.env.PLATFORM_ENVIRONMENT
|
||||
})
|
||||
env.push({
|
||||
'name': 'GATEWAY_ENDPOINT',
|
||||
'value': process.env.GATEWAY_ENDPOINT
|
||||
})
|
||||
env.push({
|
||||
'name': 'STORAGE_BASE_URL',
|
||||
'value': process.env.STORAGE_BASE_URL
|
||||
'name': 'GATEWAY_ENDPOINT_K8S',
|
||||
'value': process.env.GATEWAY_ENDPOINT_K8S
|
||||
})
|
||||
env.push({
|
||||
'name': 'STORAGE_CONNECTION_STRING',
|
||||
'value': process.env.STORAGE_CONNECTION_STRING
|
||||
'name': 'HOST_STORAGE',
|
||||
'value': 'localStorage'
|
||||
})
|
||||
// TODO Pending setting private bots
|
||||
// env.push({
|
||||
// 'name': 'HOST_ACCESS_KEY',
|
||||
// 'value': clone.host.accessKey
|
||||
// })
|
||||
env.push({
|
||||
'name': 'AUTH_URL',
|
||||
'value': process.env.AUTH_URL
|
||||
'name': 'ACCESS_TOKEN_STRATEGY',
|
||||
'value': clone.accessTokenStrategy
|
||||
})
|
||||
env.push({
|
||||
'name': 'AUTH_CLIENT_ID',
|
||||
'value': process.env.AUTH_CLIENT_ID
|
||||
})
|
||||
env.push({
|
||||
'name': 'AUTH_CLIENT_SECRET',
|
||||
'value': process.env.AUTH_CLIENT_SECRET
|
||||
})
|
||||
env.push({
|
||||
'name': 'AUTH_AUDIENCE',
|
||||
'value': process.env.AUTH_AUDIENCE
|
||||
})
|
||||
|
||||
env.push({
|
||||
'name': 'STORAGE_PROVIDER',
|
||||
'value': process.env.STORAGE_PROVIDER
|
||||
})
|
||||
|
||||
if (process.env.STORAGE_PROVIDER === 'Minio') {
|
||||
env.push({
|
||||
'name': 'MINIO_END_POINT',
|
||||
'value': process.env.MINIO_END_POINT
|
||||
})
|
||||
env.push({
|
||||
'name': 'MINIO_PORT',
|
||||
'value': process.env.MINIO_PORT
|
||||
})
|
||||
env.push({
|
||||
'name': 'MINIO_USE_SSL',
|
||||
'value': process.env.MINIO_USE_SSL
|
||||
})
|
||||
env.push({
|
||||
'name': 'MINIO_ACCESS_KEY',
|
||||
'value': process.env.MINIO_ACCESS_KEY
|
||||
})
|
||||
env.push({
|
||||
'name': 'MINIO_SECRET_KEY',
|
||||
'value': process.env.MINIO_SECRET_KEY
|
||||
})
|
||||
}
|
||||
|
||||
logger.debug('createClone General Financial Being Configuration.')
|
||||
env.push({
|
||||
@@ -167,11 +134,19 @@ const createClone = async (clone) => {
|
||||
'name': 'KEY_ID',
|
||||
'value': clone.keyId
|
||||
})
|
||||
env.push({
|
||||
'name': 'ACCESS_TOKEN',
|
||||
'value': clone.accessTokenKey
|
||||
})
|
||||
} else if (clone.mode === LIVE) {
|
||||
env.push({
|
||||
'name': 'KEY_ID',
|
||||
'value': clone.keyId
|
||||
})
|
||||
env.push({
|
||||
'name': 'ACCESS_TOKEN',
|
||||
'value': clone.accessTokenKey
|
||||
})
|
||||
}
|
||||
} else if (clone.botType === Indicator || clone.botType === Sensor) {
|
||||
if (clone.mode === NO_TIME) {
|
||||
@@ -208,6 +183,7 @@ const createClone = async (clone) => {
|
||||
|
||||
logger.debug('createClone %s on Kubernates success.', clone.id)
|
||||
} catch (err) {
|
||||
logger.error('Error creating clone: %s', err)
|
||||
throw new KubernateError(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import logger from '../config/logger'
|
||||
import { KubernateError } from '../errors'
|
||||
import { Client, config } from 'kubernetes-client'
|
||||
import kubeconfig from './kubeConfig'
|
||||
|
||||
const getClonePodLogs = async (cloneName) => {
|
||||
try {
|
||||
logger.debug('getClonePodLogs on kubernates started.')
|
||||
const client = new Client({config: config.fromKubeconfig(), version: '1.9'})
|
||||
|
||||
const Request = require('kubernetes-client/backends/request')
|
||||
const backend = new Request(Request.config.fromKubeconfig(kubeconfig()))
|
||||
const client = new Client({ backend, version: '1.9' })
|
||||
|
||||
let query = {
|
||||
'qs': {
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import logger from '../config/logger'
|
||||
import { KubernateError } from '../errors'
|
||||
import { Client, config } from 'kubernetes-client'
|
||||
import kubeconfig from './kubeConfig'
|
||||
|
||||
const getClonePodStatus = async (cloneName) => {
|
||||
try {
|
||||
logger.debug('getClonePodStatus on kubernates started.')
|
||||
const client = new Client({ config: config.fromKubeconfig(), version: '1.9' })
|
||||
|
||||
const Request = require('kubernetes-client/backends/request')
|
||||
const backend = new Request(Request.config.fromKubeconfig(kubeconfig()))
|
||||
const client = new Client({ backend, version: '1.9' })
|
||||
|
||||
let query = {
|
||||
'qs': {
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import logger from '../config/logger'
|
||||
|
||||
const kubeConfig = () => {
|
||||
|
||||
let clusterConfig = {}
|
||||
clusterConfig.name = process.env.CLUSTER_NAME
|
||||
let cluster = {}
|
||||
cluster.server = process.env.CLUSTER_SERVER
|
||||
if (process.env.CERTIFICATE_AUTHORITY_DATA) {
|
||||
cluster['certificate-authority-data'] = process.env.CERTIFICATE_AUTHORITY_DATA
|
||||
}
|
||||
if (process.env.INSECURE_SKIP_TLS_VERIFY) {
|
||||
cluster['insecure-skip-tls-verify'] = JSON.parse(process.env.INSECURE_SKIP_TLS_VERIFY)
|
||||
}
|
||||
clusterConfig.cluster = cluster
|
||||
|
||||
let contextConfig = {}
|
||||
contextConfig.name = process.env.CONTEXT_NAME
|
||||
let context = {}
|
||||
context.cluster = process.env.CLUSTER_NAME
|
||||
context.user = process.env.USER_NAME
|
||||
contextConfig.context = context
|
||||
|
||||
let userConfig = {}
|
||||
userConfig.name = process.env.USER_NAME
|
||||
let user = {}
|
||||
if (process.env.USER_PASSWORD) {
|
||||
user.password = process.env.USER_PASSWORD
|
||||
user.username = process.env.USER_NAME
|
||||
}
|
||||
if (process.env.CLIENT_CERTIFICATE_DATA) {
|
||||
user['client-certificate-data'] = process.env.CLIENT_CERTIFICATE_DATA
|
||||
user['client-key-data'] = process.env.CLIENT_KEY_DATA
|
||||
}
|
||||
userConfig.user = user
|
||||
|
||||
const config = {
|
||||
apiVersion: 'v1',
|
||||
clusters: [clusterConfig],
|
||||
contexts: [contextConfig],
|
||||
'current-context': process.env.CONTEXT_NAME,
|
||||
kind: 'Config',
|
||||
users: [userConfig]
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
export default kubeConfig
|
||||
@@ -1,10 +1,14 @@
|
||||
import logger from '../config/logger'
|
||||
import { Client, config } from 'kubernetes-client'
|
||||
import kubeconfig from './kubeConfig'
|
||||
|
||||
const removeClone = async (cloneId) => {
|
||||
try {
|
||||
logger.debug('removeClone %s', cloneId)
|
||||
const client = new Client({config: config.fromKubeconfig(), version: '1.9'})
|
||||
|
||||
const Request = require('kubernetes-client/backends/request')
|
||||
const backend = new Request(Request.config.fromKubeconfig(kubeconfig()))
|
||||
const client = new Client({ backend, version: '1.9' })
|
||||
|
||||
let query = {
|
||||
'qs': {
|
||||
|
||||
@@ -4,10 +4,12 @@ import { Clone } from '../../models'
|
||||
import { CloneModeEnum } from '../../enums/CloneMode'
|
||||
import { BotTypesEnum } from '../../enums/BotTypes'
|
||||
import teamQuery from '../../graphQLCalls/teamQuery'
|
||||
import authorizeClone from '../../graphQLCalls/authorizeClone'
|
||||
import authorizeKey from '../../graphQLCalls/authorizeKey'
|
||||
import authorizeStrategy from '../../graphQLCalls/authorizeStrategy'
|
||||
import cloneDetails from '../cloneDetails'
|
||||
import ecosystemQuery from '../../graphQLCalls/ecosystemQuery'
|
||||
import {
|
||||
AuthentificationError,
|
||||
AuthenticationError,
|
||||
WrongArgumentsError,
|
||||
OperationsError,
|
||||
AuthorizationError
|
||||
@@ -25,7 +27,7 @@ const resolve = async (parent, { clone }, context) => {
|
||||
logger.debug('addClone -> Entering Fuction.')
|
||||
|
||||
if (!context.userId) {
|
||||
throw new AuthentificationError()
|
||||
throw new AuthenticationError()
|
||||
}
|
||||
|
||||
if (!Object.values(CloneModeEnum).includes(clone.mode)) {
|
||||
@@ -77,19 +79,28 @@ const resolve = async (parent, { clone }, context) => {
|
||||
logger.debug('addClone -> Creating the clone on the Database.')
|
||||
let savedClone = await newClone.save()
|
||||
|
||||
logger.debug('addClone -> Authorizing clone to use the strategy.')
|
||||
let strategyResponse = await authorizeStrategy(context.authorization, clone.botSlug, clone.id, false)
|
||||
if (isDefined(strategyResponse.data.data.strategizer_AuthorizeStrategy)) {
|
||||
clone.accessTokenStrategy = strategyResponse.data.data.strategizer_AuthorizeStrategy
|
||||
} else {
|
||||
logger.warn('addClone -> Authorizing clone to use the strategy fail.')
|
||||
}
|
||||
|
||||
if (clone.mode === LIVE || clone.mode === COMPETITION) {
|
||||
logger.debug('addClone -> Authorizing clone to use the key.')
|
||||
let response = await authorizeClone(context.authorization, clone.keyId, clone.id, false)
|
||||
logger.debug('addClone -> Authorizing clone to use the key.')
|
||||
if (response.data.data.keyVault_AuthorizeClone === clone.keyId) {
|
||||
await createKubernetesClone(clone)
|
||||
|
||||
let keyResponse = await authorizeKey(context.authorization, clone.keyId, clone.id, false)
|
||||
if (isDefined(keyResponse.data.data.keyVault_AuthorizeClone)) {
|
||||
clone.accessTokenKey = keyResponse.data.data.keyVault_AuthorizeClone
|
||||
} else {
|
||||
logger.error('addClone -> Authorizing clone to use the key fail.')
|
||||
throw new AuthorizationError()
|
||||
}
|
||||
} else {
|
||||
await createKubernetesClone(clone)
|
||||
}
|
||||
|
||||
await createKubernetesClone(clone)
|
||||
|
||||
logger.debug('addClone -> Clone created sucessfully.')
|
||||
return savedClone
|
||||
} catch (err) {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { GraphQLNonNull, GraphQLID, GraphQLString } from 'graphql'
|
||||
import { AuthentificationError, OperationsError } from '../../errors'
|
||||
import { AuthenticationError, OperationsError } from '../../errors'
|
||||
import { Clone } from '../../models'
|
||||
import logger from '../../config/logger'
|
||||
import removeKuberneteClone from '../../kubernetes/removeClone'
|
||||
import teamQuery from '../../graphQLCalls/teamQuery'
|
||||
import { isDefined } from '../../config/utils'
|
||||
import cloneDetails from '../cloneDetails'
|
||||
import authorizeClone from '../../graphQLCalls/authorizeClone'
|
||||
import authorizeKey from '../../graphQLCalls/authorizeKey'
|
||||
import authorizeStrategy from '../../graphQLCalls/authorizeStrategy'
|
||||
import { LIVE, COMPETITION } from '../../enums/CloneMode'
|
||||
|
||||
const args = {
|
||||
@@ -17,7 +18,7 @@ const resolve = async (parent, { id }, context) => {
|
||||
logger.debug('removeClone -> Entering Fuction.')
|
||||
|
||||
if (!context.userId) {
|
||||
throw new AuthentificationError()
|
||||
throw new AuthenticationError()
|
||||
}
|
||||
try {
|
||||
let clone = await Clone.findOne({
|
||||
@@ -34,9 +35,10 @@ const resolve = async (parent, { id }, context) => {
|
||||
let bot = allUserBotsResponse.data.data.teams_FbByOwner.edges[0].node
|
||||
clone = cloneDetails(bot, clone)
|
||||
|
||||
await authorizeStrategy(context.authorization, clone.botSlug, clone.id, true)
|
||||
if ((clone.mode === LIVE || clone.mode === COMPETITION) && isDefined(clone.keyId)) {
|
||||
logger.debug('removeClone -> Release the clone key.')
|
||||
await authorizeClone(context.authorization, clone.keyId, clone.id, true)
|
||||
await authorizeKey(context.authorization, clone.keyId, clone.id, true)
|
||||
}
|
||||
|
||||
logger.debug('removeClone -> Removing Clone from Kubernates.')
|
||||
|
||||
@@ -7,11 +7,13 @@ import { DateTime } from 'luxon'
|
||||
import teamQuery from '../../graphQLCalls/teamQuery'
|
||||
import cloneDetails from '../cloneDetails'
|
||||
import {
|
||||
AuthentificationError,
|
||||
AuthenticationError,
|
||||
OperationsError
|
||||
} from '../../errors'
|
||||
import logger from '../../config/logger'
|
||||
import createKubernetesClone from '../../kubernetes/createClone'
|
||||
import authorizeStrategy from '../../graphQLCalls/authorizeStrategy'
|
||||
import { isDefined } from '../../config/utils'
|
||||
|
||||
const args = {
|
||||
simulation: { type: SimulationInputType }
|
||||
@@ -21,7 +23,7 @@ const resolve = async (parent, { simulation }, context) => {
|
||||
logger.debug('runSimulation -> Entering Fuction.')
|
||||
|
||||
if (!context.userId) {
|
||||
throw new AuthentificationError()
|
||||
throw new AuthenticationError()
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -49,6 +51,8 @@ const resolve = async (parent, { simulation }, context) => {
|
||||
|
||||
logger.debug('runSimulation -> Stop running clones.')
|
||||
|
||||
await authorizeStrategy(context.authorization, bot.slug, clones[i]._id, true)
|
||||
|
||||
await removeKuberneteClone(clones[i]._id)
|
||||
logger.debug('runSimulation -> Clone Removed from Kubernetes: %s.', clones[i]._id)
|
||||
|
||||
@@ -73,20 +77,20 @@ const resolve = async (parent, { simulation }, context) => {
|
||||
if (simulatorBot !== undefined) {
|
||||
if (simulation.timePeriodDailyArray !== undefined && simulation.timePeriodDailyArray.length > 0) {
|
||||
simulation.timePeriod = simulation.timePeriodDailyArray
|
||||
await createSimulatorClone(simulation, "Multi-Period-Daily", context.userId, simulatorBot)
|
||||
await createSimulatorClone(simulation, "Multi-Period-Daily", context.userId, simulatorBot, context.authorization)
|
||||
}
|
||||
|
||||
if (simulation.timePeriodMarketArray !== undefined && simulation.timePeriodMarketArray.length > 0) {
|
||||
simulation.timePeriod = simulation.timePeriodMarketArray
|
||||
await createSimulatorClone(simulation, "Multi-Period-Market", context.userId, simulatorBot)
|
||||
await createSimulatorClone(simulation, "Multi-Period-Market", context.userId, simulatorBot, context.authorization)
|
||||
}
|
||||
|
||||
if (simulation.timePeriodDailyArray === undefined && simulation.timePeriodMarketArray === undefined) {
|
||||
simulation.timePeriod = ["15-min", "10-min", "05-min"]
|
||||
await createSimulatorClone(simulation, "Multi-Period-Daily", context.userId, simulatorBot)
|
||||
await createSimulatorClone(simulation, "Multi-Period-Daily", context.userId, simulatorBot, context.authorization)
|
||||
|
||||
simulation.timePeriod = ["24-hs", "12-hs", "08-hs", "06-hs", "04-hs", "03-hs", "02-hs", "01-hs"]
|
||||
await createSimulatorClone(simulation, "Multi-Period-Market", context.userId, simulatorBot)
|
||||
await createSimulatorClone(simulation, "Multi-Period-Market", context.userId, simulatorBot, context.authorization)
|
||||
}
|
||||
|
||||
return "Simulation Clones Recreated."
|
||||
@@ -99,7 +103,7 @@ const resolve = async (parent, { simulation }, context) => {
|
||||
}
|
||||
}
|
||||
|
||||
async function createSimulatorClone(simulation, processName, userId, simulatorBot) {
|
||||
async function createSimulatorClone(simulation, processName, userId, simulatorBot, authorization) {
|
||||
let clone = {
|
||||
teamId: simulatorBot.team.id,
|
||||
botId: simulatorBot.id,
|
||||
@@ -123,6 +127,14 @@ async function createSimulatorClone(simulation, processName, userId, simulatorBo
|
||||
logger.debug('runSimulation -> Creating %s clone on the Database.', processName)
|
||||
await newClone.save()
|
||||
|
||||
logger.debug('runSimulation -> Authorizing clone to use the strategy.')
|
||||
let strategyResponse = await authorizeStrategy(authorization, clone.botSlug, clone.id, false)
|
||||
if (isDefined(strategyResponse.data.data.strategizer_AuthorizeStrategy)) {
|
||||
clone.accessTokenStrategy = strategyResponse.data.data.strategizer_AuthorizeStrategy
|
||||
} else {
|
||||
logger.warn('runSimulation -> Authorizing clone to use the strategy fail.')
|
||||
}
|
||||
|
||||
clone = cloneDetails(simulatorBot, clone)
|
||||
await createKubernetesClone(clone)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
GraphQLInt,
|
||||
GraphQLFloat
|
||||
} from 'graphql'
|
||||
import { OperationsError, AuthorizationError, AuthentificationError } from '../../errors'
|
||||
import { OperationsError, AuthorizationError, AuthenticationError } from '../../errors'
|
||||
import { Clone } from '../../models'
|
||||
import logger from '../../config/logger'
|
||||
import { isDefined } from '../../config/utils'
|
||||
@@ -29,7 +29,7 @@ const resolve = async (parent,
|
||||
logger.debug('UpdateExecutionSummary -> Entering Function.')
|
||||
|
||||
if (!context.userId) {
|
||||
throw new AuthentificationError()
|
||||
throw new AuthenticationError()
|
||||
}
|
||||
|
||||
if (!(context.userId === process.env.AACLOUD_ID)) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { GraphQLList, GraphQLString } from 'graphql'
|
||||
import { AuthentificationError, OperationsError } from '../../errors'
|
||||
import { AuthenticationError, OperationsError } from '../../errors'
|
||||
import { CloneType } from '../types'
|
||||
import { Clone } from '../../models'
|
||||
import logger from '../../config/logger'
|
||||
@@ -14,7 +14,7 @@ const resolve = async(parent, { botType }, context) => {
|
||||
logger.debug('Retrieving History Clones.')
|
||||
try {
|
||||
if (!context.userId) {
|
||||
throw new AuthentificationError()
|
||||
throw new AuthenticationError()
|
||||
}
|
||||
|
||||
let clones = await Clone.find({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { GraphQLList, GraphQLString, GraphQLBoolean } from 'graphql'
|
||||
import { AuthentificationError, OperationsError } from '../../errors'
|
||||
import { AuthenticationError, OperationsError } from '../../errors'
|
||||
import { CloneType } from '../types'
|
||||
import { Clone } from '../../models'
|
||||
import logger from '../../config/logger'
|
||||
@@ -17,7 +17,7 @@ const resolve = async (parent, { botType, queryLogs }, context) => {
|
||||
logger.debug('List Clones -> Entering Fuction.')
|
||||
try {
|
||||
if (!context.userId) {
|
||||
throw new AuthentificationError()
|
||||
throw new AuthenticationError()
|
||||
}
|
||||
|
||||
let clones = await Clone.find({
|
||||
|
||||
Reference in new issue
Block a user