This repository was archived by the owner on Dec 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Spike: Rust api #2
Draft
0atman
wants to merge
30
commits into
main
Choose a base branch
from
rust-prototype
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
374ecb6
Add user file based access
MeliaBurnley fde1077
Add sequel and postgres gem
MeliaBurnley a3e3116
Add dotenv
MeliaBurnley a9a87ac
Add database class and migrations
MeliaBurnley f1ccc2a
Store forms in the database rather than files
MeliaBurnley 36e9091
Set main deploy to manual only
MeliaBurnley b71eefe
Add service binding to the API
MeliaBurnley bf748ec
Specify port on run
MeliaBurnley 193dc31
Update existing forms on publish
MeliaBurnley 8c7e3b8
Handle non existing forms
MeliaBurnley 8cc368f
Handle blank username
MeliaBurnley f4108c9
Add login and jwt token based authentication
MeliaBurnley 07dedff
Add designer url as environment variable
MeliaBurnley 722c6d0
Initial rust project
0atman f537103
Moved to native rust, docker postgres
0atman 9cdd4a2
Add readme with building instructions
0atman e103390
added pool
0atman e698fd9
Fixed CORS with the poem middleware
0atman 5b0b91f
tweak api design after discussion with @danielburnley
0atman 1e0b3fe
merge in user-based-access and update
0atman 73e6e89
set up db
0atman 6584fcc
Inserting forms function done
0atman 295e5ce
Seeding working
0atman b19d0dd
Contract the form response
0atman 01f59e2
Merge branch 'rust-prototype' of github.com:alphagov/forms-api-protot…
0atman 3da8cac
Publish new forms for user
0atman 607c276
Refactored forms into module
0atman d24d1c4
API version pulled from cargo.toml
0atman 4aa62c4
Add jwt user auth to /published
0atman 26339ff
change plain json responses to typed ones
0atman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| DATABASE_URL=postgres://postgres:postgres@localhost/postgres |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,8 +1,7 @@ | ||
| name: Deploy to GOV.UK PaaS | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| workflow_dispatch: | ||
|
|
||
| env: | ||
| REGISTRY: ghcr.io | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| forms/ | ||
| *target/ |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| # GOV.UK Forms API Prototype | ||
|
|
||
| A prototype for a forms API for the GOV.UK Forms team built with Ruby and Sinatra. | ||
|
|
||
| ## Running the database with docker | ||
|
|
||
| `docker run --name db -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres:13` |
This file contains hidden or 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,5 @@ | ||
| RACK_ENV = ENV['RACK_ENV'] ||= 'development' unless defined?(RACK_ENV) | ||
| require_relative 'loader' | ||
| require_relative './server' | ||
|
|
||
| run Server |
This file contains hidden or 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,40 @@ | ||
| require "sequel" | ||
|
|
||
| class Migrator | ||
| def initialize | ||
| Sequel.extension :migration | ||
| end | ||
|
|
||
| def destroy(database) | ||
| Sequel::Migrator.run(database, "#{__dir__}/migrations", target: 0) | ||
| end | ||
|
|
||
| def migrate(database) | ||
| Sequel::Migrator.run(database, "#{__dir__}/migrations") | ||
| end | ||
|
|
||
| def migrate_to(database, version) | ||
| Sequel::Migrator.run(database, "#{__dir__}/migrations", target: version) | ||
| end | ||
| end | ||
|
|
||
| class Database | ||
| def initialize | ||
| @migrator = Migrator.new | ||
| end | ||
|
|
||
| def connect | ||
| database = Sequel.connect(ENV['DATABASE_URL']) | ||
| load_extensions_for(database) | ||
|
|
||
| @migrator.migrate(database) | ||
| database | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def load_extensions_for(database) | ||
| database.extension :pg_json | ||
| database.extension :pg_array | ||
| end | ||
| end |
This file contains hidden or 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 @@ | ||
| Sequel.migration do | ||
| change do | ||
| create_table :forms do | ||
| primary_key :id, type: :Bignum | ||
| String :username | ||
| String :key | ||
| String :display_name | ||
| column :form, 'json' | ||
| end | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.