Skip to content

Commit

Permalink
update access token getter
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Apr 20, 2022
1 parent d75be69 commit 4760cae
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
24 changes: 14 additions & 10 deletions src/ArcCommander/APIs/RemoteAccessAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ module RemoteAccessAPI =

let log = Logging.createLogger "GitAuthenticateLog"

let hostAddress = getFieldValueByName "Server" remoteAccessArgs
let hostAddress =
let ha = getFieldValueByName "Server" remoteAccessArgs
if ha.Contains "https" then ha
else $"https://{ha}"


log.Info("Start Arc Authenticate")

Expand All @@ -32,16 +36,16 @@ module RemoteAccessAPI =
| Ok token ->
log.Info("Successfully retrieved access token from token service")

log.Trace("Try transfer git user metadata to global arcCommander config")
match IniData.tryGetGlobalConfigPath () with
| Some globalConfigPath ->
IniData.setValueInIniPath globalConfigPath "general.gitname" (token.FirstName + " " + token.LastName)
IniData.setValueInIniPath globalConfigPath "general.gitemail" token.Email
log.Trace("Successfully transferred git user metadata to global arcCommander config")
| None ->
log.Error("Could not transfer git user metadata to global arcCommander config")
//log.Trace("Try transfer git user metadata to global arcCommander config")
//match IniData.tryGetGlobalConfigPath () with
//| Some globalConfigPath ->
// IniData.setValueInIniPath globalConfigPath "general.gitname" (token.FirstName + " " + token.LastName)
// IniData.setValueInIniPath globalConfigPath "general.gitemail" token.Email
// log.Trace("Successfully transferred git user metadata to global arcCommander config")
//| None ->
// log.Error("Could not transfer git user metadata to global arcCommander config")

if GitHelper.storeCredentialsToken log token then
if GitHelper.storeCredentials log hostAddress "oauth2" token.AccessToken then
log.Info($"Finished Authentication")

else
Expand Down
2 changes: 1 addition & 1 deletion src/ArcCommander/Authentication.fs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ module Authentication =

t.Wait()
t.Result
|> Result.map (fun result -> IdentityToken.ofJwt result.IdentityToken)
//|> Result.map (fun result -> IdentityToken.ofJwt result.IdentityToken)

module OAuth2 =

Expand Down
17 changes: 12 additions & 5 deletions src/ArcCommander/GitHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ module GitHelper =
executeGitCommand dir "push"

/// Stores git credentials to a git host using the git credential interface
let storeCredentials (log : NLog.Logger) host username password =
let storeCredentials (log : NLog.Logger) (host : string) username password =

log.Info($"INFO: Start git credential storing")

let protocol = "https"
let host = host.Replace($"{protocol}://","")
let path = $"git:{protocol}://{host}"

let procStartInfo =
Expand All @@ -144,12 +145,12 @@ module GitHelper =

let errorHandler (_sender:obj) (args:DataReceivedEventArgs) =

if args.Data.Contains "trace:" then
outputs.Add args.Data
log.Trace($"{args.Data}")
else
if args.Data.ToLower().Contains "error" then
errors.Add args.Data
log.Error($"{args.Data}")
else
outputs.Add args.Data
log.Trace($"{args.Data}")

let p = new Process(StartInfo = procStartInfo)

Expand All @@ -164,11 +165,17 @@ module GitHelper =

log.Trace($"Start feeding credentials into git credential interface")

log.Trace($"url={path}")
p.StandardInput.WriteLine $"url={path}"
log.Trace($"username={username}")
p.StandardInput.WriteLine $"username={username}"
log.Trace($"host={host}")
p.StandardInput.WriteLine $"host={host}"
log.Trace($"path={path}")
p.StandardInput.WriteLine $"path={path}"
log.Trace($"protocol={protocol}")
p.StandardInput.WriteLine $"protocol={protocol}"
log.Trace($"password={password}")
p.StandardInput.WriteLine $"password={password}"
p.StandardInput.WriteLine ""

Expand Down

0 comments on commit 4760cae

Please sign in to comment.