Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src/lib/auth.sh
diff options
context:
space:
mode:
authorLevente Polyak <anthraxx@archlinux.org>2022-10-23 20:42:34 +0200
committerLevente Polyak <anthraxx@archlinux.org>2023-05-19 22:27:12 +0200
commit77d800eab2419b334cafd94b2e986351919def77 (patch)
treea4d38ebe249052ec926c59ad970440845055fef7 /src/lib/auth.sh
parentd2245b1943fd30ab0252e47d47871ac94e143339 (diff)
auth: implemented module to authenticate against our GitLab
This helps to have a convenient way to manage and test our personal GitLab tokens. Those are used for certain API calls like creating new repositories. prefill the access token web view as per https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#prefill-personal-access-token-name-and-scopes Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
Diffstat (limited to 'src/lib/auth.sh')
-rw-r--r--src/lib/auth.sh72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/lib/auth.sh b/src/lib/auth.sh
new file mode 100644
index 0000000..77d6a90
--- /dev/null
+++ b/src/lib/auth.sh
@@ -0,0 +1,72 @@
+#!/hint/bash
+#
+# This may be included with or without `set -euE`
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+[[ -z ${DEVTOOLS_INCLUDE_AUTH_SH:-} ]] || return 0
+DEVTOOLS_INCLUDE_AUTH_SH=1
+
+_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@}
+
+set -e
+
+
+pkgctl_auth_usage() {
+ local -r COMMAND=${_DEVTOOLS_COMMAND:-${BASH_SOURCE[0]##*/}}
+ cat <<- _EOF_
+ Usage: ${COMMAND} [COMMAND] [OPTIONS]
+
+ Authenticate with services like GitLab.
+
+ COMMANDS
+ login Authenticate with the GitLab instance
+ status View authentication status
+
+ OPTIONS
+ -h, --help Show this help text
+
+ EXAMPLES
+ $ ${COMMAND} login --gen-access-token
+ $ ${COMMAND} status
+_EOF_
+}
+
+pkgctl_auth() {
+ if (( $# < 1 )); then
+ pkgctl_auth_usage
+ exit 0
+ fi
+
+ # option checking
+ while (( $# )); do
+ case $1 in
+ -h|--help)
+ pkgctl_auth_usage
+ exit 0
+ ;;
+ login)
+ _DEVTOOLS_COMMAND+=" $1"
+ shift
+ # shellcheck source=src/lib/auth/login.sh
+ source "${_DEVTOOLS_LIBRARY_DIR}"/lib/auth/login.sh
+ pkgctl_auth_login "$@"
+ exit 0
+ ;;
+ status)
+ _DEVTOOLS_COMMAND+=" $1"
+ shift
+ # shellcheck source=src/lib/auth/status.sh
+ source "${_DEVTOOLS_LIBRARY_DIR}"/lib/auth/status.sh
+ pkgctl_auth_status "$@"
+ exit 0
+ ;;
+ -*)
+ die "invalid argument: %s" "$1"
+ ;;
+ *)
+ die "invalid command: %s" "$1"
+ ;;
+ esac
+ done
+}