Skip to content

Commit 413dff9

Browse files
committed
add http token
1 parent 8fbfc22 commit 413dff9

File tree

9 files changed

+68
-15
lines changed

9 files changed

+68
-15
lines changed

src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ public GeneralClientBootstrap SetConfig(Configinfo configInfo)
7878
BlackFiles = configInfo.BlackFiles,
7979
ProductId = configInfo.ProductId,
8080
UpgradeClientVersion = configInfo.UpgradeClientVersion,
81-
Bowl = configInfo.Bowl
81+
Bowl = configInfo.Bowl,
82+
Scheme = configInfo.Scheme,
83+
Token = configInfo.Token
8284
};
8385
return this;
8486
}
@@ -144,14 +146,18 @@ private async Task ExecuteWorkflowAsync()
144146
, AppType.ClientApp
145147
, _configInfo.AppSecretKey
146148
, GetPlatform()
147-
, _configInfo.ProductId);
149+
, _configInfo.ProductId
150+
, _configInfo.Scheme
151+
, _configInfo.Token);
148152

149153
var upgradeResp = await VersionService.Validate(_configInfo.UpdateUrl
150154
, _configInfo.UpgradeClientVersion
151155
, AppType.UpgradeApp
152156
, _configInfo.AppSecretKey
153157
, GetPlatform()
154-
, _configInfo.ProductId);
158+
, _configInfo.ProductId
159+
, _configInfo.Scheme
160+
, _configInfo.Token);
155161

156162
_configInfo.IsUpgradeUpdate = CheckUpgrade(upgradeResp);
157163
_configInfo.IsMainUpdate = CheckUpgrade(mainResp);
@@ -191,7 +197,9 @@ private async Task ExecuteWorkflowAsync()
191197
, mainResp.Body
192198
, _configInfo.ReportUrl
193199
, _configInfo.BackupDirectory
194-
, _configInfo.Bowl);
200+
, _configInfo.Bowl
201+
, _configInfo.Scheme
202+
, _configInfo.Token);
195203

196204
_configInfo.ProcessInfo =
197205
JsonSerializer.Serialize(processInfo, ProcessInfoJsonContext.Default.ProcessInfo);

src/c#/GeneralUpdate.ClientCore/Strategys/LinuxStrategy.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ public override async Task ExecuteAsync()
6464
}
6565
finally
6666
{
67-
await VersionService.Report(_configinfo.ReportUrl, version.RecordId, status, version.AppType);
67+
await VersionService.Report(_configinfo.ReportUrl
68+
, version.RecordId
69+
, status
70+
, version.AppType
71+
, _configinfo.Scheme
72+
, _configinfo.Token);
6873
}
6974
}
7075

src/c#/GeneralUpdate.ClientCore/Strategys/WindowsStrategy.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ public override async Task ExecuteAsync()
6363
}
6464
finally
6565
{
66-
await VersionService.Report(_configinfo.ReportUrl, version.RecordId, status, version.AppType);
66+
await VersionService.Report(_configinfo.ReportUrl
67+
, version.RecordId
68+
, status
69+
, version.AppType
70+
, _configinfo.Scheme
71+
, _configinfo.Token);
6772
}
6873
}
6974

src/c#/GeneralUpdate.Common/Shared/Object/Configinfo.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public class Configinfo
6969
public string ProductId { get; set; }
7070

7171
public string Bowl { get; set; }
72+
73+
public string Scheme { get; set; }
74+
75+
public string Token { get; set; }
7276

7377
public void Validate()
7478
{

src/c#/GeneralUpdate.Common/Shared/Object/GlobalConfigInfo.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,8 @@ public class GlobalConfigInfo
117117
public string BackupDirectory { get; set; }
118118

119119
public string Bowl { get; set; }
120+
121+
public string Scheme { get; set; }
122+
123+
public string Token { get; set; }
120124
}

src/c#/GeneralUpdate.Common/Shared/Object/ProcessInfo.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public ProcessInfo(string appName
2222
, List<VersionInfo> updateVersions
2323
, string reportUrl
2424
, string backupDirectory
25-
, string bowl)
25+
, string bowl
26+
, string scheme
27+
, string token)
2628
{
2729
AppName = appName ?? throw new ArgumentNullException(nameof(appName));
2830
if (!Directory.Exists(installPath)) throw new ArgumentException($"{nameof(installPath)} path does not exist ! {installPath}.");
@@ -40,6 +42,8 @@ public ProcessInfo(string appName
4042
ReportUrl = reportUrl ?? throw new ArgumentNullException(nameof(reportUrl));
4143
BackupDirectory = backupDirectory ?? throw new ArgumentNullException(nameof(backupDirectory));
4244
Bowl = bowl;
45+
Scheme = scheme;
46+
Token = token;
4347
}
4448

4549
/// <summary>
@@ -116,5 +120,11 @@ public ProcessInfo(string appName
116120

117121
[JsonPropertyName("Bowl")]
118122
public string Bowl { get; set; }
123+
124+
[JsonPropertyName("Scheme")]
125+
public string Scheme { get; set; }
126+
127+
[JsonPropertyName("Token")]
128+
public string Token { get; set; }
119129
}
120130
}

src/c#/GeneralUpdate.Common/Shared/Service/VersionService.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ private VersionService() { }
2828
public static async Task Report(string httpUrl
2929
, int recordId
3030
, int status
31-
, int? type)
31+
, int? type
32+
, string scheme = null
33+
, string token = null)
3234
{
3335
var parameters = new Dictionary<string, object>
3436
{
3537
{ "RecordId", recordId },
3638
{ "Status", status },
3739
{ "Type", type }
3840
};
39-
await PostTaskAsync<BaseResponseDTO<bool>>(httpUrl, parameters, ReportRespJsonContext.Default.BaseResponseDTOBoolean);
41+
await PostTaskAsync<BaseResponseDTO<bool>>(httpUrl, parameters, ReportRespJsonContext.Default.BaseResponseDTOBoolean, scheme, token);
4042
}
4143

4244
/// <summary>
@@ -54,7 +56,9 @@ public static async Task<VersionRespDTO> Validate(string httpUrl
5456
, int appType
5557
, string appKey
5658
, int platform
57-
, string productId)
59+
, string productId
60+
, string scheme = null
61+
, string token = null)
5862
{
5963
var parameters = new Dictionary<string, object>
6064
{
@@ -64,10 +68,10 @@ public static async Task<VersionRespDTO> Validate(string httpUrl
6468
{ "Platform", platform },
6569
{ "ProductId", productId }
6670
};
67-
return await PostTaskAsync<VersionRespDTO>(httpUrl, parameters, VersionRespJsonContext.Default.VersionRespDTO);
71+
return await PostTaskAsync<VersionRespDTO>(httpUrl, parameters, VersionRespJsonContext.Default.VersionRespDTO, scheme, token);
6872
}
6973

70-
private static async Task<T> PostTaskAsync<T>(string httpUrl, Dictionary<string, object> parameters, JsonTypeInfo<T>? typeInfo = null)
74+
private static async Task<T> PostTaskAsync<T>(string httpUrl, Dictionary<string, object> parameters, JsonTypeInfo<T>? typeInfo = null, string scheme = null, string token = null)
7175
{
7276
try
7377
{
@@ -78,6 +82,13 @@ private static async Task<T> PostTaskAsync<T>(string httpUrl, Dictionary<string,
7882
});
7983
httpClient.Timeout = TimeSpan.FromSeconds(15);
8084
httpClient.DefaultRequestHeaders.Accept.ParseAdd("text/html, application/xhtml+xml, */*");
85+
86+
if (!string.IsNullOrEmpty(scheme) && !string.IsNullOrEmpty(token))
87+
{
88+
httpClient.DefaultRequestHeaders.Authorization =
89+
new System.Net.Http.Headers.AuthenticationHeaderValue(scheme, token);
90+
}
91+
8192
var parametersJson =
8293
JsonSerializer.Serialize(parameters, HttpParameterJsonContext.Default.DictionaryStringObject);
8394
var stringContent = new StringContent(parametersJson, Encoding.UTF8, "application/json");

src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ public GeneralUpdateBootstrap()
4747
UpdateVersions = processInfo.UpdateVersions,
4848
TempPath = StorageManager.GetTempDirectory("upgrade_temp"),
4949
ReportUrl = processInfo.ReportUrl,
50-
BackupDirectory = processInfo.BackupDirectory
50+
BackupDirectory = processInfo.BackupDirectory,
51+
Scheme = processInfo.Scheme,
52+
Token = processInfo.Token
5153
};
5254
}
5355

src/c#/GeneralUpdate.Core/Strategys/WindowsStrategy.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@ public override void Execute()
7373
}
7474
finally
7575
{
76-
await VersionService.Report(_configinfo.ReportUrl, version.RecordId, status,
77-
version.AppType);
76+
await VersionService.Report(_configinfo.ReportUrl
77+
, version.RecordId
78+
, status
79+
, version.AppType
80+
, _configinfo.Scheme
81+
, _configinfo.Token);
7882
}
7983
}
8084

0 commit comments

Comments
 (0)