diff --git a/Azaion.CommonSecurity/DTO/ApiConfig.cs b/Azaion.CommonSecurity/DTO/ApiConfig.cs index 849371f..c6d4056 100644 --- a/Azaion.CommonSecurity/DTO/ApiConfig.cs +++ b/Azaion.CommonSecurity/DTO/ApiConfig.cs @@ -5,4 +5,5 @@ public class ApiConfig public string Url { get; set; } = null!; public int RetryCount {get;set;} public double TimeoutSeconds { get; set; } + public string ResourcesFolder { get; set; } = ""; } diff --git a/Azaion.CommonSecurity/Services/AzaionApiClient.cs b/Azaion.CommonSecurity/Services/AzaionApiClient.cs index fda2007..ef6e023 100644 --- a/Azaion.CommonSecurity/Services/AzaionApiClient.cs +++ b/Azaion.CommonSecurity/Services/AzaionApiClient.cs @@ -12,26 +12,26 @@ public class AzaionApiClient(HttpClient httpClient) : IDisposable { const string JSON_MEDIA = "application/json"; + private static ApiConfig _apiConfig = null!; + private string Email { get; set; } = null!; private SecureString Password { get; set; } = new(); - private string JwtToken { get; set; } = null!; public User User { get; set; } = null!; public static AzaionApiClient Create(ApiCredentials credentials) { - ApiConfig apiConfig; try { if (!File.Exists(SecurityConstants.CONFIG_PATH)) throw new FileNotFoundException(SecurityConstants.CONFIG_PATH); var configStr = File.ReadAllText(SecurityConstants.CONFIG_PATH); - apiConfig = JsonConvert.DeserializeObject(configStr)!.ApiConfig; + _apiConfig = JsonConvert.DeserializeObject(configStr)!.ApiConfig; } catch (Exception e) { Console.WriteLine(e); - apiConfig = new ApiConfig + _apiConfig = new ApiConfig { Url = SecurityConstants.DEFAULT_API_URL, RetryCount = SecurityConstants.DEFAULT_API_RETRY_COUNT , @@ -41,8 +41,8 @@ public class AzaionApiClient(HttpClient httpClient) : IDisposable var api = new AzaionApiClient(new HttpClient { - BaseAddress = new Uri(apiConfig.Url), - Timeout = TimeSpan.FromSeconds(apiConfig.TimeoutSeconds) + BaseAddress = new Uri(_apiConfig.Url), + Timeout = TimeSpan.FromSeconds(_apiConfig.TimeoutSeconds) }); api.EnterCredentials(credentials); @@ -60,7 +60,7 @@ public class AzaionApiClient(HttpClient httpClient) : IDisposable public async Task GetResource(string fileName, string password, HardwareInfo hardware) { - var response = await Send(httpClient, new HttpRequestMessage(HttpMethod.Post, "/resources/get") + var response = await Send(httpClient, new HttpRequestMessage(HttpMethod.Post, $"/resources/get/{_apiConfig.ResourcesFolder}") { Content = new StringContent(JsonConvert.SerializeObject(new { fileName, password, hardware }), Encoding.UTF8, JSON_MEDIA) }); diff --git a/Azaion.Suite/config.json b/Azaion.Suite/config.json index 117c776..61436ee 100644 --- a/Azaion.Suite/config.json +++ b/Azaion.Suite/config.json @@ -3,6 +3,7 @@ "Url": "https://api.azaion.com/", "RetryCount": 3, "TimeoutSeconds": 40.0, + "ResourcesFolder": "stage", "TokenFile": "token.txt" }, "DirectoriesConfig": { diff --git a/Azaion.Suite/upload.cmd b/Azaion.Suite/upload.cmd index 1ba2be7..0a371f9 100644 --- a/Azaion.Suite/upload.cmd +++ b/Azaion.Suite/upload.cmd @@ -3,6 +3,7 @@ set CONFIG=%1 @echo off set API_URL=https://api.azaion.com +set RESOURCES_FOLDER=stage set EMAIL=uploader@azaion.com set PASSWORD=Az@1on_10Upl0@der @@ -28,12 +29,12 @@ for /f "tokens=2 delims=:" %%a in ('echo %RESPONSE% ^| findstr /i "token"') do ( echo Uploading files to resources... -curl --location %API_URL%/resources ^ +curl --location %API_URL%/resources/%RESOURCES_FOLDER% ^ -H "Authorization: Bearer %TOKEN%" ^ -H "Content-Type: multipart/form-data" ^ --form "data=@%FILE1_TO_UPLOAD%" -curl --location %API_URL%/resources ^ +curl --location %API_URL%/resources/%RESOURCES_FOLDER% ^ -H "Authorization: Bearer %TOKEN%" ^ -H "Content-Type: multipart/form-data" ^ --form "data=@%FILE2_TO_UPLOAD%"