-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add builtin netrc helper #82
Draft
6543
wants to merge
12
commits into
woodpecker-ci:main
Choose a base branch
from
6543-forks:build_in_netrc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+251
−2
Draft
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bda5f22
draft
6543 d4dbc40
parsin into own func
6543 42852ff
start with tests
6543 4b262e6
use build-in netrc helper on windows by default
6543 5a608d1
Apply suggestions from code review
6543 a622645
Update plugin.go
6543 cf6bfde
Merge branch 'main' into build_in_netrc
6543 012b85e
Merge branch 'main' into build_in_netrc
6543 80f68be
Merge branch 'main' into build_in_netrc
6543 4c86c72
Merge branch 'main' into build_in_netrc
6543 091794d
Merge branch 'main' into build_in_netrc
6543 04e3d4b
Merge branch 'main' into build_in_netrc
6543 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package main | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var globalFlags = []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "remote", | ||
Usage: "git remote url", | ||
EnvVars: []string{"PLUGIN_REMOTE", "CI_REPO_CLONE_URL"}, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "path", | ||
Usage: "git clone path", | ||
EnvVars: []string{"PLUGIN_PATH", "CI_WORKSPACE"}, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "sha", | ||
Usage: "git commit sha", | ||
EnvVars: []string{"PLUGIN_SHA", "CI_COMMIT_SHA"}, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "ref", | ||
Value: "refs/heads/master", | ||
Usage: "git commit ref", | ||
EnvVars: []string{"PLUGIN_REF", "CI_COMMIT_REF"}, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "event", | ||
Value: "push", | ||
Usage: "pipeline event", | ||
EnvVars: []string{"CI_PIPELINE_EVENT"}, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "netrc.machine", | ||
Usage: "netrc machine", | ||
EnvVars: []string{"CI_NETRC_MACHINE"}, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "netrc.username", | ||
Usage: "netrc username", | ||
EnvVars: []string{"CI_NETRC_USERNAME"}, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "netrc.password", | ||
Usage: "netrc password", | ||
EnvVars: []string{"CI_NETRC_PASSWORD"}, | ||
}, | ||
&cli.IntFlag{ | ||
Name: "depth", | ||
Usage: "clone depth", | ||
EnvVars: []string{"PLUGIN_DEPTH"}, | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "recursive", | ||
Usage: "clone submodules", | ||
EnvVars: []string{"PLUGIN_RECURSIVE"}, | ||
Value: true, | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "tags", | ||
Usage: "clone tags, if not explicitly set and event is tag its default is true else false", | ||
EnvVars: []string{"PLUGIN_TAGS"}, | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "skip-verify", | ||
Usage: "skip tls verification", | ||
EnvVars: []string{"PLUGIN_SKIP_VERIFY"}, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "custom-cert", | ||
Usage: "path or url to custom cert", | ||
EnvVars: []string{"PLUGIN_CUSTOM_SSL_PATH", "PLUGIN_CUSTOM_SSL_URL"}, | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "submodule-update-remote", | ||
Usage: "update remote submodules", | ||
EnvVars: []string{"PLUGIN_SUBMODULES_UPDATE_REMOTE", "PLUGIN_SUBMODULE_UPDATE_REMOTE"}, | ||
}, | ||
&cli.GenericFlag{ | ||
Name: "submodule-override", | ||
Usage: "json map of submodule overrides", | ||
EnvVars: []string{"PLUGIN_SUBMODULE_OVERRIDE"}, | ||
Value: &MapFlag{}, | ||
}, | ||
&cli.DurationFlag{ | ||
Name: "backoff", | ||
Usage: "backoff duration", | ||
EnvVars: []string{"PLUGIN_BACKOFF"}, | ||
Value: 5 * time.Second, | ||
}, | ||
&cli.IntFlag{ | ||
Name: "backoff-attempts", | ||
Usage: "backoff attempts", | ||
EnvVars: []string{"PLUGIN_ATTEMPTS"}, | ||
Value: 5, | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "lfs", | ||
Usage: "whether to retrieve LFS content if available", | ||
EnvVars: []string{"PLUGIN_LFS"}, | ||
Value: true, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "env-file", | ||
Usage: "source env file", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "branch", | ||
Usage: "Change branch name", | ||
EnvVars: []string{"PLUGIN_BRANCH", "CI_COMMIT_BRANCH", "CI_REPO_DEFAULT_BRANCH"}, | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "partial", | ||
Usage: "Enable/Disable Partial clone", | ||
EnvVars: []string{"PLUGIN_PARTIAL"}, | ||
Value: true, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "home", | ||
Usage: "Change home directory", | ||
EnvVars: []string{"PLUGIN_HOME"}, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "safe-directory", | ||
Usage: "Define safe directories", | ||
EnvVars: []string{"PLUGIN_SAFE_DIRECTORY", "CI_WORKSPACE"}, | ||
}, | ||
} |
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,77 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/urfave/cli/v2" | ||
|
||
"github.com/woodpecker-ci/plugin-git/netrc" | ||
) | ||
|
||
var netrcCommand = &cli.Command{ | ||
Name: "netrc", | ||
Usage: "built-in credentials helper to read netrc", | ||
Flags: []cli.Flag{&cli.StringFlag{ | ||
Name: "home", | ||
Usage: "Change home directory", | ||
EnvVars: []string{"PLUGIN_HOME"}, | ||
}}, | ||
Action: netrcGet, | ||
} | ||
|
||
func netrcGet(c *cli.Context) error { | ||
if c.Args().Len() == 0 { | ||
curExec, err := os.Executable() | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("built-in credentials helper to read netrc\n"+ | ||
"exec \"git config --global credential.helper '%s netrc'\" to use it\n", curExec) | ||
return nil | ||
} | ||
|
||
// set custom home | ||
if c.IsSet("home") { | ||
os.Setenv("HOME", c.String("home")) | ||
} | ||
|
||
// implement custom git credentials helper | ||
// https://git-scm.com/docs/gitcredentials | ||
switch c.Args().First() { | ||
case "get": | ||
netRC, err := netrc.Read() | ||
if err != nil { | ||
return err | ||
} | ||
if netRC != nil { | ||
fmt.Printf("username=%s\n", netRC.Login) | ||
fmt.Printf("password=%s\n", netRC.Password) | ||
fmt.Println("quit=true") | ||
} | ||
case "store": | ||
// TODO: netrc.Save() | ||
case "erase": | ||
_, err := netrc.Delete() | ||
if err != nil { | ||
return err | ||
} | ||
default: | ||
return fmt.Errorf("got unknown helper arg '%s'", c.Args().First()) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func setNetRCHelper() *exec.Cmd { | ||
curExec, err := os.Executable() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
credHelper := fmt.Sprintf("%s netrc", curExec) | ||
|
||
return appendEnv(exec.Command("git", "config", "--global", "credential.helper", credHelper), defaultEnvVars...) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this already added because you have the
app.Flags = globalFlags
statement which adds the flags globally?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to test ... but as it's mostly used only internally I dont think we do need it anyway ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested this, working as I expected.
You can try with this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That means just apply this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@6543 @qwerty287 What is the status here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as per lable > wip till i personally do dedicate time to it or it gets priorised at work ...