From 4960576cde7b0261d133aea12baba2586e1a578d Mon Sep 17 00:00:00 2001 From: jerlendds Date: Sun, 5 Nov 2023 06:02:36 -0700 Subject: [PATCH] Rework launcher source syntax .gitmodules, .gitignore, osintbuddy-plugins, api.ts, launcher, _colors, api:gen, bootstrap, build, cleanup, debug:send, downkill, env, logs, migrate, pkg:update, ps, python, restart, setup:dev, shell, start, stop, and ui_dev --- .gitmodules | 3 ++ frontend/src/app/api.ts | 94 ++++++++++++++++++++--------------------- launcher | 42 +++++++++--------- ob/cmd/_colors | 2 +- ob/cmd/api:gen | 2 +- ob/cmd/bootstrap | 6 +-- ob/cmd/build | 2 +- ob/cmd/cleanup | 2 +- ob/cmd/debug:send | 2 +- ob/cmd/downkill | 4 +- ob/cmd/env | 2 +- ob/cmd/logs | 2 +- ob/cmd/migrate | 2 +- ob/cmd/pkg:update | 2 +- ob/cmd/ps | 2 +- ob/cmd/python | 2 +- ob/cmd/restart | 2 +- ob/cmd/setup:dev | 2 +- ob/cmd/shell | 2 +- ob/cmd/start | 3 +- ob/cmd/stop | 2 +- ob/cmd/ui_dev | 4 +- 22 files changed, 95 insertions(+), 91 deletions(-) create mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..6e7ae34 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "backend/osintbuddy-plugins"] + path = backend/osintbuddy-plugins + url = git@github.com:jerlendds/osintbuddy-plugins.git diff --git a/frontend/src/app/api.ts b/frontend/src/app/api.ts index c6e1dde..f95599d 100644 --- a/frontend/src/app/api.ts +++ b/frontend/src/app/api.ts @@ -1,6 +1,26 @@ import { emptyApi as api } from "./baseApi"; const injectedRtkApi = api.injectEndpoints({ endpoints: (build) => ({ + refreshPlugins: build.query< + RefreshPluginsApiResponse, + RefreshPluginsApiArg + >({ + query: (queryArg) => ({ + url: `/api/v1/node/refresh`, + params: { hid: queryArg.hid }, + }), + }), + createGraphEntity: build.mutation< + CreateGraphEntityApiResponse, + CreateGraphEntityApiArg + >({ + query: (queryArg) => ({ + url: `/api/v1/node/`, + method: "POST", + body: queryArg.createNode, + params: { hid: queryArg.hid }, + }), + }), getCasdoorConfig: build.query< GetCasdoorConfigApiResponse, GetCasdoorConfigApiArg @@ -123,26 +143,6 @@ const injectedRtkApi = api.injectEndpoints({ method: "PUT", }), }), - refreshPlugins: build.query< - RefreshPluginsApiResponse, - RefreshPluginsApiArg - >({ - query: (queryArg) => ({ - url: `/api/v1/node/refresh`, - params: { hid: queryArg.hid }, - }), - }), - createGraphEntity: build.mutation< - CreateGraphEntityApiResponse, - CreateGraphEntityApiArg - >({ - query: (queryArg) => ({ - url: `/api/v1/node/`, - method: "POST", - body: queryArg.createNode, - params: { hid: queryArg.hid }, - }), - }), createScanMachine: build.mutation< CreateScanMachineApiResponse, CreateScanMachineApiArg @@ -176,6 +176,17 @@ const injectedRtkApi = api.injectEndpoints({ overrideExisting: false, }); export { injectedRtkApi as api }; +export type RefreshPluginsApiResponse = + /** status 200 Successful Response */ any; +export type RefreshPluginsApiArg = { + hid: string; +}; +export type CreateGraphEntityApiResponse = + /** status 200 Successful Response */ any; +export type CreateGraphEntityApiArg = { + hid: string; + createNode: CreateNode; +}; export type GetCasdoorConfigApiResponse = /** status 200 Successful Response */ any; export type GetCasdoorConfigApiArg = void; @@ -264,17 +275,6 @@ export type UpdateEntityFavoriteIdApiResponse = export type UpdateEntityFavoriteIdApiArg = { hid: string; }; -export type RefreshPluginsApiResponse = - /** status 200 Successful Response */ any; -export type RefreshPluginsApiArg = { - hid: string; -}; -export type CreateGraphEntityApiResponse = - /** status 200 Successful Response */ any; -export type CreateGraphEntityApiArg = { - hid: string; - createNode: CreateNode; -}; export type CreateScanMachineApiResponse = /** status 200 Successful Response */ any; export type CreateScanMachineApiArg = { @@ -291,12 +291,6 @@ export type DeleteScanProjectApiResponse = export type DeleteScanProjectApiArg = { sid: number; }; -export type Status = { - status: string; -}; -export type HttpError = { - detail: string; -}; export type ValidationError = { loc: (string | number)[]; msg: string; @@ -305,6 +299,20 @@ export type ValidationError = { export type HttpValidationError = { detail?: ValidationError[]; }; +export type XyPosition = { + x: number; + y: number; +}; +export type CreateNode = { + label: string; + position: XyPosition; +}; +export type Status = { + status: string; +}; +export type HttpError = { + detail: string; +}; export type User = { name: string; username?: string | null; @@ -372,19 +380,13 @@ export type EntityBase = { source?: string; is_favorite?: boolean; }; -export type XyPosition = { - x: number; - y: number; -}; -export type CreateNode = { - label: string; - position: XyPosition; -}; export type ScanMachineCreate = { name: string; description: string; }; export const { + useRefreshPluginsQuery, + useCreateGraphEntityMutation, useGetCasdoorConfigQuery, usePostSigninMutation, usePostSignoutMutation, @@ -403,8 +405,6 @@ export const { useUpdateEntityByIdMutation, useDeleteEntityMutation, useUpdateEntityFavoriteIdMutation, - useRefreshPluginsQuery, - useCreateGraphEntityMutation, useCreateScanMachineMutation, useGetScanMachinesQuery, useDeleteScanProjectMutation, diff --git a/launcher b/launcher index be24627..fc1724e 100755 --- a/launcher +++ b/launcher @@ -9,7 +9,7 @@ export OB_DIR="$(pwd)/ob" if [ -f ./ob/cmd/env ]; then cd $OB_DIR - source cmd/env; + . ./cmd/env; else echo "Error! Please run the ./launcher only from the root osintbuddy directory." exit 1 @@ -67,61 +67,61 @@ fi case "$OB_CMD" in bootstrap) - cmd/bootstrap + ./cmd/bootstrap ;; start) - cmd/start + ./cmd/start ;; restart) - cmd/restart + ./cmd/restart ;; stop) - cmd/stop + ./cmd/stop ;; build) - cmd/build + ./cmd/build ;; logs) - cmd/logs + ./cmd/logs ;; api:gen) - cmd/api:gen + ./cmd/api:gen ;; kill) - cmd/downkill + ./cmd/downkill ;; ui) - cmd/ui_dev + ./cmd/ui_dev ;; debug:send) - cmd/debug:send + ./cmd/debug:send ;; cleanup) - cmd/stop - cmd/cleanup + ./cmd/stop + ./cmd/cleanup ;; exec) - cmd/shell + ./cmd/shell ;; python) - cmd/python + ./cmd/python ;; migrate) - cmd/migrate + ./cmd/migrate ;; setup:dev) - cmd/setup:dev + ./cmd/setup:dev ;; pkg:update) - cmd/pkg:update + ./cmd/pkg:update ;; ps) - cmd/ps + ./cmd/ps ;; containers) - usage_containers + ./usage_containers ;; show) - print_access_urls + ./print_access_urls ;; esac diff --git a/ob/cmd/_colors b/ob/cmd/_colors index acaca28..f0215f4 100755 --- a/ob/cmd/_colors +++ b/ob/cmd/_colors @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh # https://github.com/ppo/bash-colors (v0.3.0) c() { [ $# == 0 ] && printf "\e[0m" || printf "$1" | sed 's/\(.\)/\1;/g;s/\([SDIUFNHT]\)/2\1/g;s/\([KRGYBMCW]\)/3\1/g;s/\([krgybmcw]\)/4\1/g;y/SDIUFNHTsdiufnhtKRGYBMCWkrgybmcw/12345789123457890123456701234567/;s/^\(.*\);$/\\e[\1m/g'; } diff --git a/ob/cmd/api:gen b/ob/cmd/api:gen index 709d47f..de14860 100755 --- a/ob/cmd/api:gen +++ b/ob/cmd/api:gen @@ -1,5 +1,5 @@ #!/usr/bin/env sh -. cmd/env +. ./cmd/env run_api_gen () { heading "Generating client SDK..." diff --git a/ob/cmd/bootstrap b/ob/cmd/bootstrap index e77390e..fe78538 100755 --- a/ob/cmd/bootstrap +++ b/ob/cmd/bootstrap @@ -1,5 +1,5 @@ #!/usr/bin/env sh -. cmd/env +. ./cmd/env # From https://stackoverflow.com/a/44660519/702738 compare_version() { @@ -195,12 +195,12 @@ setup_python_env() { else cd .. python3 -m venv venv && \ - . venv/bin/activate && \ + . ./venv/bin/activate && \ pip install --upgrade pip && \ pip install -r backend/requirements.txt && \ pip install backend/osintbuddy-plugins fi - info "Activate virtual environment: . venv/bin/activate" + info "Activate virtual environment: . ./venv/bin/activate" cd "$OB_DIR" } diff --git a/ob/cmd/build b/ob/cmd/build index ec84e18..19eb354 100755 --- a/ob/cmd/build +++ b/ob/cmd/build @@ -1,5 +1,5 @@ #!/usr/bin/env sh -. cmd/env +. ./cmd/env run_build() { if [ ! -z "$OB_CMD" ] & [ ! -z "$OB_CMD_ARGS" ]; then diff --git a/ob/cmd/cleanup b/ob/cmd/cleanup index 3543633..808c7e5 100755 --- a/ob/cmd/cleanup +++ b/ob/cmd/cleanup @@ -1,6 +1,6 @@ #!/usr/bin/env sh -. cmd/env +. ./cmd/env run_cleanup() { heading "Stopping containers and removing volumes" diff --git a/ob/cmd/debug:send b/ob/cmd/debug:send index 995e527..22a0bea 100755 --- a/ob/cmd/debug:send +++ b/ob/cmd/debug:send @@ -1,5 +1,5 @@ #!/usr/bin/env sh -. cmd/env +. ./cmd/env pastebin() { ob_compose logs > osintbuddy-debug.log diff --git a/ob/cmd/downkill b/ob/cmd/downkill index 159bfab..f1c190d 100755 --- a/ob/cmd/downkill +++ b/ob/cmd/downkill @@ -1,8 +1,8 @@ #!/usr/bin/env sh -. cmd/env +. ./cmd/env run_down_kill() { - source cmd/container_ids + . ./cmd/container_ids $docker_path kill $ID_OB_UI $ID_OB_BACKEND $ID_OB_REDIS $ID_OB_DB $ID_OB_JANUS $ID_OB_SDB $ID_OB_INDEX $ID_OB_WORKER $ID_OB_CLEARLY $ID_OB_S3 ob_compose down } diff --git a/ob/cmd/env b/ob/cmd/env index 953c9ff..dcaa5e4 100755 --- a/ob/cmd/env +++ b/ob/cmd/env @@ -1,6 +1,6 @@ #!/usr/bin/env sh # used in ./ob/cmd/* scripts ran by ./launcher -source cmd/_colors +. ./cmd/_colors export docker_path=`which docker` export git_path=`which git` diff --git a/ob/cmd/logs b/ob/cmd/logs index 3d3695f..bf3b735 100755 --- a/ob/cmd/logs +++ b/ob/cmd/logs @@ -1,5 +1,5 @@ #!/usr/bin/env sh -. cmd/env +. ./cmd/env run_logs() { heading "Loading $OB_CMD_ARGS logs" diff --git a/ob/cmd/migrate b/ob/cmd/migrate index 3928fab..8571a6d 100755 --- a/ob/cmd/migrate +++ b/ob/cmd/migrate @@ -1,5 +1,5 @@ #!/usr/bin/env sh -. cmd/env +. ./cmd/env migration_message="$OB_CMD_ARGS" diff --git a/ob/cmd/pkg:update b/ob/cmd/pkg:update index 530127b..9fe6414 100755 --- a/ob/cmd/pkg:update +++ b/ob/cmd/pkg:update @@ -1,5 +1,5 @@ #!/usr/bin/env sh -. cmd/env +. ./cmd/env pkg_update () { cd ../ diff --git a/ob/cmd/ps b/ob/cmd/ps index 994ddd4..115da08 100755 --- a/ob/cmd/ps +++ b/ob/cmd/ps @@ -1,5 +1,5 @@ #!/usr/bin/env sh -. cmd/env +. ./cmd/env run_ps () { $docker_path ps diff --git a/ob/cmd/python b/ob/cmd/python index f46e9cd..2504738 100755 --- a/ob/cmd/python +++ b/ob/cmd/python @@ -1,5 +1,5 @@ #!/usr/bin/env sh -. cmd/env +. ./cmd/env run_python() { diff --git a/ob/cmd/restart b/ob/cmd/restart index c4f217c..dbf7641 100755 --- a/ob/cmd/restart +++ b/ob/cmd/restart @@ -1,5 +1,5 @@ #!/usr/bin/env sh -. cmd/env +. ./cmd/env run_restart() { if [ ! -z "$OB_CMD" ] & [ ! -z "$OB_CMD_ARGS" ]; then diff --git a/ob/cmd/setup:dev b/ob/cmd/setup:dev index d45c36a..38a45a1 100755 --- a/ob/cmd/setup:dev +++ b/ob/cmd/setup:dev @@ -1,5 +1,5 @@ #!/usr/bin/env sh -. cmd/env +. ./cmd/env run_setup_dev () { cd ../ diff --git a/ob/cmd/shell b/ob/cmd/shell index a6a22ac..4bc0c44 100755 --- a/ob/cmd/shell +++ b/ob/cmd/shell @@ -1,5 +1,5 @@ #!/usr/bin/env sh -. cmd/env +. ./cmd/env run_shell() { heading "Running $OB_CMD_OPT1 inside $OB_CMD_ARGS" diff --git a/ob/cmd/start b/ob/cmd/start index 619ffe5..1f492bc 100755 --- a/ob/cmd/start +++ b/ob/cmd/start @@ -1,5 +1,6 @@ #!/usr/bin/env sh -. cmd/env + +. ./cmd/env start() { if [[ ! -z "$OB_CMD_ARGS" ]]; then diff --git a/ob/cmd/stop b/ob/cmd/stop index 9d44f7f..5da9a3f 100755 --- a/ob/cmd/stop +++ b/ob/cmd/stop @@ -1,5 +1,5 @@ #!/usr/bin/env sh -. cmd/env +. ./cmd/env run_stop() { diff --git a/ob/cmd/ui_dev b/ob/cmd/ui_dev index 635328e..06a93c2 100755 --- a/ob/cmd/ui_dev +++ b/ob/cmd/ui_dev @@ -1,5 +1,5 @@ #!/usr/bin/env sh -. cmd/env +. ./cmd/env run_uidev() { unset ERR @@ -10,7 +10,7 @@ run_uidev() { success "Starting frontend:" info " http://localhost:3000" ob_compose stop ui > /dev/null 2>&1 - source $COMPOSE_ENV_FILES + . $COMPOSE_ENV_FILES echo "REACT_APP_BASE_URL (used by ui to call backend): $REACT_APP_BASE_URL" cd ../frontend export REACT_APP_BASE_URL=$REACT_APP_BASE_URL