Compare commits
1 commit
main
...
access-lis
Author | SHA1 | Date | |
---|---|---|---|
3a7e58abca |
3 changed files with 29 additions and 5 deletions
|
@ -71,7 +71,7 @@ let user_list () dbpath =
|
||||||
connect (Uri.make ~scheme:"sqlite3" ~path:dbpath ~query:["create", ["false"]] ())
|
connect (Uri.make ~scheme:"sqlite3" ~path:dbpath ~query:["create", ["false"]] ())
|
||||||
in
|
in
|
||||||
Db.iter_s Builder_db.User.get_all
|
Db.iter_s Builder_db.User.get_all
|
||||||
(fun username -> Ok (print_endline username))
|
(fun (_id, username) -> Ok (print_endline username))
|
||||||
()
|
()
|
||||||
in
|
in
|
||||||
or_die 1 r
|
or_die 1 r
|
||||||
|
@ -136,6 +136,17 @@ let access_remove () dbpath username jobname =
|
||||||
in
|
in
|
||||||
or_die 1 r
|
or_die 1 r
|
||||||
|
|
||||||
|
let access_list () dbpath =
|
||||||
|
let r =
|
||||||
|
let* (module Db : Caqti_blocking.CONNECTION) =
|
||||||
|
connect (Uri.make ~scheme:"sqlite3" ~path:dbpath ~query:["create", ["false"]] ())
|
||||||
|
in
|
||||||
|
Db.iter_s Builder_db.Access_list.get_all_names
|
||||||
|
(fun (username, job) -> Ok (Printf.printf "%s:%s\n" username job))
|
||||||
|
()
|
||||||
|
in
|
||||||
|
or_die 1 r
|
||||||
|
|
||||||
let job_remove () datadir jobname =
|
let job_remove () datadir jobname =
|
||||||
let dbpath = datadir ^ "/builder.sqlite3" in
|
let dbpath = datadir ^ "/builder.sqlite3" in
|
||||||
let r =
|
let r =
|
||||||
|
@ -432,6 +443,11 @@ let access_remove_cmd =
|
||||||
(Cmdliner.Term.(pure access_remove $ setup_log $ dbpath $ username $ job),
|
(Cmdliner.Term.(pure access_remove $ setup_log $ dbpath $ username $ job),
|
||||||
Cmdliner.Term.info ~doc "access-remove")
|
Cmdliner.Term.info ~doc "access-remove")
|
||||||
|
|
||||||
|
let access_list_cmd =
|
||||||
|
let doc = "list user access" in
|
||||||
|
(Cmdliner.Term.(pure access_list $ setup_log $ dbpath),
|
||||||
|
Cmdliner.Term.info ~doc "access-list")
|
||||||
|
|
||||||
let job_remove_cmd =
|
let job_remove_cmd =
|
||||||
let doc = "remove job and its associated builds and artifacts" in
|
let doc = "remove job and its associated builds and artifacts" in
|
||||||
(Cmdliner.Term.(pure job_remove $ setup_log $ datadir $ jobname),
|
(Cmdliner.Term.(pure job_remove $ setup_log $ datadir $ jobname),
|
||||||
|
@ -467,6 +483,6 @@ let () =
|
||||||
default_cmd
|
default_cmd
|
||||||
[help_cmd; migrate_cmd;
|
[help_cmd; migrate_cmd;
|
||||||
user_add_cmd; user_update_cmd; user_remove_cmd; user_list_cmd; user_disable_cmd;
|
user_add_cmd; user_update_cmd; user_remove_cmd; user_list_cmd; user_disable_cmd;
|
||||||
access_add_cmd; access_remove_cmd; job_remove_cmd;
|
access_add_cmd; access_remove_cmd; access_list_cmd; job_remove_cmd;
|
||||||
verify_input_id_cmd; verify_data_dir_cmd ]
|
verify_input_id_cmd; verify_data_dir_cmd ]
|
||||||
|> Cmdliner.Term.exit
|
|> Cmdliner.Term.exit
|
||||||
|
|
|
@ -588,8 +588,8 @@ module User = struct
|
||||||
let get_all =
|
let get_all =
|
||||||
Caqti_request.collect
|
Caqti_request.collect
|
||||||
Caqti_type.unit
|
Caqti_type.unit
|
||||||
Caqti_type.string
|
Caqti_type.(tup2 (id `user) string)
|
||||||
"SELECT username FROM user"
|
"SELECT id, username FROM user"
|
||||||
|
|
||||||
let add =
|
let add =
|
||||||
Caqti_request.exec
|
Caqti_request.exec
|
||||||
|
@ -644,6 +644,12 @@ module Access_list = struct
|
||||||
(id `access_list)
|
(id `access_list)
|
||||||
"SELECT id FROM access_list WHERE user = ? AND job = ?"
|
"SELECT id FROM access_list WHERE user = ? AND job = ?"
|
||||||
|
|
||||||
|
let get_all_names =
|
||||||
|
Caqti_request.collect
|
||||||
|
Caqti_type.unit
|
||||||
|
Caqti_type.(tup2 string string)
|
||||||
|
"SELECT username, name FROM access_list acl LEFT JOIN user, job ON user.id = acl.user AND job.id = acl.job"
|
||||||
|
|
||||||
let add =
|
let add =
|
||||||
Caqti_request.exec
|
Caqti_request.exec
|
||||||
Caqti_type.(tup2 (id `user) (id `job))
|
Caqti_type.(tup2 (id `user) (id `job))
|
||||||
|
|
|
@ -163,7 +163,7 @@ module User : sig
|
||||||
[< `Many | `One | `Zero > `One `Zero ])
|
[< `Many | `One | `Zero > `One `Zero ])
|
||||||
Caqti_request.t
|
Caqti_request.t
|
||||||
val get_all :
|
val get_all :
|
||||||
(unit, string, [ `Many | `One | `Zero ]) Caqti_request.t
|
(unit, [`user] id * string, [ `Many | `One | `Zero ]) Caqti_request.t
|
||||||
val add :
|
val add :
|
||||||
(Builder_web_auth.scrypt Builder_web_auth.user_info, unit, [< `Many | `One | `Zero > `Zero ])
|
(Builder_web_auth.scrypt Builder_web_auth.user_info, unit, [< `Many | `One | `Zero > `Zero ])
|
||||||
Caqti_request.t
|
Caqti_request.t
|
||||||
|
@ -177,6 +177,8 @@ end
|
||||||
module Access_list : sig
|
module Access_list : sig
|
||||||
val get :
|
val get :
|
||||||
([`user] id * [`job] id, [`access_list] id, [< `Many | `One | `Zero > `One ]) Caqti_request.t
|
([`user] id * [`job] id, [`access_list] id, [< `Many | `One | `Zero > `One ]) Caqti_request.t
|
||||||
|
val get_all_names :
|
||||||
|
(unit, string * string, [ `Many | `One | `Zero ]) Caqti_request.t
|
||||||
val add :
|
val add :
|
||||||
([`user] id * [`job] id, unit, [< `Many | `One | `Zero > `Zero ]) Caqti_request.t
|
([`user] id * [`job] id, unit, [< `Many | `One | `Zero > `Zero ]) Caqti_request.t
|
||||||
val remove :
|
val remove :
|
||||||
|
|
Loading…
Reference in a new issue