Skip to content

Commit

Permalink
Merge pull request #3 from rarimo/feat/s3-integrations
Browse files Browse the repository at this point in the history
Add endpoints with s3 integrations. Change docs.
  • Loading branch information
Zaptoss authored Jul 22, 2024
2 parents 8d6f740 + 948397f commit 378991e
Show file tree
Hide file tree
Showing 38 changed files with 892 additions and 240 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
cd geo-forms-svc
go build main.go
export KV_VIPER_FILE=./config.yaml
export SPACES_KEY=access_key
export SPACES_SECRET=secret_key
./main migrate up
./main run service
```
Expand Down
5 changes: 5 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ forms:
resend_forms_count: 1
url: forms:forms@tcp(127.0.0.1:5441)/forms

storage:
endpoint: https://fra1.digitaloceanspaces.com
allowed_buckets:
- bucket

auth:
addr: http://127.0.0.1:5000
21 changes: 18 additions & 3 deletions docs/spec/components/schemas/Form.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ allOf:
attributes:
type: object
required:
- status
- name
- surname
- id_num
Expand All @@ -29,32 +28,48 @@ allOf:
description: |
Accepted - the data was saved by the service for further processing
Processed - the data is processed and stored
Read-only.
name:
type: string
example: Hilary
surname:
type: string
example: Cabe
id_num:
type: string
example: "3736297649"
birthday:
type: string
example: 27/6/1988
citizen:
type: string
example: Georgian
visited:
type: string
example: 18/07/2024
purpose:
type: string
example: Make documents
country:
type: string
example: Georgia
city:
type: string
example: Kutaisi
address:
type: string
example: Central street, 1
postal:
type: string
example: "21626"
phone:
type: string
example: "+13165282105"
email:
type: string
type: [email protected]
image:
type: string
description: base64 encoded image with max size 4 MB
description: |
base64 encoded image with max size 4 MB or
URL for S3 storage with image up to 4 mb
example: https://geoforms.nyc3.digitaloceanspaces.com/awesome_phono.jpg
3 changes: 1 addition & 2 deletions docs/spec/components/schemas/FormKey.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
type: object
required:
- id
- type
properties:
id:
type: string
description: UUID for check form submission status
type:
type: string
enum: [ form ]
enum: [ form, submit_form ]
41 changes: 41 additions & 0 deletions docs/spec/components/schemas/FormStatus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
allOf:
- $ref: '#/components/schemas/FormStatusKey'
- type: object
required:
- attributes
properties:
attributes:
type: object
required:
- status
- created_at
- next_form_at
- until_next_form
properties:
status:
type: string
enum: [ accepted, processed ]
description: |
Accepted - the data was saved by the service for further processing
Processed - the data is processed and stored
created_at:
type: integer
format: int64
example: 1721392530
description: Form submission time. Unix time.
processed_at:
type: integer
format: int64
example: 1721392530
description: Form processing time. Absent if the status is accepted. Unix time.
next_form_at:
type: integer
format: int64
example: 1721392530
description: Time of the next possible form submission. Unix time.
until_next_form:
type: integer
format: int64
example: 120
description: Time until the next form submission in seconds.

7 changes: 7 additions & 0 deletions docs/spec/components/schemas/FormStatusKey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: object
required:
- type
properties:
type:
type: string
enum: [ form_status ]
54 changes: 0 additions & 54 deletions docs/spec/components/schemas/SubmitForm.yaml

This file was deleted.

13 changes: 0 additions & 13 deletions docs/spec/components/schemas/SubmitFormKey.yaml

This file was deleted.

7 changes: 3 additions & 4 deletions docs/spec/components/securitySchemes/BearerAuth.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
BearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
type: http
scheme: bearer
bearerFormat: JWT
44 changes: 44 additions & 0 deletions docs/spec/paths/integrations@forms-svc@[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
post:
tags:
- User form
summary: Submit lightweight user answers
description: |
Send user answers and return their current status.
The image is a link to s3 storage
Only a user with a confirmed passport can send the form ('verified: true' in JWT).
There is a configurable delay before the same user
can submit another form.
operationId: lightweightSubmitForm
security:
- BearerAuth: []
requestBody:
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/SubmitForm'
responses:
200:
description: "Success"
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/FormStatus'
400:
$ref: '#/components/responses/invalidParameter'
401:
$ref: '#/components/responses/invalidAuth'
429:
description: "It is necessary to wait some time before sending the next form"
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/Errors'
500:
$ref: '#/components/responses/internalError'
10 changes: 6 additions & 4 deletions docs/spec/paths/integrations@forms-svc@v1@[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ post:
description: |
Send user answers and return their current status.
Only a user with a confirmed passport can send the form.
The image is a base64 string.
Only a user with a confirmed passport can send the form ('verified: true' in JWT).
There is a configurable delay before the same user
can submit another form.
operationId: submitForm
security:
- BearerAuth: [ "verified: true" ]
- BearerAuth: []
requestBody:
content:
application/vnd.api+json:
Expand All @@ -20,10 +22,10 @@ post:
- data
properties:
data:
$ref: '#/components/schemas/SubmitForm'
$ref: '#/components/schemas/Form'
responses:
200:
description: "Success"
description: "Success. All fields except image will be returned."
content:
application/vnd.api+json:
schema:
Expand Down
31 changes: 31 additions & 0 deletions docs/spec/paths/integrations@forms-svc@v1@[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
get:
tags:
- User form
summary: Get last form status
description: |
Get last form status filled out by the user nullifier.
operationId: getLastFormStatus
parameters:
- $ref: '#/components/parameters/pathNullifier'
security:
- BearerAuth: []
responses:
200:
description: Success
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/FormStatus'
400:
$ref: '#/components/responses/invalidParameter'
401:
$ref: '#/components/responses/invalidAuth'
404:
$ref: '#/components/responses/notFound'
500:
$ref: '#/components/responses/internalError'
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
get:
tags:
- User form
summary: Get form
summary: Get form status
description: |
Get user form by UUID with status.
User must be authorized, but `is_verified` field is not required in JWT.
operationId: getForm
Get form status by UUID.
operationId: getFormStatus
parameters:
- $ref: '#/components/parameters/pathID'
security:
- BearerAuth: []
responses:
200:
description: Success
Expand Down
12 changes: 8 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ go 1.22.2
require (
github.com/Masterminds/squirrel v1.5.4
github.com/alecthomas/kingpin v2.2.6+incompatible
github.com/aws/aws-sdk-go v1.54.20
github.com/go-chi/chi v4.1.2+incompatible
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
github.com/go-sql-driver/mysql v1.6.0
github.com/rarimo/geo-auth-svc v0.1.0
github.com/rubenv/sql-migrate v1.6.1
gitlab.com/distributed_lab/ape v1.7.1
gitlab.com/distributed_lab/dig v0.0.0-20230207152643-c44f80a4294c
gitlab.com/distributed_lab/figure/v3 v3.1.4
gitlab.com/distributed_lab/kit v1.11.3
gitlab.com/distributed_lab/logan v3.8.1+incompatible
Expand Down Expand Up @@ -46,6 +48,7 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/iden3/go-rapidsnark/types v0.0.3 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmoiron/sqlx v1.3.5 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
Expand Down Expand Up @@ -77,13 +80,14 @@ require (
gitlab.com/distributed_lab/figure v2.1.2+incompatible // indirect
gitlab.com/distributed_lab/lorem v0.2.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.20.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
Expand Down
Loading

0 comments on commit 378991e

Please sign in to comment.