From 3e126e751dfb884a745b434c3f240622d6c3ef86 Mon Sep 17 00:00:00 2001 From: gabrie30 Date: Sun, 9 Apr 2023 12:40:37 -0700 Subject: [PATCH] Add GHORG_NO_TOKEN (#299) --- CHANGELOG.md | 10 ++++++++++ cmd/clone.go | 4 ++++ cmd/root.go | 25 +++++++++++++++---------- cmd/version.go | 2 +- configs/configs.go | 4 ++++ sample-conf.yaml | 4 ++++ 6 files changed, 38 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae9d163..8cf84e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +## [1.9.5] - unreleased +### Added +- GHORG_NO_TOKEN to allow cloning no token present; thanks @6543 +### Changed +### Deprecated +### Removed +### Fixed +### Security + + ## [1.9.4] - 2/26/23 ### Added ### Changed diff --git a/cmd/clone.go b/cmd/clone.go index c8ffe19..d232369 100644 --- a/cmd/clone.go +++ b/cmd/clone.go @@ -166,6 +166,10 @@ func cloneFunc(cmd *cobra.Command, argz []string) { os.Setenv("GHORG_QUIET", "true") } + if cmd.Flags().Changed("no-token") { + os.Setenv("GHORG_NO_TOKEN", "true") + } + if cmd.Flags().Changed("preserve-dir") { os.Setenv("GHORG_PRESERVE_DIRECTORY_STRUCTURE", "true") } diff --git a/cmd/root.go b/cmd/root.go index f897c75..5587779 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -30,6 +30,15 @@ var ( outputDir string topics string gitFilter string + targetCloneSource string + matchPrefix string + excludeMatchPrefix string + matchRegex string + excludeMatchRegex string + config string + gitlabGroupExcludeMatchRegex string + ghorgIgnorePath string + ghorgReClonePath string includeSubmodules bool skipArchived bool skipForks bool @@ -45,19 +54,11 @@ var ( fetchAll bool ghorgReCloneVerbose bool ghorgReCloneQuiet bool + noToken bool + quietMode bool args []string cloneErrors []string cloneInfos []string - targetCloneSource string - matchPrefix string - excludeMatchPrefix string - matchRegex string - excludeMatchRegex string - config string - gitlabGroupExcludeMatchRegex string - ghorgIgnorePath string - ghorgReClonePath string - quietMode bool ) // rootCmd represents the base command when called without any subcommands @@ -128,6 +129,8 @@ func getOrSetDefaults(envVar string) { os.Setenv(envVar, "false") case "GHORG_BACKUP": os.Setenv(envVar, "false") + case "GHORG_NO_TOKEN": + os.Setenv(envVar, "false") case "GHORG_RECLONE_VERBOSE": os.Setenv(envVar, "false") case "GHORG_RECLONE_QUIET": @@ -204,6 +207,7 @@ func InitConfig() { getOrSetDefaults("GHORG_SKIP_ARCHIVED") getOrSetDefaults("GHORG_SKIP_FORKS") getOrSetDefaults("GHORG_NO_CLEAN") + getOrSetDefaults("GHORG_NO_TOKEN") getOrSetDefaults("GHORG_FETCH_ALL") getOrSetDefaults("GHORG_PRUNE") getOrSetDefaults("GHORG_PRUNE_NO_CONFIRM") @@ -277,6 +281,7 @@ func init() { cloneCmd.Flags().BoolVar(&insecureGiteaClient, "insecure-gitea-client", false, "GHORG_INSECURE_GITEA_CLIENT - Must be set to clone from a Gitea instance using http") cloneCmd.Flags().BoolVar(&cloneWiki, "clone-wiki", false, "GHORG_CLONE_WIKI - Additionally clone the wiki page for repo") cloneCmd.Flags().BoolVar(&skipForks, "skip-forks", false, "GHORG_SKIP_FORKS - Skips repo if its a fork, github/gitlab/gitea only") + cloneCmd.Flags().BoolVar(&noToken, "no-token", false, "GHORG_NO_TOKEN - Allows you to run ghorg with no token (GHORG__TOKEN), SCM server needs to specify no auth required for api calls") cloneCmd.Flags().BoolVar(&preserveDir, "preserve-dir", false, "GHORG_PRESERVE_DIRECTORY_STRUCTURE - Clones repos in a directory structure that matches gitlab namespaces eg company/unit/subunit/app would clone into ghorg/unit/subunit/app, gitlab only") cloneCmd.Flags().BoolVar(&backup, "backup", false, "GHORG_BACKUP - Backup mode, clone as mirror, no working copy (ignores branch parameter)") cloneCmd.Flags().BoolVar(&quietMode, "quiet", false, "GHORG_QUIET - Emit critical output only") diff --git a/cmd/version.go b/cmd/version.go index fbc6c71..5900271 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" ) -const ghorgVersion = "v1.9.4" +const ghorgVersion = "v1.9.5" var versionCmd = &cobra.Command{ Use: "version", diff --git a/configs/configs.go b/configs/configs.go index 049927a..b296c26 100644 --- a/configs/configs.go +++ b/configs/configs.go @@ -237,6 +237,10 @@ func getOrSetGiteaToken() { // VerifyTokenSet checks to make sure env is set for the correct scm provider func VerifyTokenSet() error { + if os.Getenv("GHORG_NO_TOKEN") == "true" { + return nil + } + scmProvider := os.Getenv("GHORG_SCM_TYPE") if scmProvider == "github" && os.Getenv("GHORG_GITHUB_TOKEN") == "" { diff --git a/sample-conf.yaml b/sample-conf.yaml index 4aa5428..aa9f602 100644 --- a/sample-conf.yaml +++ b/sample-conf.yaml @@ -137,6 +137,10 @@ GHORG_EXIT_CODE_ON_CLONE_INFOS: 0 # flag (--exit-code-on-clone-issues) GHORG_EXIT_CODE_ON_CLONE_ISSUES: 1 +# Allows you to run ghorg with no token (GHORG__TOKEN), SCM server needs to specify no auth required for api calls +# flag (--no-token) +GHORG_NO_TOKEN: false + # Specifies the location of your ghorg conf.yaml, allowing you to have many configuration files, or none at all # default: ghorg looks in $HOME/.config/ghorg/conf.yaml, if not set in that location nor as a commandline flag, ghorg will use all default values # NOTE: this cannot be set in the configuration file. Its supported through CLI flag and ENV var only.