forked from semgrep/semgrep
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
osemgrep: skeleton for the login/logout/ci subcommands (semgrep#6389)
test plan: make test make osemgrep-e2e => 65 tests are passing.
- Loading branch information
Showing
13 changed files
with
323 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,21 @@ | ||
(*****************************************************************************) | ||
(* Prelude *) | ||
(*****************************************************************************) | ||
(* | ||
'semgrep ci' subcommand | ||
Translated from ci.py | ||
*) | ||
|
||
(*****************************************************************************) | ||
(* Types and constants *) | ||
(*****************************************************************************) | ||
|
||
type conf = Scan_CLI.conf | ||
|
||
(*****************************************************************************) | ||
(* Entry point *) | ||
(*****************************************************************************) | ||
|
||
let parse_argv (argv : string array) : (conf, Exit_code.t) result = | ||
Scan_CLI.parse_argv argv |
This file contains 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,19 @@ | ||
(* | ||
'semgrep ci' command-line parsing. | ||
*) | ||
|
||
(* | ||
The result of parsing a 'semgrep ci' command. | ||
*) | ||
|
||
type conf = Scan_CLI.conf | ||
|
||
(* | ||
Usage: parse_argv [| "semgrep-ci"; <args> |] | ||
This function returns an exit code to be passed to the 'exit' function | ||
if there was an error parsing argv (Exit_code.fatal) or when | ||
using semgrep ci --help (Exit_code.ok), and the conf otherwise if everything | ||
went fine. | ||
*) | ||
val parse_argv : string array -> (conf, Exit_code.t) result |
This file contains 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,42 @@ | ||
let _logger = Logging.get_logger [ __MODULE__ ] | ||
|
||
(*****************************************************************************) | ||
(* Prelude *) | ||
(*****************************************************************************) | ||
(* | ||
Parse a semgrep-ci command, execute it and exit. | ||
Translated from ci.py | ||
*) | ||
|
||
(*****************************************************************************) | ||
(* Types *) | ||
(*****************************************************************************) | ||
|
||
(*****************************************************************************) | ||
(* Helpers *) | ||
(*****************************************************************************) | ||
|
||
(*****************************************************************************) | ||
(* Main logic *) | ||
(*****************************************************************************) | ||
|
||
(* All the business logic after command-line parsing. Return the desired | ||
exit code. *) | ||
let run (_conf : Ci_CLI.conf) : Exit_code.t = | ||
(* TODO: | ||
Setup_logging.setup config; | ||
logger#info "Executed as: %s" (Sys.argv |> Array.to_list |> String.concat " "); | ||
logger#info "Version: %s" config.version; | ||
*) | ||
Exit_code.ok | ||
|
||
(*****************************************************************************) | ||
(* Entry point *) | ||
(*****************************************************************************) | ||
|
||
let main (argv : string array) : Exit_code.t = | ||
let res = Ci_CLI.parse_argv argv in | ||
match res with | ||
| Ok conf -> CLI_common.safe_run run conf | ||
| Error exit_code -> exit_code |
This file contains 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,12 @@ | ||
(* | ||
Parse a semgrep-ci command, execute it and exit. | ||
Usage: main [| "semgrep-ci"; ... |] | ||
This function returns an exit code to be passed to the 'exit' function. | ||
Exceptions are caught and turned into an appropriate exit code. | ||
*) | ||
val main : string array -> Exit_code.t | ||
|
||
(* internal *) | ||
val run : Ci_CLI.conf -> Exit_code.t |
This file contains 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,22 @@ | ||
; OCaml implementation of the 'semgrep ci' subcommand. | ||
; | ||
(library | ||
(name osemgrep_cli_ci) | ||
(wrapped false) | ||
(libraries | ||
cmdliner | ||
|
||
osemgrep_core | ||
osemgrep_utils | ||
osemgrep_networking | ||
osemgrep_cli_scan ; reusing the same flags and most of the code | ||
) | ||
(preprocess | ||
(pps | ||
ppx_profiling | ||
ppx_deriving.show | ||
ppx_deriving.eq | ||
ppx_hash | ||
) | ||
) | ||
) |
This file contains 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,78 @@ | ||
open Cmdliner | ||
|
||
let _logger = Logging.get_logger [ __MODULE__ ] | ||
|
||
(*****************************************************************************) | ||
(* Prelude *) | ||
(*****************************************************************************) | ||
(* | ||
Parse a semgrep-login command, execute it and exit. | ||
Translated from login.py | ||
*) | ||
|
||
(*****************************************************************************) | ||
(* Types *) | ||
(*****************************************************************************) | ||
(* no CLI parameters for now *) | ||
type login_cli_conf = unit | ||
type conf = login_cli_conf | ||
|
||
(*****************************************************************************) | ||
(* Helpers *) | ||
(*****************************************************************************) | ||
|
||
(* this could be moved in a Login_CLI.ml file at some point *) | ||
let cmdline_term : conf Term.t = | ||
let combine = () in | ||
Term.(const combine) | ||
|
||
let doc = "Obtain and save credentials for semgrep.dev" | ||
|
||
let man : Manpage.block list = | ||
[ | ||
`S Manpage.s_description; | ||
`P | ||
"Obtain and save credentials for semgrep.dev\n\n\ | ||
\ Looks for an semgrep.dev API token in the environment variable \ | ||
SEMGREP_API_TOKEN_SETTINGS_KEY.\n\ | ||
\ If not defined and running in a TTY, prompts interactively.\n\ | ||
\ Once token is found, saves it to global settings file"; | ||
] | ||
@ CLI_common.help_page_bottom | ||
|
||
let parse_argv (argv : string array) : (conf, Exit_code.t) result = | ||
let info : Cmd.info = Cmd.info "semgrep login" ~doc ~man in | ||
let cmd : conf Cmd.t = Cmd.v info cmdline_term in | ||
match Cmd.eval_value ~argv cmd with | ||
| Error _n -> Error Exit_code.fatal | ||
| Ok ok -> ( | ||
match ok with | ||
| `Ok config -> Ok config | ||
| `Version | ||
| `Help -> | ||
Error Exit_code.ok) | ||
|
||
(*****************************************************************************) | ||
(* Main logic *) | ||
(*****************************************************************************) | ||
|
||
(* All the business logic after command-line parsing. Return the desired | ||
exit code. *) | ||
let run (_conf : login_cli_conf) : Exit_code.t = | ||
(* TODO: | ||
Setup_logging.setup config; | ||
logger#info "Executed as: %s" (Sys.argv |> Array.to_list |> String.concat " "); | ||
logger#info "Version: %s" config.version; | ||
*) | ||
Exit_code.ok | ||
|
||
(*****************************************************************************) | ||
(* Entry point *) | ||
(*****************************************************************************) | ||
|
||
let main (argv : string array) : Exit_code.t = | ||
let res = parse_argv argv in | ||
match res with | ||
| Ok conf -> CLI_common.safe_run run conf | ||
| Error exit_code -> exit_code |
This file contains 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,15 @@ | ||
(* no parameters for now *) | ||
type login_cli_conf = unit | ||
|
||
(* | ||
Parse a semgrep-login command, execute it and exit. | ||
Usage: main [| "semgrep-login"; ... |] | ||
This function returns an exit code to be passed to the 'exit' function. | ||
Exceptions are caught and turned into an appropriate exit code. | ||
*) | ||
val main : string array -> Exit_code.t | ||
|
||
(* internal *) | ||
val run : login_cli_conf -> Exit_code.t |
This file contains 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,73 @@ | ||
open Cmdliner | ||
|
||
let _logger = Logging.get_logger [ __MODULE__ ] | ||
|
||
(*****************************************************************************) | ||
(* Prelude *) | ||
(*****************************************************************************) | ||
(* | ||
Parse a semgrep-logout command, execute it and exit. | ||
Translated from login.py | ||
*) | ||
|
||
(*****************************************************************************) | ||
(* Types *) | ||
(*****************************************************************************) | ||
(* no CLI parameters for now *) | ||
type logout_cli_conf = unit | ||
type conf = logout_cli_conf | ||
|
||
(*****************************************************************************) | ||
(* Helpers *) | ||
(*****************************************************************************) | ||
|
||
(* this could be moved in a Login_CLI.ml file at some point *) | ||
let cmdline_term : conf Term.t = | ||
let combine = () in | ||
Term.(const combine) | ||
|
||
let doc = "Remove locally stored credentials to semgrep.dev" | ||
|
||
let man : Manpage.block list = | ||
[ | ||
`S Manpage.s_description; | ||
`P "Remove locally stored credentials to semgrep.dev"; | ||
] | ||
@ CLI_common.help_page_bottom | ||
|
||
let parse_argv (argv : string array) : (conf, Exit_code.t) result = | ||
let info : Cmd.info = Cmd.info "semgrep logout" ~doc ~man in | ||
let cmd : conf Cmd.t = Cmd.v info cmdline_term in | ||
match Cmd.eval_value ~argv cmd with | ||
| Error _n -> Error Exit_code.fatal | ||
| Ok ok -> ( | ||
match ok with | ||
| `Ok config -> Ok config | ||
| `Version | ||
| `Help -> | ||
Error Exit_code.ok) | ||
|
||
(*****************************************************************************) | ||
(* Main logic *) | ||
(*****************************************************************************) | ||
|
||
(* All the business logic after command-line parsing. Return the desired | ||
exit code. *) | ||
let run (_conf : logout_cli_conf) : Exit_code.t = | ||
(* TODO: | ||
Setup_logging.setup config; | ||
logger#info "Executed as: %s" (Sys.argv |> Array.to_list |> String.concat " "); | ||
logger#info "Version: %s" config.version; | ||
*) | ||
Exit_code.ok | ||
|
||
(*****************************************************************************) | ||
(* Entry point *) | ||
(*****************************************************************************) | ||
|
||
let main (argv : string array) : Exit_code.t = | ||
let res = parse_argv argv in | ||
match res with | ||
| Ok conf -> CLI_common.safe_run run conf | ||
| Error exit_code -> exit_code |
This file contains 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,15 @@ | ||
(* no parameters for now *) | ||
type logout_cli_conf = unit | ||
|
||
(* | ||
Parse a semgrep-logout command, execute it and exit. | ||
Usage: main [| "semgrep-logut"; ... |] | ||
This function returns an exit code to be passed to the 'exit' function. | ||
Exceptions are caught and turned into an appropriate exit code. | ||
*) | ||
val main : string array -> Exit_code.t | ||
|
||
(* internal *) | ||
val run : logout_cli_conf -> Exit_code.t |
This file contains 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,21 @@ | ||
; OCaml implementation of the 'semgrep login' and 'semgrep logout' subcommands. | ||
; | ||
(library | ||
(name osemgrep_cli_login) | ||
(wrapped false) | ||
(libraries | ||
cmdliner | ||
|
||
osemgrep_core | ||
osemgrep_utils | ||
osemgrep_networking | ||
) | ||
(preprocess | ||
(pps | ||
ppx_profiling | ||
ppx_deriving.show | ||
ppx_deriving.eq | ||
ppx_hash | ||
) | ||
) | ||
) |