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

Enhance interface to support multiple authentication methods #86

Open
calebcartwright opened this issue Nov 17, 2020 · 0 comments
Open
Labels
good first issue Good for newcomers help wanted Issue or PR needs someone to work on it!

Comments

@calebcartwright
Copy link
Member

Currently the only authentication mechanism supported by the mirror task is URI encoding with basic auth in the userinfo subcomponent. Though this is a viable means of authentication with the major git hosting platforms, it's generally discouraged, not necessarily universally supported, and there are of course several other preferable ways to authenticate.

The lack of support for alternatives has been reported as a problem (e.g. #63, #10) and more generally it'd be good for us to support other use cases (e.g. #85, #1)

For anyone interested in working on this, some details/hints are below. It would also probably be a good idea to include support for one of the other authentication mechanisms as part of the PR that addresses this issue (the easiest one may be None)

  • Two new inputs needs to be added to the task that allow the user to specify the authentication mechanism, one for the Source repo and another for the Target repo (for example sourceGitRepositoryAuthenticationMechanism and destinationGitRepositoryAuthenticationMechanism
    • Both should be of type picklist since we'll eventually support several such mechanisms
    • I imagine the first values should have display names like access token (current available option), and probably none
  • The existing inputs for the access tokens (sourceGitRepositoryPersonalAccessToken and destinationGitRepositoryPersonalAccessToken) need to have visibleRules wired up based on the value of the respective new inputs created in the preceding step
  • The task code that loads the input values needs to be updated to import the value of the new inputs, and then the second boolean arg used for other getInput calls to indicate whether the input is required will need to be updated to be set dynamically based on the value of the new authentication mechanism input fields vs. a literal bool. e.g. the second arg to getInput will be based on the value of destinationGitRepositoryAuthenticationMechanism
    this.destinationGitRepositoryPersonalAccessToken = taskLib.getInput("destinationGitRepositoryPersonalAccessToken", true);
  • The task code will need to be updated to build the uri and potentially the git command args/flags (for example with Support authorization via header #85 -c http.extraheader="AUTHORIZATION: .....) based on the new input values

public getAuthenticatedGitUri(uri: string, token: string): string {
if (!validUrl.isUri(uri)) {
throw new Error("Provided URI '" + uri + "' is not a valid URI");
}
else if (token === undefined) {
return uri;
}
else {
const colonSlashSlash = "://";
const protocol = uri.substring(0, uri.indexOf(colonSlashSlash));
const address = uri.substring(uri.indexOf(colonSlashSlash) + colonSlashSlash.length);
return protocol + colonSlashSlash + token + "@" + address;
}
}

public gitPushMirror() {
const authenticatedDestinationGitUrl = this.getAuthenticatedGitUri(this.destinationGitRepositoryUri, this.destinationGitRepositoryPersonalAccessToken);
const verifySSLCertificateFlag = this.getDestinationVerifySSLCertificate();
return taskLib
.tool("git")
.argIf(verifySSLCertificateFlag, ["-c", "http.sslVerify=true"])
.argIf(!verifySSLCertificateFlag, ["-c", "http.sslVerify=false"])
.arg("-C")
.arg(this.sourceGitRepositoryCloneDirectory)
.arg("push")
.arg("--mirror")
.arg(authenticatedDestinationGitUrl)
.exec();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Issue or PR needs someone to work on it!
Projects
None yet
Development

No branches or pull requests

1 participant