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

LibGit2 credential approval/rejection #23711

Merged
merged 7 commits into from
Sep 18, 2017
Merged

LibGit2 credential approval/rejection #23711

merged 7 commits into from
Sep 18, 2017

Conversation

omus
Copy link
Member

@omus omus commented Sep 14, 2017

Previously the credential callback would mutate the explicitly provided credential or cached credential. With this change we never mutate explicitly provided credentials and only add/replace credentials in the cache when they have successfully been used.

Additionally, this PR lays the ground work for integrating other credential storage systems such as the git credential helpers and removes the LibGit2 function get_creds!.

Part of #20725.

@omus omus added the libgit2 The libgit2 library or the LibGit2 stdlib module label Sep 14, 2017
@omus
Copy link
Member Author

omus commented Sep 14, 2017

I missed a usage of get_creds! in test/misc.jl

@omus omus force-pushed the cv/libgit2-cred-approval branch from 219a750 to cc25af0 Compare September 14, 2017 16:58
Copy link
Contributor

@rofinn rofinn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from properly deprecating get_creds! this seems reasonable.

@@ -45,7 +45,7 @@ function user_abort()
(Cint, Cstring),
Cint(Error.Callback), "Aborting, user cancelled credential request.")

return Cint(Error.EAUTH)
return Cint(Error.EUSER)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just going to mention that EUSER is a generic error code which is suppose to be for callback usage. It doesn't formally mean the user cancelled the callback.

@@ -1119,14 +1119,29 @@ struct CachedCredentials <: AbstractCredentials
CachedCredentials() = new(Dict{String,AbstractCredentials}())
end

"Obtain the cached credentials for the given host+protocol (credid), or return and store the default if not found"
get_creds!(collection::CachedCredentials, credid, default) = get!(collection.cred, credid, default)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably deprecate get_creds! properly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member Author

@omus omus Sep 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a proper deprecation for this. It required adding Base.get!(cache::CachedCredentials, cred_id, default). Additionally, I switched the test/misc.jl tests to use get!.

@omus omus force-pushed the cv/libgit2-cred-approval branch from cc25af0 to 93c3dbb Compare September 15, 2017 21:39
Differentiates this error from EAUTH exceptions which indicate that the
credentials are invalid.
Only save credentials to the cache when they are used successfully.
Credentials that trigger an EAUTH exception will be removed from the
cache.

Note: Modifications to the credential field in the CredentialPayload
should not modify cached credentials until they are approved.
Since the credential ID is based upon the URL which couldn't change
during the lifetime of a CredentialPayload then we only need to pull
a credential out of the cache once.
@omus omus force-pushed the cv/libgit2-cred-approval branch from 93c3dbb to 86c6a17 Compare September 17, 2017 01:33
@omus omus merged commit d668a95 into master Sep 18, 2017
@omus omus deleted the cv/libgit2-cred-approval branch September 18, 2017 00:43
omus added a commit that referenced this pull request Sep 18, 2017
Requires:
- Approval/rejection (#23711)
- Allow prompt keyword (#23690)

Helpful:
- Generate tests (#23668)

I would apply this commit to the approval/rejection PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libgit2 The libgit2 library or the LibGit2 stdlib module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants