Skip to content
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

Store tokens somewhere other than ~/.gitconfig #63

Closed
colemickens opened this issue Nov 4, 2016 · 11 comments
Closed

Store tokens somewhere other than ~/.gitconfig #63

colemickens opened this issue Nov 4, 2016 · 11 comments
Assignees
Milestone

Comments

@colemickens
Copy link

I keep ~/.gitconfig stored in source control. I can't do so with git-repo storing the github auth token in there...

Thanks.

@guyzmo
Copy link
Owner

guyzmo commented Nov 5, 2016

hm… I did not think about that. I guess it can't hurt to see if I can extend the --config option to all commands, so you can store it where you'd like, and modify the alias command to add the --config option.

Meanwhile you can use environment variables that we use for the testing to setup the tokens else where.

Finally, you also have the option to have store your credentials locally to your workstation in a commit (using a branch) you don't push back to the repository, and merge the changes back… And there are a couple of tools to help with that, to manage local commits.

@guyzmo
Copy link
Owner

guyzmo commented Nov 23, 2016

I have had a thought about it, how would you feel about having credentials stored in ~/.netrc which look like a place commonly used for credentials…

@colemickens any opinion on that?

@colemickens
Copy link
Author

Seems reasonable to me.

@guyhughes
Copy link
Contributor

@colemickens you could also use set include.path in your gitconfig to include a untracked file, like this.

@guyzmo
Copy link
Owner

guyzmo commented Nov 24, 2016

hm… @guyhughes did not know about that, but if it's actually working (we need to test that!), I guess this would be a case for not changing the credential storage mechanism, meaning less work for me ☺

@colemickens any opinions on that?

@guyzmo
Copy link
Owner

guyzmo commented Nov 27, 2016

I actually tested this, and it's working like a charm. 👍

So won't implement a .netrc option, and make a documentation about this feature.

@guyzmo guyzmo closed this as completed in 18a3d4f Nov 27, 2016
@guyzmo
Copy link
Owner

guyzmo commented Nov 27, 2016

I've added a small utility that actually extract all gitrepo ".*" sections into a new file, and automatically replaces them with a include.path item. I've info about that to the README file in the configuration section.

Just run (currently from the devel branch):

python -m git_repo.extract_config

which will extract the relevant configuration from ~/.gitconfig into ~/.gitconfig-repos. If you want some other path:

python -m git_repo.extract_config ~/.local/gitrepo-config

Hope it covers the issue ☺

@guyzmo guyzmo added this to the 1.7 milestone Nov 27, 2016
@guyzmo guyzmo self-assigned this Nov 27, 2016
@m040601
Copy link

m040601 commented Jan 17, 2017

Thanks for your effort providing an alternative solution to having the auth tokens written in .gitconfig

But this still doesnt solve the issue that git-repo still assumes a .gitconfig must exist , or else it will force me to create one.

I want to use $HOME/.config/XYZ as possible to all my configuration.
I am already doing that for git, using the $HOME/.config/git/config file there (or gitk, or other /x,y,z files in there). This is possible because git, like many other programs nowadays follow the XDG specifications.
This already happened in 2012,
http://git.661346.n2.nabble.com/Git-to-use-XDG-Base-Directory-Standard-td7565625.html
https://wiki.archlinux.org/index.php/XDG_Base_Directory_support
https://wiki.archlinux.org/index.php/XDG_user_directories
This simplifies backups, doesnt pollute my $HOME among many other things.

Other git tools do it this way as well.
For example, hub, the github "semiofficial" cli tool (https://github.com/github/hub) does it.
They use the file, $HOME/.config/hub,

Hub will prompt for GitHub username & password the first time it needs to access the API
and exchange it for an OAuth token, which it saves in "~/.config/hub".

It will still go looking for other options in $HOME/.config/git/config. Ex:
[hub]
protocol = https
But at least, it wont force me, to have a .gitconfig fie.

I do not want any other tool to CREATE without my consent a file that is or might be used to configure (and mess with) ANOTHER application configuration.That is, I do not want git-repo to force me to create that .gitconfig file in my system, when I already have my git config done some other way.

I simply do not want that .gitconfig file to exist.

My suggestion to make this possible:

  1. Start by looking for $HOME/.gitconfig
  2. If that file exists, do the way it's being done now. This would suit users, who still use .gitconfig and want to go the "include paths" or ".netrc" route)
    3 If that file, .gitconfig doesnt exist, DONT CREATE IT
  3. Go look for auth tokens in a $HOME/.config/git-repo/tokens file
  4. If that file exists, use the tokens stored there (or eventually do what you're told there, ex: include XYZ file, use netrc )
  5. If that file doesnt exist, create it and store the tokens there.
  6. Any other options and or alias that git-repo needs

[alias]
hub = repo hub
bb = repo bb
lab = repo lab
[gitrepo]
some-future-gitrepo-option = XYZ
another-future-gitrepo-option = ABC
[gitrepo "myprecious"]
type = gitlab
token = YourSuperPrivateKey
fqdn = gitlab.example.org
Set this only if you use a self-signed certificate and experience problems
insecure = true

continue to do like you do now.That is, look into $HOME.gitconfig.
But, If that doesnt exist, dont create it, but look into $HOME/.config/git/config. (Eventually later use $HOME/.config/git-repo/config)

Thanks in advance !

@guyhughes
Copy link
Contributor

Using the XDG directory, the git-config supported path is $XDG_CONFIG_HOME/git/config.

Git began fully implementing support for config files in $XDG_CONFIG_HOME fairly recently in v2.4.3. Here's the commit:
git/git@ea19289

This is a new feature request. So I'll open a new issue.

@guyzmo
Copy link
Owner

guyzmo commented Jan 18, 2017

thank you @guyhughes

@guyzmo
Copy link
Owner

guyzmo commented Jan 18, 2017

thank you for that well documented comment, @m040601, but as @guyhughes it's better fitted as a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants