Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

Commit 312e4c5

Browse files
committed
shared: move more static values into instanced values.
In preparation for adding capture and replay proxies, more and more content cannot be static. In order to achieve this, as many static values are moved into instance values in the `Program` class.
1 parent e5c0e5d commit 312e4c5

File tree

5 files changed

+44
-12
lines changed

5 files changed

+44
-12
lines changed

Shared/Cli/Functions/Bitbucket.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static bool OAuthPrompt(Program program, string title, TargetUri targetUr
9494
}
9595

9696
accessToken = buffer.ToString(0, (int)read);
97-
accessToken = accessToken.Trim(Program.NewLineChars);
97+
accessToken = accessToken.Trim(program.NewLineChars);
9898
}
9999
}
100100
return accessToken != null;

Shared/Cli/Functions/Common.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ public static async Task<BaseAuthentication> CreateAuthentication(Program progra
8686

8787
// Detect the authority.
8888
authority = await Vsts.Authentication.GetAuthentication(program.Context,
89-
operationArguments.TargetUri,
90-
Program.VstsCredentialScope,
91-
new SecretStore(program.Context, secretsNamespace, Vsts.Authentication.UriNameConversion))
89+
operationArguments.TargetUri,
90+
Program.VstsCredentialScope,
91+
new SecretStore(program.Context, secretsNamespace, Vsts.Authentication.UriNameConversion))
9292
?? Github.Authentication.GetAuthentication(program.Context,
9393
operationArguments.TargetUri,
9494
Program.GitHubCredentialScope,
@@ -145,9 +145,9 @@ public static async Task<BaseAuthentication> CreateAuthentication(Program progra
145145

146146
// Create the authority object.
147147
authority = new Vsts.AadAuthentication(program.Context,
148-
tenantId,
149-
operationArguments.VstsTokenScope,
150-
new SecretStore(program.Context, secretsNamespace, Vsts.AadAuthentication.UriNameConversion));
148+
tenantId,
149+
operationArguments.VstsTokenScope,
150+
new SecretStore(program.Context, secretsNamespace, Vsts.AadAuthentication.UriNameConversion));
151151
}
152152

153153
// Return the allocated authority or a generic AAD backed VSTS authentication object.
@@ -184,8 +184,8 @@ public static async Task<BaseAuthentication> CreateAuthentication(Program progra
184184

185185
// Return the allocated authority or a generic MSA backed VSTS authentication object.
186186
return authority ?? new Vsts.MsaAuthentication(program.Context,
187-
operationArguments.VstsTokenScope,
188-
new SecretStore(program.Context, secretsNamespace, Vsts.MsaAuthentication.UriNameConversion));
187+
operationArguments.VstsTokenScope,
188+
new SecretStore(program.Context, secretsNamespace, Vsts.MsaAuthentication.UriNameConversion));
189189

190190
case AuthorityType.Ntlm:
191191
// Enforce NTLM authentication only.

Shared/Cli/Functions/GitHub.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static bool AuthCodePrompt(Program program, TargetUri targetUri, Github.G
8989
}
9090

9191
authenticationCode = buffer.ToString(0, (int)read);
92-
authenticationCode = authenticationCode.Trim(Program.NewLineChars);
92+
authenticationCode = authenticationCode.Trim(program.NewLineChars);
9393
}
9494

9595
return authenticationCode != null;

Shared/Cli/Program.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ partial class Program
7676
internal const string ConfigPrefix = "credential";
7777
internal const string SecretsNamespace = "git";
7878

79-
internal static readonly char[] NewLineChars = Environment.NewLine.ToCharArray();
80-
8179
internal static readonly Vsts.TokenScope VstsCredentialScope = Vsts.TokenScope.CodeWrite | Vsts.TokenScope.PackagingRead;
8280
internal static readonly Github.TokenScope GitHubCredentialScope = Github.TokenScope.Gist | Github.TokenScope.Repo;
8381

@@ -162,6 +160,7 @@ static Program()
162160
private readonly RuntimeContext _context;
163161
private string _location;
164162
private string _name;
163+
private char[] _newlineChars;
165164
private IntPtr _parentHwnd;
166165
private Stream _stdErrStream;
167166
private TextWriter _stdErrWriter;
@@ -372,6 +371,22 @@ internal Stream InStream
372371
internal INetwork Network
373372
=> _context.Network;
374373

374+
internal char[] NewLineChars
375+
{
376+
get
377+
{
378+
lock (_syncpoint)
379+
{
380+
if (_newlineChars is null)
381+
{
382+
_newlineChars = Environment.NewLine.ToCharArray();
383+
}
384+
385+
return _newlineChars;
386+
}
387+
}
388+
}
389+
375390
internal TextWriter Out
376391
{
377392
get

Shared/Win32/Types.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,18 @@ internal enum ErrorCode
280280
/// </summary>
281281
NoToken = 1008,
282282

283+
/// <summary>
284+
/// Element not found.
285+
/// </summary>
286+
NotFound = 1168,
287+
288+
/// <summary>
289+
/// A specified logon session does not exist.
290+
/// <para/>
291+
/// It may already have been terminated.
292+
/// </summary>
293+
NoSuchLogonSession = 1312,
294+
283295
/// <summary>
284296
/// A required privilege is not held by the client.
285297
/// </summary>
@@ -294,6 +306,11 @@ internal enum ErrorCode
294306
/// Not enough quota is available to process this command.
295307
/// </summary>
296308
NotEnoughQuota = 1816,
309+
310+
/// <summary>
311+
/// The specified username is invalid.
312+
/// </summary>
313+
BadUserName = 2202,
297314
}
298315

299316
internal enum Hresult : uint

0 commit comments

Comments
 (0)