Skip to content
This repository was archived by the owner on Dec 13, 2022. It is now read-only.
Draft
Show file tree
Hide file tree
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 Jan 14, 2022
fde1077
Add sequel and postgres gem
MeliaBurnley Jan 14, 2022
a3e3116
Add dotenv
MeliaBurnley Jan 17, 2022
a9a87ac
Add database class and migrations
MeliaBurnley Jan 17, 2022
f1ccc2a
Store forms in the database rather than files
MeliaBurnley Jan 17, 2022
36e9091
Set main deploy to manual only
MeliaBurnley Jan 19, 2022
b71eefe
Add service binding to the API
MeliaBurnley Jan 19, 2022
bf748ec
Specify port on run
MeliaBurnley Jan 19, 2022
193dc31
Update existing forms on publish
MeliaBurnley Jan 19, 2022
8c7e3b8
Handle non existing forms
MeliaBurnley Jan 20, 2022
8cc368f
Handle blank username
MeliaBurnley Jan 25, 2022
f4108c9
Add login and jwt token based authentication
MeliaBurnley Jan 26, 2022
07dedff
Add designer url as environment variable
MeliaBurnley Jan 27, 2022
722c6d0
Initial rust project
0atman Feb 7, 2022
f537103
Moved to native rust, docker postgres
0atman Feb 8, 2022
9cdd4a2
Add readme with building instructions
0atman Feb 8, 2022
e103390
added pool
0atman Feb 9, 2022
e698fd9
Fixed CORS with the poem middleware
0atman Feb 9, 2022
5b0b91f
tweak api design after discussion with @danielburnley
0atman Feb 9, 2022
1e0b3fe
merge in user-based-access and update
0atman Feb 14, 2022
73e6e89
set up db
0atman Feb 14, 2022
6584fcc
Inserting forms function done
0atman Feb 15, 2022
295e5ce
Seeding working
0atman Feb 22, 2022
b19d0dd
Contract the form response
0atman Feb 22, 2022
01f59e2
Merge branch 'rust-prototype' of github.com:alphagov/forms-api-protot…
0atman Feb 22, 2022
3da8cac
Publish new forms for user
0atman Feb 23, 2022
607c276
Refactored forms into module
0atman Feb 28, 2022
d24d1c4
API version pulled from cargo.toml
0atman Feb 28, 2022
4aa62c4
Add jwt user auth to /published
0atman Mar 1, 2022
26339ff
change plain json responses to typed ones
0atman Mar 2, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL=postgres://postgres:postgres@localhost/postgres
3 changes: 1 addition & 2 deletions .github/workflows/deploy.yml
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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
forms/
*target/
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
gem "sinatra"
gem "pry"
gem "thin"
gem "pg"
gem "sequel"
gem "dotenv"
gem "jwt"
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ GEM
specs:
coderay (1.1.3)
daemons (1.4.1)
dotenv (2.7.6)
eventmachine (1.2.7)
jwt (2.3.0)
method_source (1.0.0)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
pg (1.2.3)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
rack (2.2.3)
rack-protection (2.1.0)
rack
ruby2_keywords (0.0.5)
sequel (5.52.0)
sinatra (2.1.0)
mustermann (~> 1.0)
rack (~> 2.2)
Expand All @@ -29,7 +33,11 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
dotenv
jwt
pg
pry
sequel
sinatra
thin

Expand Down
4 changes: 4 additions & 0 deletions README.md
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`
5 changes: 5 additions & 0 deletions config.ru
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
40 changes: 40 additions & 0 deletions db/database.rb
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
11 changes: 11 additions & 0 deletions db/migrations/1_add_forms_table.rb
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
Loading