Skip to content

Création d'un service en Go pour pouvoir m'y connecter via mon portfolio-apple et interagire avec le système de fichier via l'IHM.

Notifications You must be signed in to change notification settings

nicolachoquet06250/file-system-service

Repository files navigation

file-system-service

Création d'un service en Go pour pouvoir m'y connecter via mon portfolio-apple et interagire avec le système de fichier via l'IHM.

Quick start

Installation

Linux & MacOSX

Get Last Swagger
wget https://github.com/nicolachoquet06250/file-system-service/releases/download/$(curl https://api.github.com/repos/nicolachoquet06250/file-system-service/releases | jq .[0].name | sed 's/.\(.*\)/\1/' | sed 's/\(.*\)./\1/')/swagger/swagger.yaml

Linux

Get Last binary
last_version="$(curl https://api.github.com/repos/nicolachoquet06250/file-system-service/releases | jq .[0].name | sed 's/.\(.*\)/\1/' | sed 's/\(.*\)./\1/')" && \
  wget -c https://github.com/nicolachoquet06250/file-system-service/releases/download/${last_version}/file-system-service-linux-${last_version}-linux-amd64.tar.gz && \
  tar -xf file-system-service-linux-${last_version}-linux-amd64.tar.gz && \
  rm file-system-service-linux-${last_version}-linux-amd64.tar.gz

MacOSX amd64

Get Last binary
last_version="$(curl https://api.github.com/repos/nicolachoquet06250/file-system-service/releases | jq .[0].name | sed 's/.\(.*\)/\1/' | sed 's/\(.*\)./\1/')" && \
  wget -c https://github.com/nicolachoquet06250/file-system-service/releases/download/${last_version}/file-system-service-darwin-${last_version}-darwin-amd64.tar.gz && \
  tar -xf file-system-service-darwin-${last_version}-darwin-amd64.tar.gz && \
  rm file-system-service-darwin-${last_version}-darwin-amd64.tar.gz

MacOSX arm64

Get Last binary
last_version="$(curl https://api.github.com/repos/nicolachoquet06250/file-system-service/releases | jq .[0].name | sed 's/.\(.*\)/\1/' | sed 's/\(.*\)./\1/')" && \
  wget -c https://github.com/nicolachoquet06250/file-system-service/releases/download/${last_version}/file-system-service-darwin-${last_version}-darwin-arm64.tar.gz && \
  tar -xf file-system-service-darwin-${last_version}-darwin-arm64.tar.gz && \
  rm file-system-service-darwin-${last_version}-darwin-arm64.tar.gz

Windows

https://github.com/nicolachoquet06250/file-system-service/releases/latest

Get Last Swagger

Click on file-system-service.swagger.yml

Get Last binary

Click on file-system-service-windows-{version}-windows-amd64.zip

Commands

Generate credentials

sudo file-system-service --generate-credentials [--role <role=readonly>]
flag type default value optional
generate-credential boolean false
role enum (readwrite, readonly) readonly ✔️

Update credentials

sudo file-system-service --update-credentials --client_id <client_id> [--role <role=readonly>]
flag type default value optional
update-credential boolean false
client_id string null
role enum (readwrite, readonly) readonly ✔️

Show all available roles

sudo file-system-service --show-roles
flag type default value optional
show-roles boolean false

Show user current role

sudo file-system-service --show-user-role --client_id <client_id>
flag type default value optional
show-user-role boolean false
client_id string null

Start server

sudo file-system-service [--host <host='127.0.0.1'>] [--port <port=3000>]
flag type default value optional
host string 127.0.0.1 ✔️
post integer 3000 ✔️

Swagger

API Reference

Check Validity

GET /check-validity
Response 200
{
  "isValid": true
}

Authentification

Get first token
POST /auth/get-token
Accept: application/json
Content-Type: application/json
Authorization: Basic {base64(<client_id>:<client_secret>)}

or

POST /auth/get-token?client_id=<client_id>&client_secret=<client_secret>
Accept: application/json
Content-Type: application/json
Response 200
{
  "access_token": "string",
  "refresh_token": "string",
  "expires_in": "int",
  "created_at": "int"
}
Response 400
{
  "code": 400,
  "message": "string"
}
Response 500
{
  "code": 500,
  "message": "string"
}
Refresh token
PUT /auth/get-token
Accept: application/json
Content-Type: application/json
Refresh-Token: {getted-refresh-token}
Response 200
{
  "access_token": "string",
  "refresh_token": "string",
  "expires_in": "int",
  "created_at": "int"
}
Response 400
{
  "code": 400,
  "message": "string"
}
Response 500
{
  "code": 500,
  "message": "string"
}

Get directory list content items

GET /file-system/${path...}
Parameter Type Description Default value
path string Optional. The path of the directory you would like open /
Response 200
[
    {
        "type": "directory",
        "path": "/home",
        "name": "nchoquet"
    },
    {
        "type": "file",
        "path": "/home",
        "name": ".bashrc"
    },
    "..."
]
Response 400
{
    "code": 400,
    "message": "an error message"
}
Response 404
{
  "code": 404,
  "message": "an error message"
}
Response 403
{
  "code": 403,
  "message": "an error message"
}

Create a directory

POST /directory
Accept: application/json
Content-Type: application/json

{
    "type": "directory",
    "path": "string",
    "name": "string"
}
Response 200
{
  "path": "string",
  "name": "string"
}
Response 400
{
  "code": 400,
  "message": "an error message"
}
Response 404
{
  "code": 404,
  "message": "an error message"
}
Response 403
{
  "code": 403,
  "message": "an error message"
}

Rename directory

PATCH /directory/{path...}
Accept: application/json
Content-Type: application/json

{
  "type": "directory",
  "path": "string",
  "name": "string"
}
Parameter Type Description Default value
path string Optional. The path of the directory you would like open /
Response 200
{
  "path": "string",
  "name": "string"
}
Response 400
{
  "code": 400,
  "message": "an error message"
}
Response 404
{
  "code": 404,
  "message": "an error message"
}
Response 403
{
  "code": 403,
  "message": "an error message"
}

Delete directory

DELETE /directory/{path...}
Accept: application/json
Parameter Type Description Default value
path string Optional. The path of the directory you would like open /
Response 200
{
  "status": "success"
}
Response 400
{
  "code": 400,
  "message": "an error message"
}
Response 404
{
  "code": 404,
  "message": "an error message"
}
Response 403
{
  "code": 403,
  "message": "an error message"
}

Create file with content

POST http://localhost:3000/file
Accept: application/json
Content-Type: multipart/form-data; boundary=boundary

--boundary
Content-Disposition: form-data; name="file"
Content-Type: application/json

{
    "type": "file"
    "path": "/path/to/create",
    "name": "file-to-create",
    "extension": "your-extension"
}

--boundary
Content-Disposition: form-data; name="content"
Content-Type: text/plain

Ceci est un test
--boundary--
Response 200
{
    "path": "/path/to/create",
    "name": "file-to-create",
    "extension": "your-extension"
}
Response 400
{
    "code": 400,
    "message": "an error message"
}
Parameter Type Description Default value
path string Optional. The path of the directory you would like open /
Response 403
{
  "code": 403,
  "message": "an error message"
}

Create file without content

POST http://localhost:3000/file
Accept: application/json
Content-Type: application/json

{
    "type": "file"
    "path": "/path/to/create",
    "name": "file-to-create",
    "extension": "your-extension"
}
Response 200
{
    "path": "/path/to/create",
    "name": "file-to-create",
    "extension": "your-extension"
}
Response 400
{
    "code": 400,
    "message": "an error message"
}
Parameter Type Description Default value
path string Optional. The path of the directory you would like open /
Response 403
{
  "code": 403,
  "message": "an error message"
}

Get file content

GET /file/${path...}
Accept: application/json
Parameter Type Description Default value
path string Optional. The path of the directory you would like open /
Response 200
application/json
text/plain
text/xml
application/pdf
Response 400
{
  "code": 400,
  "message": "an error message"
}
Response 404
{
  "code": 404,
  "message": "an error message"
}
Response 403
{
  "code": 403,
  "message": "an error message"
}

Rename selected file

PATCH /file/{path...}
Accept: application/json
Content-Type: application/json

{
  "type": "file",
  "path": "/path/to/create",
  "name": "file-to-create",
  "extension": "your-extension"
}
Parameter Type Description Default value
path string Optional. The path of the directory you would like open /
Response 200
{
  "path": "/path/to/create",
  "name": "file-to-create",
  "extension": "your-extension"
}
Response 400
{
  "code": 400,
  "message": "an error message"
}
Response 404
{
  "code": 404,
  "message": "an error message"
}
Response 403
{
  "code": 403,
  "message": "an error message"
}

Update selected file content

PUT /file/{path...}
Accept: application/json
Content-Type: text/plain

This is a text for update
the fichier
Response 200
{
  "status": "success"
}
Response 400
{
  "code": 400,
  "message": "an error message"
}
Response 404
{
  "code": 404,
  "message": "an error message"
}
Response 403
{
  "code": 403,
  "message": "an error message"
}

Delete selected file

DELETE /file/{path...}
Accept: application/json
Response 200
{
  "status": "success"
}
Response 400
{
  "code": 400,
  "message": "an error message"
}
Response 404
{
  "code": 404,
  "message": "an error message"
}
Response 403
{
  "code": 403,
  "message": "an error message"
}

About

Création d'un service en Go pour pouvoir m'y connecter via mon portfolio-apple et interagire avec le système de fichier via l'IHM.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages