-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to newly built API from GH Run 145
- Loading branch information
1 parent
fb28ce3
commit ed4245c
Showing
250 changed files
with
24,984 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<PackOnBuild>true</PackOnBuild> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="System.Net.Http" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="System.Net.Http" Version="4.3.4" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Large diffs are not rendered by default.
Oops, something went wrong.
181 changes: 181 additions & 0 deletions
181
Client/Com/Cumulocity/Client/Api/ApplicationBinariesApi.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
/// | ||
/// ApplicationBinariesApi.cs | ||
/// CumulocityCoreLibrary | ||
/// | ||
/// Copyright (c) 2014-2022 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors. | ||
/// Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG. | ||
/// | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using System.Web; | ||
using Com.Cumulocity.Client.Model; | ||
using Com.Cumulocity.Client.Supplementary; | ||
|
||
namespace Com.Cumulocity.Client.Api | ||
{ | ||
/// <summary> | ||
/// An API method to upload an application binary. It is a deployable microservice or web application. | ||
/// </summary> | ||
#nullable enable | ||
public class ApplicationBinariesApi : AdaptableApi | ||
{ | ||
public ApplicationBinariesApi(HttpClient httpClient) : base(httpClient) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Retrieve all application attachments<br/> | ||
/// Retrieve all application attachments. This method is not supported by microservice applications. <section><h5>Required roles</h5> ROLE_APPLICATION_MANAGEMENT_ADMIN </section> | ||
/// <br>The following table gives an overview of the possible response codes and their meanings:</br> | ||
/// <list type="bullet"> | ||
/// <item> | ||
/// <term>HTTP 200</term> | ||
/// <description>The request has succeeded and the application attachments are sent in the response.</description> | ||
/// </item> | ||
/// <item> | ||
/// <term>HTTP 401</term> | ||
/// <description>Authentication information is missing or invalid.</description> | ||
/// </item> | ||
/// <item> | ||
/// <term>HTTP 404</term> | ||
/// <description>Application not found.</description> | ||
/// </item> | ||
/// </list> | ||
/// </summary> | ||
/// <param name="id">Unique identifier of the application.</param> | ||
/// <returns></returns> | ||
public async Task<ApplicationBinaries?> GetApplicationAttachments(string id) | ||
{ | ||
var client = HttpClient; | ||
var uriBuilder = new UriBuilder(new Uri($"{client?.BaseAddress?.AbsoluteUri}/application/applications/{id}/binaries")); | ||
var request = new HttpRequestMessage | ||
{ | ||
Method = HttpMethod.Get, | ||
RequestUri = new Uri(uriBuilder.ToString()) | ||
}; | ||
request.Headers.TryAddWithoutValidation("Accept", "application/vnd.com.nsn.cumulocity.applicationbinaries+json, application/vnd.com.nsn.cumulocity.error+json"); | ||
var response = await client.SendAsync(request); | ||
response.EnsureSuccessStatusCode(); | ||
using var responseStream = await response.Content.ReadAsStreamAsync(); | ||
return await JsonSerializer.DeserializeAsync<ApplicationBinaries?>(responseStream); | ||
} | ||
|
||
/// <summary> | ||
/// Upload an application attachment<br/> | ||
/// Upload an application attachment (by a given application ID). For the applications of type “microservice” and “web application” to be available for Cumulocity IoT platform users, an attachment ZIP file must be uploaded. For a microservice application, the ZIP file must consist of: * cumulocity.json - file describing the deployment * image.tar - executable Docker image For a web application, the ZIP file must include an index.html file in the root directory. <section><h5>Required roles</h5> ROLE_APPLICATION_MANAGEMENT_ADMIN <b>AND</b> tenant is the owner of the application </section> | ||
/// <br>The following table gives an overview of the possible response codes and their meanings:</br> | ||
/// <list type="bullet"> | ||
/// <item> | ||
/// <term>HTTP 201</term> | ||
/// <description>The application attachments have been uploaded.</description> | ||
/// </item> | ||
/// <item> | ||
/// <term>HTTP 401</term> | ||
/// <description>Authentication information is missing or invalid.</description> | ||
/// </item> | ||
/// </list> | ||
/// </summary> | ||
/// <param name="file">The ZIP file to be uploaded.</param> | ||
/// <param name="id">Unique identifier of the application.</param> | ||
/// <returns></returns> | ||
public async Task<Application?> UploadApplicationAttachment(byte[] file, string id) | ||
{ | ||
var client = HttpClient; | ||
var uriBuilder = new UriBuilder(new Uri($"{client?.BaseAddress?.AbsoluteUri}/application/applications/{id}/binaries")); | ||
var requestContent = new MultipartFormDataContent(); | ||
var fileContentFile = new ByteArrayContent(file); | ||
fileContentFile.Headers.ContentType = MediaTypeHeaderValue.Parse("application/zip"); | ||
requestContent.Add(fileContentFile, "file"); | ||
var request = new HttpRequestMessage | ||
{ | ||
Content = requestContent, | ||
Method = HttpMethod.Post, | ||
RequestUri = new Uri(uriBuilder.ToString()) | ||
}; | ||
request.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data"); | ||
request.Headers.TryAddWithoutValidation("Accept", "application/vnd.com.nsn.cumulocity.error+json, application/vnd.com.nsn.cumulocity.application+json"); | ||
var response = await client.SendAsync(request); | ||
response.EnsureSuccessStatusCode(); | ||
using var responseStream = await response.Content.ReadAsStreamAsync(); | ||
return await JsonSerializer.DeserializeAsync<Application?>(responseStream); | ||
} | ||
|
||
/// <summary> | ||
/// Retrieve a specific application attachment<br/> | ||
/// Retrieve a specific application attachment (by a given application ID and a given binary ID). This method is not supported by microservice applications. <section><h5>Required roles</h5> ROLE_APPLICATION_MANAGEMENT_ADMIN </section> | ||
/// <br>The following table gives an overview of the possible response codes and their meanings:</br> | ||
/// <list type="bullet"> | ||
/// <item> | ||
/// <term>HTTP 200</term> | ||
/// <description>The request has succeeded and the application attachment is sent as a ZIP file in the response.</description> | ||
/// </item> | ||
/// <item> | ||
/// <term>HTTP 401</term> | ||
/// <description>Authentication information is missing or invalid.</description> | ||
/// </item> | ||
/// </list> | ||
/// </summary> | ||
/// <param name="id">Unique identifier of the application.</param> | ||
/// <param name="binaryId">Unique identifier of the binary.</param> | ||
public async Task<System.IO.Stream> GetApplicationAttachment(string id, string binaryId) | ||
{ | ||
var client = HttpClient; | ||
var uriBuilder = new UriBuilder(new Uri($"{client?.BaseAddress?.AbsoluteUri}/application/applications/{id}/binaries/{binaryId}")); | ||
var request = new HttpRequestMessage | ||
{ | ||
Method = HttpMethod.Get, | ||
RequestUri = new Uri(uriBuilder.ToString()) | ||
}; | ||
request.Headers.TryAddWithoutValidation("Accept", "application/vnd.com.nsn.cumulocity.error+json, application/zip"); | ||
var response = await client.SendAsync(request); | ||
response.EnsureSuccessStatusCode(); | ||
using var responseStream = await response.Content.ReadAsStreamAsync(); | ||
return responseStream; | ||
} | ||
|
||
/// <summary> | ||
/// Delete a specific application attachment<br/> | ||
/// Delete a specific application attachment (by a given application ID and a given binary ID). This method is not supported by microservice applications. <section><h5>Required roles</h5> ROLE_APPLICATION_MANAGEMENT_ADMIN <b>AND</b> tenant is the owner of the application </section> | ||
/// <br>The following table gives an overview of the possible response codes and their meanings:</br> | ||
/// <list type="bullet"> | ||
/// <item> | ||
/// <term>HTTP 204</term> | ||
/// <description>An application binary was removed.</description> | ||
/// </item> | ||
/// <item> | ||
/// <term>HTTP 401</term> | ||
/// <description>Authentication information is missing or invalid.</description> | ||
/// </item> | ||
/// <item> | ||
/// <term>HTTP 403</term> | ||
/// <description>Not authorized to perform this operation.</description> | ||
/// </item> | ||
/// </list> | ||
/// </summary> | ||
/// <param name="id">Unique identifier of the application.</param> | ||
/// <param name="binaryId">Unique identifier of the binary.</param> | ||
public async Task<System.IO.Stream> DeleteApplicationAttachment(string id, string binaryId) | ||
{ | ||
var client = HttpClient; | ||
var uriBuilder = new UriBuilder(new Uri($"{client?.BaseAddress?.AbsoluteUri}/application/applications/{id}/binaries/{binaryId}")); | ||
var request = new HttpRequestMessage | ||
{ | ||
Method = HttpMethod.Delete, | ||
RequestUri = new Uri(uriBuilder.ToString()) | ||
}; | ||
request.Headers.TryAddWithoutValidation("Accept", "application/json"); | ||
var response = await client.SendAsync(request); | ||
response.EnsureSuccessStatusCode(); | ||
using var responseStream = await response.Content.ReadAsStreamAsync(); | ||
return responseStream; | ||
} | ||
} | ||
#nullable disable | ||
} |
Oops, something went wrong.