-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: minio client management (env, singleton, ...) (#115)
* feat: minio client management (env, singleton, ...) * feat: bucket file upload handler + crud operations for minio bucket * feat: restrict bucket(-file) creation to robot/user * feat: remove bucket(-file) in minio before db entity deletion * fix: bucket-file upload handler should be mounted on POST http method
- Loading branch information
Showing
28 changed files
with
358 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ export function useEnv(key?: string) : any { | |
env: read('NODE_ENV', 'development') as `${EnvironmentName}`, | ||
port: readInt('PORT', 3000), | ||
redisConnectionString: read('REDIS_CONNECTION_STRING', null), | ||
minioConnectionString: read('MINIO_CONNECTION_STRING', 'http://admin:[email protected]:9000'), | ||
vaultConnectionString: read('VAULT_CONNECTION_STRING', 'start123@http://127.0.0.1:8090/v1/'), | ||
|
||
authupApiURL: read('AUTHUP_API_URL', 'http://127.0.0.1:3010/'), | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ | |
*/ | ||
|
||
export * from './authup'; | ||
export * from './minio'; | ||
export * from './database'; | ||
export * from './redis'; |
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,29 @@ | ||
/* | ||
* Copyright (c) 2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
import { parseProxyConnectionString } from '@privateaim/core'; | ||
import type { ClientOptions } from 'minio'; | ||
import { Client } from 'minio'; | ||
import { setMinioFactory } from '../../core'; | ||
import { useEnv } from '../env'; | ||
|
||
export function setupMinio() { | ||
const connectionString = useEnv('minioConnectionString'); | ||
const connectionConfig = parseProxyConnectionString(connectionString); | ||
|
||
setMinioFactory(() => { | ||
const options : ClientOptions = { | ||
endPoint: connectionConfig.host, | ||
port: connectionConfig.port, | ||
useSSL: false, | ||
accessKey: connectionConfig.auth.username, | ||
secretKey: connectionConfig.auth.password, | ||
}; | ||
|
||
return new Client(options); | ||
}); | ||
} |
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 |
---|---|---|
|
@@ -6,4 +6,6 @@ | |
*/ | ||
|
||
export * from './authup'; | ||
export * from './minio'; | ||
export * from './redis'; | ||
export * from './utils'; |
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,8 @@ | ||
/* | ||
* Copyright (c) 2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
export * from './module'; |
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,26 @@ | ||
/* | ||
* Copyright (c) 2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
import type { Client } from 'minio'; | ||
import type { Factory } from 'singa'; | ||
import { singa } from 'singa'; | ||
|
||
const singleton = singa<Client>({ | ||
name: 'redis', | ||
}); | ||
|
||
export function useMinio() { | ||
return singleton.use(); | ||
} | ||
|
||
export function hasMinio() { | ||
return singleton.has() || singleton.hasFactory(); | ||
} | ||
|
||
export function setMinioFactory(factory: Factory<Client>) { | ||
return singleton.setFactory(factory); | ||
} |
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,8 @@ | ||
/* | ||
* Copyright (c) 2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
export * from './stream-to-buffer'; |
18 changes: 18 additions & 0 deletions
18
packages/server-storage/src/core/utils/stream-to-buffer.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,18 @@ | ||
/* | ||
* Copyright (c) 2022-2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
import type { Stream } from 'node:stream'; | ||
|
||
export async function streamToBuffer(stream: Stream): Promise<Buffer> { | ||
return new Promise <Buffer>((resolve, reject) => { | ||
const parts : Buffer[] = []; | ||
|
||
stream.on('data', (chunk) => parts.push(chunk)); | ||
stream.on('end', () => resolve(Buffer.concat(parts))); | ||
stream.on('error', (err) => reject(err)); | ||
}); | ||
} |
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,11 @@ | ||
/* | ||
* Copyright (c) 2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
export enum ActorType { | ||
USER = 'user', | ||
ROBOT = 'robot', | ||
} |
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,10 @@ | ||
/* | ||
* Copyright (c) 2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
export * from './constants'; | ||
export * from './type'; | ||
export * from './utils'; |
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,13 @@ | ||
/* | ||
* Copyright (c) 2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
import type { ActorType } from './constants'; | ||
|
||
export type Actor = { | ||
id: string, | ||
type: `${ActorType}` | ||
}; |
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,25 @@ | ||
/* | ||
* Copyright (c) 2024. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
import type { Request } from 'routup'; | ||
import { useRequestEnv } from '../../http/request'; | ||
import { ActorType } from './constants'; | ||
import type { Actor } from './type'; | ||
|
||
export function getActorFromRequest(req: Request) : Actor | undefined { | ||
const userId = useRequestEnv(req, 'userId'); | ||
if (userId) { | ||
return { type: ActorType.USER, id: userId }; | ||
} | ||
|
||
const robotId = useRequestEnv(req, 'robotId'); | ||
if (robotId) { | ||
return { type: ActorType.ROBOT, id: robotId }; | ||
} | ||
|
||
return undefined; | ||
} |
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
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
Oops, something went wrong.