Adding read and write permissions to teams
This commit is contained in:
1 parent
afb5a35269
commit
4b519f25b6
7 files changed
+70
-8
No files matched your search
@@ -8,7 +8,7 @@
|
||||
"url": "https://demo-api-dev.superalgos.org/",
|
||||
"storage": "localStorage",
|
||||
"container": "aamasters",
|
||||
"accessKey": ""
|
||||
"accessKey": "09e890b76767ede3e10f0526b5036600a6b8d3faac540336e12b493fdb2aa9ed46f86094c34652f99fb6322e5f09806412f17725807f85e4dc4169bd22dd59f0b23aba5251f5544478a1aabf5a2dea5260e6eb0c29af3a788208af85025a02f94950437d501b91fd55b9d97b3d6ac3af4e1161321f78b73ca0fda524dc3a5d03"
|
||||
},
|
||||
"bots": [
|
||||
{
|
||||
@@ -728,7 +728,7 @@
|
||||
"url": "https://demo-api-dev.superalgos.org/",
|
||||
"container": "aavikings",
|
||||
"storage": "localStorage",
|
||||
"accessKey": ""
|
||||
"accessKey": "0f38fea438be5adfc5873228f503c55353fb334406128b16a958851b8e47c118a08f0105dd8985d5479758fc4cc3f56c2e2364c2d7c3d0fdffba8d7e9356056a34629e3b926b1ebb940122d973db30b04fc18fab542cbc1afdc032dccf64b0fe308ee6bbc74f82bd350aaebf723428a50d8a699fa2b4b96d58716986ed24069f"
|
||||
},
|
||||
"bots": [
|
||||
{
|
||||
@@ -834,8 +834,8 @@
|
||||
"host": {
|
||||
"url": "https://demo-api-dev.superalgos.org/",
|
||||
"storage": "localStorage",
|
||||
"container": "aaplatform",
|
||||
"accessKey": ""
|
||||
"container": "aamasters",
|
||||
"accessKey": "09e890b76767ede3e10f0526b5036600a6b8d3faac540336e12b493fdb2aa9ed46f86094c34652f99fb6322e5f09806412f17725807f85e4dc4169bd22dd59f0b23aba5251f5544478a1aabf5a2dea5260e6eb0c29af3a788208af85025a02f94950437d501b91fd55b9d97b3d6ac3af4e1161321f78b73ca0fda524dc3a5d03"
|
||||
},
|
||||
"competitions": [
|
||||
{
|
||||
|
||||
@@ -31,6 +31,10 @@ const ecosystemSchema = new Schema({
|
||||
accessKey: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
ownerKey: {
|
||||
type: String,
|
||||
required: false
|
||||
}
|
||||
},
|
||||
bots: [{
|
||||
|
||||
@@ -6,6 +6,7 @@ import { TeamInputType } from '../types/input'
|
||||
import { copyBot } from '../../storage/CopyBot'
|
||||
import { copySimulator } from '../../storage/CopySimulator'
|
||||
import { createContainer, writeFileContent } from '../../storage/providers/MinioStorage'
|
||||
import crypto from 'crypto'
|
||||
|
||||
export const args = { team: { type: TeamInputType } }
|
||||
|
||||
@@ -51,7 +52,8 @@ const resolve = async (parent, { team }, context) => {
|
||||
url: process.env.NODE_ENDPOINT,
|
||||
storage: 'localStorage',
|
||||
container: team.codeName,
|
||||
accessKey: '',
|
||||
accessKey: crypto.randomBytes(128).toString('hex'),
|
||||
ownerKey: crypto.randomBytes(128).toString('hex')
|
||||
}
|
||||
team.host = nodeEndpoint
|
||||
}
|
||||
|
||||
@@ -2,13 +2,24 @@ import logger from '../../utils/logger'
|
||||
import { FileInputType } from '../types/input'
|
||||
import { GraphQLString } from 'graphql'
|
||||
import { writeFileContent } from '../../storage/providers/MinioStorage'
|
||||
import { AuthenticationError, WrongArgumentsError } from '../../errors'
|
||||
import getDevTeamHost from '../../utils/getDevTeamHost'
|
||||
|
||||
export const args = { file: { type: FileInputType } }
|
||||
|
||||
const resolve = async (parent, { file }, context) => {
|
||||
logger.debug('createFile -> Entering Function: ' + file.container + '/' + file.filePath)
|
||||
try {
|
||||
//TODO Add permissions
|
||||
if (file.accessKey === undefined || file.accessKey === null) {
|
||||
throw new WrongArgumentsError()
|
||||
}
|
||||
|
||||
let host = await getDevTeamHost(file.container, undefined, file.accessKey)
|
||||
|
||||
if (host === undefined || host === null) {
|
||||
throw new AuthenticationError()
|
||||
}
|
||||
|
||||
await writeFileContent(file.container, file.filePath, file.fileContent)
|
||||
return 'File created.'
|
||||
} catch (err) {
|
||||
|
||||
@@ -3,6 +3,8 @@ import { FileInputType } from '../types/input'
|
||||
import { GraphQLString } from 'graphql'
|
||||
import { getFileContent } from '../../storage/providers/MinioStorage'
|
||||
import { getFileContentRemote } from '../../storage/providers/AzureStorage'
|
||||
import { AuthenticationError, WrongArgumentsError } from '../../errors'
|
||||
import getDevTeamHost from '../../utils/getDevTeamHost'
|
||||
|
||||
export const args = { file: { type: FileInputType } }
|
||||
|
||||
@@ -10,10 +12,18 @@ const resolve = async (parent, { file }, context) => {
|
||||
logger.debug('getFileContent -> Entering Function: ' + file.container + '/' + file.filePath)
|
||||
|
||||
try {
|
||||
if (file.accessKey === undefined || file.accessKey === null) {
|
||||
throw new WrongArgumentsError()
|
||||
}
|
||||
|
||||
let host = await getDevTeamHost(file.container, file.accessKey)
|
||||
|
||||
if (host === undefined || host === null) {
|
||||
throw new AuthenticationError()
|
||||
}
|
||||
|
||||
let fileContent
|
||||
if (file.storage === 'localStorage') {
|
||||
//TODO Add permissions
|
||||
fileContent = await getFileContent(file.container, file.filePath)
|
||||
} else {
|
||||
fileContent = await getFileContentRemote(file.container, file.filePath, file.storage, file.accessKey)
|
||||
|
||||
@@ -9,7 +9,8 @@ const HostType = new GraphQLObjectType({
|
||||
url: { type: GraphQLString },
|
||||
storage: { type: GraphQLString },
|
||||
container: { type: GraphQLString },
|
||||
accessKey: { type: GraphQLString }
|
||||
accessKey: { type: GraphQLString },
|
||||
ownerKey: { type: GraphQLString }
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Ecosystem } from '../models'
|
||||
|
||||
let teamCache = new Map()
|
||||
export default async function getDevTeamHost(devTeamName, accessKey, ownerKey) {
|
||||
let host
|
||||
if (accessKey) {
|
||||
host = teamCache.get(devTeamName + '.accessKey')
|
||||
} else {
|
||||
host = teamCache.get(devTeamName + '.ownerKey')
|
||||
}
|
||||
if (host) {
|
||||
if (host.accessKey === accessKey || host.ownerKey === ownerKey) {
|
||||
return host
|
||||
}
|
||||
} else {
|
||||
let ecosystem = await Ecosystem.find()
|
||||
|
||||
for (var i = 0; i < ecosystem.length; i++) {
|
||||
for (var j = 0; j < ecosystem[i].devTeams.length; j++) {
|
||||
if (ecosystem[i].devTeams[j].codeName.toLowerCase() === devTeamName.toLowerCase()) {
|
||||
if (ecosystem[i].devTeams[j].host.accessKey === accessKey) {
|
||||
teamCache.set(devTeamName + '.accessKey', ecosystem[i].devTeams[j].host)
|
||||
return ecosystem[i].devTeams[j].host
|
||||
}
|
||||
if (ecosystem[i].devTeams[j].host.ownerKey === ownerKey) {
|
||||
teamCache.set(devTeamName + '.ownerKey', ecosystem[i].devTeams[j].host)
|
||||
return ecosystem[i].devTeams[j].host
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user