vsts-mirror-git-repository
vsts-mirror-git-repository copied to clipboard
Enhance interface to support multiple authentication methods
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
sourceGitRepositoryAuthenticationMechanismanddestinationGitRepositoryAuthenticationMechanism- Both should be of type
picklistsince we'll eventually support several such mechanisms - I imagine the first values should have display names like
access token(current available option), and probablynone
- Both should be of type
- The existing inputs for the access tokens (
sourceGitRepositoryPersonalAccessTokenanddestinationGitRepositoryPersonalAccessToken) need to havevisibleRules wired up based on the value of the respective new inputs created in the preceding step- Here's an example utilizing
visibleRulehttps://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureFileCopyV4/task.json#L77
- Here's an example utilizing
- 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
getInputcalls 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 togetInputwill be based on the value ofdestinationGitRepositoryAuthenticationMechanismhttps://github.com/swellaby/vsts-mirror-git-repository/blob/3b11470f42e2617c46f7ae607d23e0a64da776a6/src/git-mirror/git-mirror-task.ts#L25 - The task code will need to be updated to build the uri and potentially the git command args/flags (for example with #85
-c http.extraheader="AUTHORIZATION: .....) based on the new input values
https://github.com/swellaby/vsts-mirror-git-repository/blob/3b11470f42e2617c46f7ae607d23e0a64da776a6/src/git-mirror/git-mirror-task.ts#L128-L141
https://github.com/swellaby/vsts-mirror-git-repository/blob/3b11470f42e2617c46f7ae607d23e0a64da776a6/src/git-mirror/git-mirror-task.ts#L91-L104