Skip to content

Commit 8668d5e

Browse files
committed
updated shield api routes
1 parent e3133a4 commit 8668d5e

File tree

9 files changed

+38
-21
lines changed

9 files changed

+38
-21
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Shield.Client.Extensions
6+
{
7+
public static class RouteExtensions
8+
{
9+
10+
public static string ToApiRoute(this string path) => $"api{(!path.StartsWith("/") ? "/" : "")}{path}";
11+
}
12+
}

Client/Extensions/ServerSentEvents.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void ProtectSingleFile(string projectKey, string fileBlob, ApplicationCon
9191
{
9292
BeforeConnect?.Invoke();
9393

94-
var taskUrl = $"{_baseUrl}protection/protect/single/sse?projectKey={projectKey}&fileBlob={fileBlob}&onlLog={_defaultLoggerId}";
94+
var taskUrl = $"{_baseUrl}api/protection/protect/single/sse?projectKey={projectKey}&fileBlob={fileBlob}&onlLog={_defaultLoggerId}";
9595

9696
if (configuration is not null)
9797
{
@@ -157,7 +157,7 @@ public async Task ProtectSingleFileAsync(string projectKey, string fileBlob, App
157157

158158
BeforeConnect?.Invoke();
159159

160-
var taskUrl = $"{_baseUrl}protection/protect/single/sse?projectKey={projectKey}&fileBlob={fileBlob}&onlLog={_defaultLoggerId}";
160+
var taskUrl = $"{_baseUrl}api/protection/protect/single/sse?projectKey={projectKey}&fileBlob={fileBlob}&onlLog={_defaultLoggerId}";
161161

162162
if (configuration is not null)
163163
{

Client/ShieldApplication.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Threading.Tasks;
77
using Microsoft.Extensions.Logging;
88
using RestSharp;
9+
using Shield.Client.Extensions;
910
using Shield.Client.Helpers;
1011
using Shield.Client.Models;
1112
using Shield.Client.Models.API.Application;
@@ -47,7 +48,7 @@ public async Task<DirectUploadDto> UploadApplicationDirectlyAsync(string project
4748
{
4849
Parent.CustomLogger?.LogDebug("Initiating the request to upload an application to project.");
4950

50-
var request = new RestRequest("/app/direct")
51+
var request = new RestRequest("/app/direct".ToApiRoute())
5152
.AddJsonBody(projectKey)
5253
.AddFile("file", file.FileContent, file.FileName, MimeTypeMap.GetMimeType(file.FileName))
5354
.AddDependencies(dependencies?.Select(x => (x.FileContent, x.FileName)).ToList());
@@ -79,7 +80,7 @@ public DirectUploadDto UploadApplicationDirectly(string projectKey, ShieldFile f
7980
{
8081
Parent.CustomLogger?.LogDebug("Initiating the request to upload an application to project.");
8182

82-
var request = new RestRequest("/app/direct")
83+
var request = new RestRequest("/app/direct".ToApiRoute())
8384
.AddJsonBody(projectKey)
8485
.AddFile("file", file.FileContent, file.FileName, MimeTypeMap.GetMimeType(file.FileName))
8586
.AddDependencies(dependencies?.Select(x => (x.FileContent, x.FileName)).ToList());
@@ -111,7 +112,7 @@ public async Task<DirectUploadDto> UploadApplicationDirectlyAsync(string project
111112
{
112113
Parent.CustomLogger?.LogDebug("Initiating the request to upload an application to project.");
113114

114-
var request = new RestRequest("/app/direct")
115+
var request = new RestRequest("/app/direct".ToApiRoute())
115116
.AddQueryParameter("projectKey", projectKey)
116117
.AddFileFromPath(filePath)
117118
.AddDependencies(dependenciesPaths);
@@ -144,7 +145,7 @@ public DirectUploadDto UploadApplicationDirectly(string projectKey, string fileP
144145
{
145146
Parent.CustomLogger?.LogDebug("Initiating the request to upload an application to project.");
146147

147-
var request = new RestRequest("/app/direct")
148+
var request = new RestRequest("/app/direct".ToApiRoute())
148149
.AddQueryParameter("projectKey", projectKey)
149150
.AddFileFromPath(filePath)
150151
.AddDependencies(dependenciesPaths);
@@ -227,7 +228,7 @@ internal async Task<MemoryStream> DownloadApplicationAsync(string downloadKey, D
227228

228229
Parent.CustomLogger?.LogDebug("Initiating the request to download an application.");
229230
using var stream = new MemoryStream();
230-
var request = new RestRequest("/app/download")
231+
var request = new RestRequest("/app/download".ToApiRoute())
231232
{
232233
ResponseWriter = async responseStream =>
233234
{
@@ -271,7 +272,7 @@ internal MemoryStream DownloadApplication(string downloadKey, DownloadFormat for
271272

272273
Parent.CustomLogger?.LogDebug("Initiating the request to download an application.");
273274
using var stream = new MemoryStream();
274-
var request = new RestRequest("/app/download")
275+
var request = new RestRequest("/app/download".ToApiRoute())
275276
{
276277
ResponseWriter = responseStream =>
277278
{

Client/ShieldConnector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public ShieldConnector(IRestClient client, ShieldClient parent, string bearerTok
2323
_client = new RestClient(client.BaseUrl ?? throw new InvalidOperationException()) {Authenticator = client.Authenticator, Timeout = 1000 * 60 * 10};
2424
_originalBaseUrl = client.BaseUrl.AbsoluteUri;
2525
//Not required version for logger (Only in dev).
26-
if (!client.BaseUrl.ToString().ToLower().StartsWith("https://api.dotnetsafer.com"))
27-
_client.BaseUrl = new Uri(_client.BaseUrl?.AbsoluteUri.Replace(_client.BaseUrl.PathAndQuery,null) ?? throw new InvalidOperationException());
26+
//if (!client.BaseUrl.ToString().ToLower().StartsWith("https://api.dotnetsafer.com"))
27+
// _client.BaseUrl = new Uri(_client.BaseUrl?.AbsoluteUri.Replace(_client.BaseUrl.PathAndQuery,null) ?? throw new InvalidOperationException());
2828
Parent = parent;
2929
_bearerToken = bearerToken;
3030
_apiVersion = apiVersion;

Client/ShieldProject.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
using System.Threading.Tasks;
33
using Microsoft.Extensions.Logging;
44
using RestSharp;
5+
using Shield.Client.Extensions;
56
using Shield.Client.Models.API.Project;
67

78
namespace Shield.Client
89
{
910
public class ShieldProject
1011
{
1112
private readonly RestClient _client;
13+
1214
public ShieldClient Parent { get; set; }
1315

1416
public ShieldProject(RestClient client, ShieldClient parent)
@@ -36,7 +38,7 @@ public async Task<ProjectDto> FindOrCreateExternalProjectAsync(string projectNam
3638
Parent.CustomLogger?.LogDebug("Initiating the request to find or create external project.");
3739

3840
var request =
39-
new RestRequest("/project/externalProject/{projectName}")
41+
new RestRequest("project/externalProject/{projectName}".ToApiRoute())
4042
.AddUrlSegment("projectName", projectName);
4143

4244
var result = await _client.GetAsync<ProjectDto>(request);
@@ -63,7 +65,7 @@ public ProjectDto FindOrCreateExternalProject(string projectName)
6365
Parent.CustomLogger?.LogDebug("Initiating the request to find or create external project.");
6466

6567
var request =
66-
new RestRequest("/project/externalProject/{projectName}")
68+
new RestRequest("/project/externalProject/{projectName}".ToApiRoute())
6769
.AddUrlSegment("projectName", projectName);
6870

6971
var result = _client.Get<ProjectDto>(request);
@@ -94,7 +96,7 @@ public async Task<ProjectDto> FindByIdOrCreateExternalProjectAsync(string projec
9496
Parent.CustomLogger?.LogDebug("Initiating the request to find or create external project.");
9597

9698
var request =
97-
new RestRequest("/project/externalProject/{projectName}")
99+
new RestRequest("/project/externalProject/{projectName}".ToApiRoute())
98100
.AddUrlSegment("projectName", projectName)
99101
.AddQueryParameter("projectKey", projectKey);
100102

@@ -123,7 +125,7 @@ public ProjectDto FindByIdOrCreateExternalProject(string projectName, string pro
123125
Parent.CustomLogger?.LogDebug("Initiating the request to find or create external project.");
124126

125127
var request =
126-
new RestRequest("/project/externalProject/{projectName}")
128+
new RestRequest("/project/externalProject/{projectName}".ToApiRoute())
127129
.AddUrlSegment("projectName", projectName)
128130
.AddQueryParameter("projectKey", projectKey);
129131

Client/ShieldProtections.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Threading.Tasks;
44
using Microsoft.Extensions.Logging;
55
using RestSharp;
6+
using Shield.Client.Extensions;
67
using Shield.Client.Models.API.Protections;
78

89
namespace Shield.Client
@@ -39,7 +40,7 @@ public List<ProtectionDto> GetProtections(string projectKey)
3940
Parent.CustomLogger?.LogDebug("Initiating the request to get project available protections.");
4041

4142
var request =
42-
new RestRequest("project/{projectKey}/protections/available/")
43+
new RestRequest("project/{projectKey}/protections/available/".ToApiRoute())
4344
.AddUrlSegment("projectKey", projectKey);
4445

4546
var result = _client.Get<List<ProtectionDto>>(request);
@@ -66,7 +67,7 @@ public async Task<List<ProtectionDto>> GetProtectionsAsync(string projectKey)
6667
Parent.CustomLogger?.LogDebug("Initiating the request to get project available protections.");
6768

6869
var request =
69-
new RestRequest("project/{projectKey}/protections/available/")
70+
new RestRequest("project/{projectKey}/protections/available/".ToApiRoute())
7071
.AddUrlSegment("projectKey", projectKey);
7172

7273
var result = await _client.GetAsync<List<ProtectionDto>>(request);

Client/ShieldTasks.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Threading.Tasks;
33
using Microsoft.Extensions.Logging;
44
using RestSharp;
5+
using Shield.Client.Extensions;
56
using Shield.Client.Models;
67
using Shield.Client.Models.API.Application;
78

@@ -52,7 +53,7 @@ public async Task<ProtectionResult> ProtectSingleFileAsync(string projectKey, st
5253
Parent.CustomLogger?.LogDebug("Initiating the request to protect a single file.");
5354

5455
var request =
55-
new RestRequest("/protection/protect/single")
56+
new RestRequest("/protection/protect/single".ToApiRoute())
5657
.AddQueryParameter("projectKey", projectKey)
5758
.AddQueryParameter("fileBlob", fileBlob)
5859
.AddQueryParameter("runKey", runKey)
@@ -113,7 +114,7 @@ public ProtectionResult ProtectSingleFile(string projectKey, string fileBlob, st
113114
Parent.CustomLogger?.LogDebug("Initiating the request to protect a single file.");
114115

115116
var request =
116-
new RestRequest("/protection/protect/single")
117+
new RestRequest("/protection/protect/single".ToApiRoute())
117118
.AddQueryParameter("projectKey", projectKey)
118119
.AddQueryParameter("fileBlob", fileBlob)
119120
.AddQueryParameter("runKey", runKey)

Examples/NetCore.Console.Example/Consumer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal async Task Run()
3131
var dependencies = Directory.GetFiles($"{directory}").ToList();
3232

3333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FeYnyCHLXM4RbWgzugqRMmwzt6qctQ_uPXLfdiSL6Br0Cb5mA45tBwU2hcWfN3wLeCIeIncN1HxOpBBphMjOLP27N39OMf0uFJ4eqvnWC7AM_aEsWGCuse9svxRYSeznFVoU9KaPu_X9geRbBBat35QnDjnzJyHOa30EiK-qnuRlrAX-Qhrm1LTGx0hQY461Yx7hv2tnlT-s2_s41w02DSAlxQsNKrxAH5U1OKUujgLEJNsEONRnD7oYBuu2NisRFg8RWfJi3S6kZS8UjrXR646J7AkBB8R2EUeJULEv1SUoDLTveCl1NyDJQjvhFroQrhKsuT4QTH2Gd8kWcjEfRrm63qjzFMLGDo7JcMCh_O4lXNXdJ6Bk8T3eWdCk1vfUoPeiZ9ppuYtR4XncuNk-93sb3FchU-dNZGlcrq4LEcyn1lNMflCSARfqdbvdwn-4QYu7X03nfZqmQ2mzxmr7aUOu1z2idpvACKKaPJ-G9akWOzfVYPKgH0WA0XH81zE"
3535
, _logger);
3636

3737
var projectTest = await client.Project.FindOrCreateExternalProjectAsync("arg3");
@@ -145,7 +145,7 @@ internal async Task RunWithSse()
145145
_logger.LogInformation("Application Started at {dateTime}", DateTime.UtcNow);
146146

147147
var client = ShieldClient.CreateInstance(
148-
"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI5MWVkZjU4OC1iMmJhLTQ3NDAtOTJkYy1mY2RkMjFmMTI5M2YiLCJqdGkiOiI1ZDJlYTQ4OTk4ZmNmYzM0ZTQ0ODJhMTgwNmNlZTRmNDQ4YjlmN2YzMjUyYTUyY2ZmYmFkZTJkMzc2Yjg4NzM0YThmYWQ4OTVhN2ViYWY0NCIsImlhdCI6MTYyNTI2MDc4NywibmJmIjoxNjI1MjYwNzg3LCJleHAiOjE2NTY3OTY3ODYsInN1YiI6IjkxZWRmMDAzLWVlNjktNDU1Yy1hZWU4LWZlMzQ1ODZhOTdkNiIsInNjb3BlcyI6W119.GKbGITxU_UGSDYC3TA1BMycwgUl08DE2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-fpn0qTazcWGzBM1uzZiOjB2YT-ex_fEIZlWs0gO7TbTVQbs3E9LuLO-HNQz5Q0VQeN9gW1tfW-aB5mIN0T2FNMeECcqT2UQeVD5W1AGU3K4oadOMUMif9Hqujgyi3mXU4zt_EubHZ-A8eLhUDcbP5UdLJE7FeYnyCHLXM4RbWgzugqRMmwzt6qctQ_uPXLfdiSL6Br0Cb5mA45tBwU2hcWfN3wLeCIeIncN1HxOpBBphMjOLP27N39OMf0uFJ4eqvnWC7AM_aEsWGCuse9svxRYSeznFVoU9KaPu_X9geRbBBat35QnDjnzJyHOa30EiK-qnuRlrAX-Qhrm1LTGx0hQY461Yx7hv2tnlT-s2_s41w02DSAlxQsNKrxAH5U1OKUujgLEJNsEONRnD7oYBuu2NisRFg8RWfJi3S6kZS8UjrXR646J7AkBB8R2EUeJULEv1SUoDLTveCl1NyDJQjvhFroQrhKsuT4QTH2Gd8kWcjEfRrm63qjzFMLGDo7JcMCh_O4lXNXdJ6Bk8T3eWdCk1vfUoPeiZ9ppuYtR4XncuNk-93sb3FchU-dNZGlcrq4LEcyn1lNMflCSARfqdbvdwn-4QYu7X03nfZqmQ2mzxmr7aUOu1z2idpvACKKaPJ-G9akWOzfVYPKgH0WA0XH81zE"
149149
, _logger);
150150

151151

Examples/NetCore.Console.Example/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private static async Task Main(string[] args)
2222
await using var serviceProvider = services.BuildServiceProvider();
2323
var app = serviceProvider.GetService<Consumer>();
2424
// ReSharper disable once PossibleNullReferenceException
25-
await app?.RunWithSse();
25+
await app.Run();
2626
}
2727
private static void ConfigureServices(IServiceCollection services)
2828
{

0 commit comments

Comments
 (0)