Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication: Registration #6

Merged
merged 33 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8fa890d
frontend styles and pages for sign up
PizieDust Jul 2, 2024
8786773
robur.coop absolute url
PizieDust Jul 2, 2024
be6291f
load multiple images
PizieDust Jul 3, 2024
2d086e4
add robur image
PizieDust Jul 3, 2024
282cb24
add robur img
PizieDust Jul 3, 2024
71f902a
add favicon
PizieDust Jul 3, 2024
b212fbb
add password enc and uuid
PizieDust Jul 3, 2024
7d56771
favicon for index
PizieDust Jul 3, 2024
62e8c17
add favico and http request
PizieDust Jul 3, 2024
afa94be
api registration endpoint
PizieDust Jul 3, 2024
52bb41c
handle authentication
PizieDust Jul 3, 2024
b85fe1b
update styles
PizieDust Jul 3, 2024
8fe6ec8
update styles, basic client input validation
PizieDust Jul 3, 2024
6f9f9e1
Merge branch 'main' of github.com:robur-coop/mollymawk into pixie_dev
PizieDust Jul 3, 2024
197ab5a
create user records
PizieDust Jul 3, 2024
07b887c
Update user_model.ml
PizieDust Jul 3, 2024
41d1b38
Update user_model.ml
PizieDust Jul 3, 2024
3be8539
Update user_model.ml
PizieDust Jul 3, 2024
8e389ee
Update unikernel.ml
PizieDust Jul 3, 2024
42c6471
Update unikernel.ml
PizieDust Jul 3, 2024
2782599
Update user_model.ml
PizieDust Jul 3, 2024
44b440d
Update user_model.ml
PizieDust Jul 3, 2024
c128018
Update user_model.ml
PizieDust Jul 3, 2024
2df784b
Update user_model.ml
PizieDust Jul 3, 2024
c6aa4ce
Apply suggestions from code review
hannesm Jul 3, 2024
3be1046
backend and frontend validation of user input
PizieDust Jul 3, 2024
1d400c3
tokens as list
PizieDust Jul 3, 2024
f231197
Merge branch 'pixie_dev' of github.com:robur-coop/mollymawk into pixi…
PizieDust Jul 3, 2024
94c8cee
tokens list
PizieDust Jul 3, 2024
68abcdc
Update user_model.ml
PizieDust Jul 3, 2024
56735da
Update user_model.ml
PizieDust Jul 3, 2024
bc896f0
rename to value
PizieDust Jul 3, 2024
760929c
ocaml format
PizieDust Jul 3, 2024
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
251 changes: 152 additions & 99 deletions albatross_json.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,87 @@ let unikernel_info (unikernel_name, info) =
and fail_behaviour = function
| `Quit -> `String "quit"
| `Restart ex ->
let els = Option.value ~default:[] (Option.map Vmm_core.IS.elements ex) in
`Assoc [
("restart", `Null);
("exit_code", `List (List.map (fun e -> `Int e) els));
("all_exit_codes", `Bool (ex = None));
]
let els =
Option.value ~default:[] (Option.map Vmm_core.IS.elements ex)
in
`Assoc
[
("restart", `Null);
("exit_code", `List (List.map (fun e -> `Int e) els));
("all_exit_codes", `Bool (ex = None));
]
and cpuid c = `Int c
and memory m = `Int m
and block_devices bs =
let block (name, dev, sec) =
let dev = Option.value ~default:"none specified (name is used)" dev in
let s = Option.value ~default:(-1) sec in
`Assoc [("name", `String name) ; ("host_device", `String dev); ("sector_size", `Int s)]
`Assoc
[
("name", `String name);
("host_device", `String dev);
("sector_size", `Int s);
]
in
`List (List.map block bs)
and bridges bs =
let bridge (name, dev, mac) =
let dev = Option.value ~default:name dev in
let mac = Option.value ~default:(Vmm_core.Name.mac unikernel_name dev) mac in
`Assoc [("name", `String name) ; ("host_device", `String dev); ("mac", `String (Macaddr.to_string mac)) ]
let mac =
Option.value ~default:(Vmm_core.Name.mac unikernel_name dev) mac
in
`Assoc
[
("name", `String name);
("host_device", `String dev);
("mac", `String (Macaddr.to_string mac));
]
in
`List (List.map bridge bs)
and argv args =
`List (List.map (fun a -> `String a) (Option.value ~default:[] args))
and digest d =
`String (Cstruct.to_hex_string d)
in
`Assoc [
("name", `String (Vmm_core.Name.to_string unikernel_name));
("typ", typ info.Vmm_core.Unikernel.typ);
("fail_behaviour", fail_behaviour info.fail_behaviour);
("cpuid", cpuid info.cpuid);
("memory", memory info.memory);
("block_devices", block_devices info.block_devices);
("network_interfaces", bridges info.bridges);
("arguments", argv info.argv);
("digest", digest info.digest);
]
and digest d = `String (Cstruct.to_hex_string d) in
`Assoc
[
("name", `String (Vmm_core.Name.to_string unikernel_name));
("typ", typ info.Vmm_core.Unikernel.typ);
("fail_behaviour", fail_behaviour info.fail_behaviour);
("cpuid", cpuid info.cpuid);
("memory", memory info.memory);
("block_devices", block_devices info.block_devices);
("network_interfaces", bridges info.bridges);
("arguments", argv info.argv);
("digest", digest info.digest);
]

let unikernel_infos is = `List (List.map unikernel_info is)

let block_info (name, size, used) =
`Assoc [
("name", `String (Vmm_core.Name.to_string name));
("size", `Int size);
("used", `Bool used);
]
`Assoc
[
("name", `String (Vmm_core.Name.to_string name));
("size", `Int size);
("used", `Bool used);
]

let block_infos bs = `List (List.map block_info bs)

let policy_info (name, policy) =
`Assoc [
("name", `String (Vmm_core.Name.to_string name));
("allowed_vms", `Int policy.Vmm_core.Policy.vms);
("allowed_cpuids", `List (List.map (fun id -> `Int id) (Vmm_core.IS.elements policy.cpuids)));
("allowed_memory", `Int policy.memory);
("allowed_block_size", `Int (Option.value ~default:0 policy.block));
("allowed_bridges", `List (List.map (fun b -> `String b) (Vmm_core.String_set.elements policy.bridges)))
]
`Assoc
[
("name", `String (Vmm_core.Name.to_string name));
("allowed_vms", `Int policy.Vmm_core.Policy.vms);
( "allowed_cpuids",
`List
(List.map (fun id -> `Int id) (Vmm_core.IS.elements policy.cpuids)) );
("allowed_memory", `Int policy.memory);
("allowed_block_size", `Int (Option.value ~default:0 policy.block));
( "allowed_bridges",
`List
(List.map
(fun b -> `String b)
(Vmm_core.String_set.elements policy.bridges)) );
]

let policy_infos ps = `List (List.map policy_info ps)

Expand All @@ -77,7 +99,8 @@ let success = function
| `Block_device_image _ -> `String "block device image not supported"

let console_data_to_json (ts, data) =
`Assoc [ ("timestamp", `String (Ptime.to_rfc3339 ts)) ; ("line", `String data) ]
`Assoc
[ ("timestamp", `String (Ptime.to_rfc3339 ts)); ("line", `String data) ]

let res = function
| `Command _ -> `String "command not supported"
Expand All @@ -96,107 +119,137 @@ let fail_behaviour_of_json js =
let ( let* ) = Result.bind in
match js with
| `String "quit" -> Ok `Quit
| `Assoc rs ->
(match
get "restart" rs, get "exit_code" rs, get "all_exit_codes" rs
with
| None, _, _ -> Error (`Msg "expected a restart")
| Some _, Some `List codes, _ ->
let* codes =
try Ok (List.map (function `Int n -> n | _ -> failwith "not an integer") codes) with
Failure s -> Error (`Msg ("expected integer values as exit codes, error: " ^ s))
in
Ok (`Restart (Some (Vmm_core.IS.of_list codes)))
| Some _, Some _, _ -> Error (`Msg "expected a list of integers as exit_code payload")
| Some _, _, _ -> Ok (`Restart None))
| `Assoc rs -> (
match (get "restart" rs, get "exit_code" rs, get "all_exit_codes" rs) with
| None, _, _ -> Error (`Msg "expected a restart")
| Some _, Some (`List codes), _ ->
let* codes =
try
Ok
(List.map
(function `Int n -> n | _ -> failwith "not an integer")
codes)
with Failure s ->
Error
(`Msg ("expected integer values as exit codes, error: " ^ s))
in
Ok (`Restart (Some (Vmm_core.IS.of_list codes)))
| Some _, Some _, _ ->
Error (`Msg "expected a list of integers as exit_code payload")
| Some _, _, _ -> Ok (`Restart None))
| _ -> Error (`Msg "fail behaviour must be quit or restart")

let bridge_of_json (js : Yojson.Basic.t) =
(* we support [ "foo" ] as well as [ { name: "foo" ; host_device: "myfoo" ; mac: "aa:bb:cc:dd:ee:ff" *)
let ( let* ) = Result.bind in
match js with
| `String bridge -> Ok (bridge, None, None)
| `Assoc xs ->
(match get "name" xs, get "host_device" xs, get "mac" xs with
| None, _, _ -> Error (`Msg "name must be present in the json")
| Some `String name, None, None -> Ok (name, None, None)
| Some `String name, Some `String host, None -> Ok (name, Some host, None)
| Some `String name, None, Some `String mac ->
let* mac = Macaddr.of_string mac in
Ok (name, None, Some mac)
| Some `String name, Some `String host, Some `String mac ->
let* mac = Macaddr.of_string mac in
Ok (name, Some host, Some mac)
| _, _, _ -> Error (`Msg "couldn't decode json"))
| `Assoc xs -> (
match (get "name" xs, get "host_device" xs, get "mac" xs) with
| None, _, _ -> Error (`Msg "name must be present in the json")
| Some (`String name), None, None -> Ok (name, None, None)
| Some (`String name), Some (`String host), None ->
Ok (name, Some host, None)
| Some (`String name), None, Some (`String mac) ->
let* mac = Macaddr.of_string mac in
Ok (name, None, Some mac)
| Some (`String name), Some (`String host), Some (`String mac) ->
let* mac = Macaddr.of_string mac in
Ok (name, Some host, Some mac)
| _, _, _ -> Error (`Msg "couldn't decode json"))
| _ -> Error (`Msg "bad json, either string or assoc")

let block_device_of_json js =
(* we support [ "foo" ] as well as [ { name: "foo" ; host_device: "myfoo" ; sector_size: 20 *)
match js with
| `String name -> Ok (name, None, None)
| `Assoc xs ->
(match get "name" xs, get "host_device" xs, get "sector_size" xs with
| None, _, _ -> Error (`Msg "name must be present in the json")
| Some `String name, None, None -> Ok (name, None, None)
| Some `String name, Some `String host, None -> Ok (name, Some host, None)
| Some `String name, None, Some `Int sector_size -> Ok (name, None, Some sector_size)
| Some `String name, Some `String host, Some `Int sector_size -> Ok (name, Some host, Some sector_size)
| _, _, _ -> Error (`Msg "couldn't decode json"))
| `Assoc xs -> (
match (get "name" xs, get "host_device" xs, get "sector_size" xs) with
| None, _, _ -> Error (`Msg "name must be present in the json")
| Some (`String name), None, None -> Ok (name, None, None)
| Some (`String name), Some (`String host), None ->
Ok (name, Some host, None)
| Some (`String name), None, Some (`Int sector_size) ->
Ok (name, None, Some sector_size)
| Some (`String name), Some (`String host), Some (`Int sector_size) ->
Ok (name, Some host, Some sector_size)
| _, _, _ -> Error (`Msg "couldn't decode json"))
| _ -> Error (`Msg "bad json, either string or assoc")

let config_of_json str =
let ( let* ) = Result.bind in
let* json = try Ok (Yojson.Basic.from_string str) with Yojson.Json_error s -> Error (`Msg s) in
let* dict = match json with `Assoc r -> Ok r | _ -> Error (`Msg "not a json assoc") in
let* json =
try Ok (Yojson.Basic.from_string str)
with Yojson.Json_error s -> Error (`Msg s)
in
let* dict =
match json with `Assoc r -> Ok r | _ -> Error (`Msg "not a json assoc")
in
let* fail_behaviour =
Option.fold ~none:(Ok `Quit)
~some:fail_behaviour_of_json (get "fail_behaviour" dict)
Option.fold ~none:(Ok `Quit) ~some:fail_behaviour_of_json
(get "fail_behaviour" dict)
in
let* cpuid =
Option.fold ~none:(Ok 0)
~some:(function `Int n -> Ok n | _ -> Error (`Msg "cpuid must be an integer"))
~some:(function
| `Int n -> Ok n | _ -> Error (`Msg "cpuid must be an integer"))
(get "cpuid" dict)
in
let* memory =
Option.fold ~none:(Ok 32)
~some:(function `Int n -> Ok n | _ -> Error (`Msg "memory must be an integer"))
~some:(function
| `Int n -> Ok n | _ -> Error (`Msg "memory must be an integer"))
(get "memory" dict)
in
let* bridges =
match get "network_interfaces" dict with
| None -> Ok []
| Some `List bs ->
List.fold_left (fun r x ->
let* r = r in
let* b = bridge_of_json x in
Ok (b :: r))
(Ok []) bs
| Some (`List bs) ->
List.fold_left
(fun r x ->
let* r = r in
let* b = bridge_of_json x in
Ok (b :: r))
(Ok []) bs
| Some _ -> Error (`Msg "expected a list of network devices")
in
let* block_devices =
match get "block_devices" dict with
| None -> Ok []
| Some `List bs ->
List.fold_left (fun r x ->
let* r = r in
let* b = block_device_of_json x in
Ok (b :: r))
(Ok []) bs
| Some (`List bs) ->
List.fold_left
(fun r x ->
let* r = r in
let* b = block_device_of_json x in
Ok (b :: r))
(Ok []) bs
| Some _ -> Error (`Msg "expected a list of block devices")
in
let* argv =
try
Option.fold ~none:(Ok None)
~some:(function
| `List bs ->
Ok (Some (List.map (function
| `String n -> n
| _ -> failwith "argument is not a string") bs))
| _ -> Error (`Msg "arguments must be a list of strings"))
(get "arguments" dict)
with
Failure s -> Error (`Msg ("expected strings as argv, error: " ^ s))
| `List bs ->
Ok
(Some
(List.map
(function
| `String n -> n
| _ -> failwith "argument is not a string")
bs))
| _ -> Error (`Msg "arguments must be a list of strings"))
(get "arguments" dict)
with Failure s -> Error (`Msg ("expected strings as argv, error: " ^ s))
in
Ok { Vmm_core.Unikernel.typ = `Solo5 ; compressed = false ;
image = Cstruct.empty ; fail_behaviour ; cpuid ;
memory ; block_devices ; bridges ; argv }
Ok
{
Vmm_core.Unikernel.typ = `Solo5;
compressed = false;
image = Cstruct.empty;
fail_behaviour;
cpuid;
memory;
block_devices;
bridges;
argv;
}
Binary file added assets/molly_bird.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/robur.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading