Add builder-db access-list command
This commit is contained in:
parent
16748b8995
commit
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"]] ())
|
||||
in
|
||||
Db.iter_s Builder_db.User.get_all
|
||||
(fun username -> Ok (print_endline username))
|
||||
(fun (_id, username) -> Ok (print_endline username))
|
||||
()
|
||||
in
|
||||
or_die 1 r
|
||||
|
@ -136,6 +136,17 @@ let access_remove () dbpath username jobname =
|
|||
in
|
||||
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 dbpath = datadir ^ "/builder.sqlite3" in
|
||||
let r =
|
||||
|
@ -432,6 +443,11 @@ let access_remove_cmd =
|
|||
(Cmdliner.Term.(pure access_remove $ setup_log $ dbpath $ username $ job),
|
||||
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 doc = "remove job and its associated builds and artifacts" in
|
||||
(Cmdliner.Term.(pure job_remove $ setup_log $ datadir $ jobname),
|
||||
|
@ -467,6 +483,6 @@ let () =
|
|||
default_cmd
|
||||
[help_cmd; migrate_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 ]
|
||||
|> Cmdliner.Term.exit
|
||||
|
|
|
@ -588,8 +588,8 @@ module User = struct
|
|||
let get_all =
|
||||
Caqti_request.collect
|
||||
Caqti_type.unit
|
||||
Caqti_type.string
|
||||
"SELECT username FROM user"
|
||||
Caqti_type.(tup2 (id `user) string)
|
||||
"SELECT id, username FROM user"
|
||||
|
||||
let add =
|
||||
Caqti_request.exec
|
||||
|
@ -644,6 +644,12 @@ module Access_list = struct
|
|||
(id `access_list)
|
||||
"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 =
|
||||
Caqti_request.exec
|
||||
Caqti_type.(tup2 (id `user) (id `job))
|
||||
|
|
|
@ -163,7 +163,7 @@ module User : sig
|
|||
[< `Many | `One | `Zero > `One `Zero ])
|
||||
Caqti_request.t
|
||||
val get_all :
|
||||
(unit, string, [ `Many | `One | `Zero ]) Caqti_request.t
|
||||
(unit, [`user] id * string, [ `Many | `One | `Zero ]) Caqti_request.t
|
||||
val add :
|
||||
(Builder_web_auth.scrypt Builder_web_auth.user_info, unit, [< `Many | `One | `Zero > `Zero ])
|
||||
Caqti_request.t
|
||||
|
@ -177,6 +177,8 @@ end
|
|||
module Access_list : sig
|
||||
val get :
|
||||
([`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 :
|
||||
([`user] id * [`job] id, unit, [< `Many | `One | `Zero > `Zero ]) Caqti_request.t
|
||||
val remove :
|
||||
|
|
Loading…
Reference in a new issue