Skip to content

Commit

Permalink
Merge pull request #11 from Duna-System/feat/pipeline-1.0
Browse files Browse the repository at this point in the history
pipeline 1.0
  • Loading branch information
Marcus-D-Forte authored Jun 23, 2023
2 parents 7001b7d + 370ed9d commit 6aa5378
Show file tree
Hide file tree
Showing 16 changed files with 446 additions and 265 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Docker Image CI

on:
push:
branches: ['main']
pull_request:
branches: ['main']

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: ./docker_build.sh
shell: bash
- name: Coder formatter
run: docker run duna-web-platform-projects npx prettier -c .

- name: Tests
run: docker run duna-web-platform-projects npm run test
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Duna Web Platform Buckets
# Duna Web Platform Projects

Este repositório é hospedado em cluster de computação distribuída escalável com o único propósito de
hospedagem de pastas como buckets para usuários da Duna Web Platform.
Este repositório é hospedado em cluster de computação distribuída escalável (i.e AWS) com o único propósito de
hospedagem de pastas de projetos para usuários da Duna Web Platform. Projetos são agrupamento de entidades de captura.

## Formatação de código

Expand Down
2 changes: 1 addition & 1 deletion docker_build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

docker build -t duna-web-platform-buckets .
docker build -t duna-web-platform-projects .
16 changes: 8 additions & 8 deletions docs/api_documentatio.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Introduction

The Buckets API is designed to manage the files (buckets) for each user of the `Duna platform` system.
The Buckets API is designed to manage the files (buckets) for each user of the `Duna platform` system.
The user has the abitlity to create, delete and update projects and its entities. The platform will translate the user requests into API calls.


## API endpoints

| Endpoint | Type | Description | Input |
|-----------------------------------|--------|----------------------------|-----------------------------------------------------------------|
| --------------------------------- | ------ | -------------------------- | --------------------------------------------------------------- |
| /api | POST | Check the API key validity | api_token |
| /create | POST | Create bucket | client_name; project_name; project_type |
| /delete | DELETE | Delete User | owner_uuid |
Expand All @@ -17,21 +16,22 @@ The user has the abitlity to create, delete and update projects and its entities
| /delete/:project_id | DELETE | Delete a project | owner_uuid; project_id |
| /info/:project_id | GET | Get project information | owner_uuid; project_id |
| /put/:project_id | PUT | Add entity | owner_uuid; project_id |
| /get/:project_id/:type/:entity | GET | Request entity | owner_uuid; project_id; entity_type; entity_name |
| /delete/:project_id/:type/:entity | DELETE | Delete entity | owner_uuid; project_id; entity_type; entity_name |
| /rename/:project_id/:type/:entity | POST | Rename entity | owner_uuid; project_id; entity_type; entity_name; new_name |
| /get/:project_id/:type/:entity | GET | Request entity | owner_uuid; project_id; entity_type; entity_name |
| /delete/:project_id/:type/:entity | DELETE | Delete entity | owner_uuid; project_id; entity_type; entity_name |
| /rename/:project_id/:type/:entity | POST | Rename entity | owner_uuid; project_id; entity_type; entity_name; new_name |

---

## File Structure

Each `user` can have one or more projects (buckets) assigned to its account. For each project 3 folders are created to organize the entities by its type. The possible types are `bim`, `cloulds` and `images`.

![File Structure](file_structure.drawio.svg)

---

## Local storage vs Cloud storage

The buckets api can be hosted in a local server or in a cloud based storage. To make it possible, the design of the api has to create an abstraction of the possible requests of the storage system, and also provide specific implementations for each kind of storage service. For instance, creating a folder in a local storage might use `mkdir` command in the OS level, but using AWS storage service, the command will be a request to the AWS API instead.
The buckets api can be hosted in a local server or in a cloud based storage. To make it possible, the design of the api has to create an abstraction of the possible requests of the storage system, and also provide specific implementations for each kind of storage service. For instance, creating a folder in a local storage might use `mkdir` command in the OS level, but using AWS storage service, the command will be a request to the AWS API instead.

![Class Diagram](bucket_abstraction.drawio.svg)

2 changes: 2 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ export default {

//evitar que o jest utilize arquivos buildados
modulePathIgnorePatterns: ['dist'],

setupFilesAfterEnv: ['<rootDir>/tst/setup.ts'],
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"dev": "nodemon src/Main.ts -e ts",
"prod": "NODE_ENV=production node dist/src/Main.js",
"format": "prettier --write .",
"test": "jest"
"test": "jest --silent"
},
"repository": {
"type": "git",
Expand Down
11 changes: 5 additions & 6 deletions src/BaseBucketManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ export abstract class BaseBucketManager {
constructor(bucket_root: string) {
this.bucket_root = bucket_root;

console.log('Manager root exist?', fs.existsSync(this.bucket_root));
// console.log('Manager root exist?', fs.existsSync(this.bucket_root));
if (!fs.existsSync(this.bucket_root)) {
console.log('creating dir: ', this.bucket_root);
// console.log('creating dir: ', this.bucket_root);
fs.mkdirSync(this.bucket_root);
}

Expand Down Expand Up @@ -207,9 +207,9 @@ export abstract class BaseBucketManager {
* @param user_id (uuid) of owner of project.
* @returns
*/
public async getInfo(user_id: string): Promise<BucketObject> {
public async getInfo(user_id: string): Promise<Array<BucketObject>> {
try {
return await this.db.getObject<BucketObject>(this.dbPath(user_id));
return await this.db.getObject<Array<BucketObject>>(this.dbPath(user_id));
} catch (err) {
throw Error(`No Project for user_id '${user_id}' exists.`);
}
Expand Down Expand Up @@ -331,7 +331,6 @@ export abstract class BaseBucketManager {
project_type: string
): Promise<BucketObject> {
const bucket_obj = new BucketObject(project_name, client_name, project_type);

try {
// if Exists
if (await this.db.exists(this.dbPath(user_id, 'projects'))) {
Expand Down Expand Up @@ -396,7 +395,7 @@ export abstract class BaseBucketManager {
public async removeProject(user_id: string, project_id: string) {
let idx = await this.db.getIndex(this.dbPath(user_id, 'projects'), project_id, 'id');
if (idx != -1) {
this.db.delete(this.dbPath(user_id, `projects[${idx}]`));
await this.db.delete(this.dbPath(user_id, `projects[${idx}]`));
this.performRemoveProject(user_id, project_id);
} else throw new Error(`Project '${project_id}' does exist for user '${user_id}'.`);
}
Expand Down
10 changes: 7 additions & 3 deletions src/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export class Controller {
entity_type,
entity_name
);
console.log(`ret = ${ret}`);
res.download(ret);
} catch (err) {
// Create test for this ,check if this status is 400
Expand All @@ -175,7 +176,7 @@ export class Controller {
const owner_uuid = res.locals.token_uuid;

if (project_id == undefined) {
return res.send(ErrorMessages.InvalidFormat);
return res.status(400).send(ErrorMessages.InvalidFormat);
}

const quota_info = await this.bucketManager.getQuotaInfo(owner_uuid, project_id);
Expand Down Expand Up @@ -266,17 +267,20 @@ export class Controller {
const project_id = req.params.project_id;
const owner_uuid = res.locals.token_uuid;

if (owner_uuid === undefined) return res.status(400).send(ErrorMessages.InvalidFormat).end();

try {
// Send general info.
if (project_id === undefined) {
const ret = await this.bucketManager.getInfo(owner_uuid);
res.status(200).send(ret);
res.status(200).send(ret).end();
return;
} else {
const ret = await this.bucketManager.getProjectInfo(owner_uuid, project_id);
res.status(200).send(ret);
res.status(200).send(ret).end();
}
} catch (err) {
console.error(err);
res.status(500).send(`Error: ${(err as Error).message}`);
}
res.end();
Expand Down
81 changes: 0 additions & 81 deletions tst/bucketGetInfo.test.ts

This file was deleted.

133 changes: 0 additions & 133 deletions tst/bucketListRemove.test.ts

This file was deleted.

Loading

0 comments on commit 6aa5378

Please sign in to comment.