This repository was archived by the owner on Oct 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathGlobal.java
More file actions
38 lines (34 loc) · 1.71 KB
/
Global.java
File metadata and controls
38 lines (34 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root.
package com.microsoft.alm.authentication;
final class Global
{
public static final int PasswordMaxLength = 2047;
public static final int UsernameMaxLength = 511;
private static String userAgent = null;
/**
* Creates the correct user-agent string for HTTP calls.
*
* @return The `user-agent` string for "git-tools".
* Example from Windows version:
* git-credential-manager (Microsoft Windows NT 6.2.9200.0; Win32NT; x64) CLR/4.0.30319 git-tools/1.0.0
* Example from Java version:
* git-credential-manager (Windows 8.1; 6.3; amd64) Java HotSpot(TM) 64-Bit Server VM/1.8.0_51-b16 git-tools/1.0.0-SNAPSHOT
*/
public static String getUserAgent()
{
if (userAgent == null)
{
// https://stackoverflow.com/a/6773868/
final String version = Global.class.getPackage().getImplementationVersion();
userAgent = String.format("git-credential-manager (%1$s; %2$s; %3$s) %4$s/%5$s git-tools/%6$s",
System.getProperty("os.name"), // "Windows Server 2012 R2", "Mac OS X", "Linux"
System.getProperty("os.version"), // "6.3", "10.9.5", "3.19.0-28-generic"
System.getProperty("os.arch"), // "amd64", "x86_64", "amd64"
System.getProperty("java.vm.name"), // "Java HotSpot(TM) 64-Bit Server VM", "OpenJDK 64-Bit Server VM"
System.getProperty("java.runtime.version"), // "1.8.0_60-b27", "1.7.0_71-b14", "1.7.0_79-b14"
version);
}
return userAgent;
}
}