Skip to content

Commit

Permalink
Features/automatic update (#7)
Browse files Browse the repository at this point in the history
* Update to newly built API from GH Run 117

* Update to newly built API from GH Run 121

* Update to newly built API from GH Run 128

* Update to newly built API from GH Run 129

* Update to newly built API from GH Run 134

Co-authored-by: OpenApi-Bot <OpenApi-Bot@users.noreply.github.com>
  • Loading branch information
joerghartmann and openapi-bot committed Aug 5, 2022
1 parent 54da278 commit 4c17262
Show file tree
Hide file tree
Showing 18 changed files with 803 additions and 72 deletions.
18 changes: 9 additions & 9 deletions Sources/CumulocityCoreLibrary/Api/AlarmsApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class AlarmsApi: AdaptableApi {
/// - status
/// The status of the alarm to search for.
/// - type
/// The type of alarm to search for.
/// The types of alarm to search for (comma separated).
/// - withSourceAssets
/// When set to `true` also alarms for related source assets will be included in the request. When this parameter is provided a `source` must be specified.
/// - withSourceDevices
Expand All @@ -67,7 +67,7 @@ public class AlarmsApi: AdaptableApi {
/// When set to `true`, the returned result will contain in the statistics object the total number of elements. Only applicable on [range queries](https://en.wikipedia.org/wiki/Range_query_(database)).
/// - withTotalPages
/// When set to `true`, the returned result will contain in the statistics object the total number of pages. Only applicable on [range queries](https://en.wikipedia.org/wiki/Range_query_(database)).
public func getAlarms(createdFrom: String? = nil, createdTo: String? = nil, currentPage: Int? = nil, dateFrom: String? = nil, dateTo: String? = nil, lastUpdatedFrom: String? = nil, lastUpdatedTo: String? = nil, pageSize: Int? = nil, resolved: Bool? = nil, severity: String? = nil, source: String? = nil, status: String? = nil, type: String? = nil, withSourceAssets: Bool? = nil, withSourceDevices: Bool? = nil, withTotalElements: Bool? = nil, withTotalPages: Bool? = nil) throws -> AnyPublisher<C8yAlarmCollection, Swift.Error> {
public func getAlarms(createdFrom: String? = nil, createdTo: String? = nil, currentPage: Int? = nil, dateFrom: String? = nil, dateTo: String? = nil, lastUpdatedFrom: String? = nil, lastUpdatedTo: String? = nil, pageSize: Int? = nil, resolved: Bool? = nil, severity: String? = nil, source: String? = nil, status: String? = nil, type: [String]? = nil, withSourceAssets: Bool? = nil, withSourceDevices: Bool? = nil, withTotalElements: Bool? = nil, withTotalPages: Bool? = nil) throws -> AnyPublisher<C8yAlarmCollection, Swift.Error> {
var queryItems: [URLQueryItem] = []
if let parameter = createdFrom { queryItems.append(URLQueryItem(name: "createdFrom", value: String(parameter))) }
if let parameter = createdTo { queryItems.append(URLQueryItem(name: "createdTo", value: String(parameter))) }
Expand All @@ -81,7 +81,7 @@ public class AlarmsApi: AdaptableApi {
if let parameter = severity { queryItems.append(URLQueryItem(name: "severity", value: String(parameter))) }
if let parameter = source { queryItems.append(URLQueryItem(name: "source", value: String(parameter))) }
if let parameter = status { queryItems.append(URLQueryItem(name: "status", value: String(parameter))) }
if let parameter = type { queryItems.append(URLQueryItem(name: "type", value: String(parameter))) }
if let parameter = type { parameter.forEach{ p in queryItems.append(URLQueryItem(name: "type", value: p)) } }
if let parameter = withSourceAssets { queryItems.append(URLQueryItem(name: "withSourceAssets", value: String(parameter))) }
if let parameter = withSourceDevices { queryItems.append(URLQueryItem(name: "withSourceDevices", value: String(parameter))) }
if let parameter = withTotalElements { queryItems.append(URLQueryItem(name: "withTotalElements", value: String(parameter))) }
Expand Down Expand Up @@ -323,12 +323,12 @@ public class AlarmsApi: AdaptableApi {
/// - status
/// The status of the alarm to search for.
/// - type
/// The type of alarm to search for.
/// The types of alarm to search for (comma separated).
/// - withSourceAssets
/// When set to `true` also alarms for related source assets will be included in the request. When this parameter is provided a `source` must be specified.
/// - withSourceDevices
/// When set to `true` also alarms for related source devices will be included in the request. When this parameter is provided a `source` must be specified.
public func deleteAlarms(createdFrom: String? = nil, createdTo: String? = nil, dateFrom: String? = nil, dateTo: String? = nil, resolved: Bool? = nil, severity: String? = nil, source: String? = nil, status: String? = nil, type: String? = nil, withSourceAssets: Bool? = nil, withSourceDevices: Bool? = nil) throws -> AnyPublisher<Data, Swift.Error> {
public func deleteAlarms(createdFrom: String? = nil, createdTo: String? = nil, dateFrom: String? = nil, dateTo: String? = nil, resolved: Bool? = nil, severity: String? = nil, source: String? = nil, status: String? = nil, type: [String]? = nil, withSourceAssets: Bool? = nil, withSourceDevices: Bool? = nil) throws -> AnyPublisher<Data, Swift.Error> {
var queryItems: [URLQueryItem] = []
if let parameter = createdFrom { queryItems.append(URLQueryItem(name: "createdFrom", value: String(parameter))) }
if let parameter = createdTo { queryItems.append(URLQueryItem(name: "createdTo", value: String(parameter))) }
Expand All @@ -338,7 +338,7 @@ public class AlarmsApi: AdaptableApi {
if let parameter = severity { queryItems.append(URLQueryItem(name: "severity", value: String(parameter))) }
if let parameter = source { queryItems.append(URLQueryItem(name: "source", value: String(parameter))) }
if let parameter = status { queryItems.append(URLQueryItem(name: "status", value: String(parameter))) }
if let parameter = type { queryItems.append(URLQueryItem(name: "type", value: String(parameter))) }
if let parameter = type { parameter.forEach{ p in queryItems.append(URLQueryItem(name: "type", value: p)) } }
if let parameter = withSourceAssets { queryItems.append(URLQueryItem(name: "withSourceAssets", value: String(parameter))) }
if let parameter = withSourceDevices { queryItems.append(URLQueryItem(name: "withSourceDevices", value: String(parameter))) }
let builder = URLRequestBuilder()
Expand Down Expand Up @@ -517,20 +517,20 @@ public class AlarmsApi: AdaptableApi {
/// - status
/// The status of the alarm to search for.
/// - type
/// The type of alarm to search for.
/// The types of alarm to search for (comma separated).
/// - withSourceAssets
/// When set to `true` also alarms for related source assets will be included in the request. When this parameter is provided a `source` must be specified.
/// - withSourceDevices
/// When set to `true` also alarms for related source devices will be included in the request. When this parameter is provided a `source` must be specified.
public func getNumberOfAlarms(dateFrom: String? = nil, dateTo: String? = nil, resolved: Bool? = nil, severity: String? = nil, source: String? = nil, status: String? = nil, type: String? = nil, withSourceAssets: Bool? = nil, withSourceDevices: Bool? = nil) throws -> AnyPublisher<Int, Swift.Error> {
public func getNumberOfAlarms(dateFrom: String? = nil, dateTo: String? = nil, resolved: Bool? = nil, severity: String? = nil, source: String? = nil, status: String? = nil, type: [String]? = nil, withSourceAssets: Bool? = nil, withSourceDevices: Bool? = nil) throws -> AnyPublisher<Int, Swift.Error> {
var queryItems: [URLQueryItem] = []
if let parameter = dateFrom { queryItems.append(URLQueryItem(name: "dateFrom", value: String(parameter))) }
if let parameter = dateTo { queryItems.append(URLQueryItem(name: "dateTo", value: String(parameter))) }
if let parameter = resolved { queryItems.append(URLQueryItem(name: "resolved", value: String(parameter))) }
if let parameter = severity { queryItems.append(URLQueryItem(name: "severity", value: String(parameter))) }
if let parameter = source { queryItems.append(URLQueryItem(name: "source", value: String(parameter))) }
if let parameter = status { queryItems.append(URLQueryItem(name: "status", value: String(parameter))) }
if let parameter = type { queryItems.append(URLQueryItem(name: "type", value: String(parameter))) }
if let parameter = type { parameter.forEach{ p in queryItems.append(URLQueryItem(name: "type", value: p)) } }
if let parameter = withSourceAssets { queryItems.append(URLQueryItem(name: "withSourceAssets", value: String(parameter))) }
if let parameter = withSourceDevices { queryItems.append(URLQueryItem(name: "withSourceDevices", value: String(parameter))) }
let builder = URLRequestBuilder()
Expand Down
5 changes: 1 addition & 4 deletions Sources/CumulocityCoreLibrary/Api/AuditsApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public class AuditsApi: AdaptableApi {
/// End date or date and time of the audit record.
/// - pageSize
/// Indicates how many entries of the collection shall be returned. The upper limit for one page is 2,000 objects.
/// - revert
/// When set to `true` the results will be sorted in the opposite way, that is, to get the latest records first. Unless [range queries](https://en.wikipedia.org/wiki/Range_query_(database)) are used, by default results are sorted by ID.
/// - source
/// The platform component ID to which the audit is associated.
/// - type
Expand All @@ -54,14 +52,13 @@ public class AuditsApi: AdaptableApi {
/// When set to `true`, the returned result will contain in the statistics object the total number of elements. Only applicable on [range queries](https://en.wikipedia.org/wiki/Range_query_(database)).
/// - withTotalPages
/// When set to `true`, the returned result will contain in the statistics object the total number of pages. Only applicable on [range queries](https://en.wikipedia.org/wiki/Range_query_(database)).
public func getAuditRecords(application: String? = nil, currentPage: Int? = nil, dateFrom: String? = nil, dateTo: String? = nil, pageSize: Int? = nil, revert: Bool? = nil, source: String? = nil, type: String? = nil, user: String? = nil, withTotalElements: Bool? = nil, withTotalPages: Bool? = nil) throws -> AnyPublisher<C8yAuditRecordCollection, Swift.Error> {
public func getAuditRecords(application: String? = nil, currentPage: Int? = nil, dateFrom: String? = nil, dateTo: String? = nil, pageSize: Int? = nil, source: String? = nil, type: String? = nil, user: String? = nil, withTotalElements: Bool? = nil, withTotalPages: Bool? = nil) throws -> AnyPublisher<C8yAuditRecordCollection, Swift.Error> {
var queryItems: [URLQueryItem] = []
if let parameter = application { queryItems.append(URLQueryItem(name: "application", value: String(parameter))) }
if let parameter = currentPage { queryItems.append(URLQueryItem(name: "currentPage", value: String(parameter))) }
if let parameter = dateFrom { queryItems.append(URLQueryItem(name: "dateFrom", value: String(parameter))) }
if let parameter = dateTo { queryItems.append(URLQueryItem(name: "dateTo", value: String(parameter))) }
if let parameter = pageSize { queryItems.append(URLQueryItem(name: "pageSize", value: String(parameter))) }
if let parameter = revert { queryItems.append(URLQueryItem(name: "revert", value: String(parameter))) }
if let parameter = source { queryItems.append(URLQueryItem(name: "source", value: String(parameter))) }
if let parameter = type { queryItems.append(URLQueryItem(name: "type", value: String(parameter))) }
if let parameter = user { queryItems.append(URLQueryItem(name: "user", value: String(parameter))) }
Expand Down
60 changes: 56 additions & 4 deletions Sources/CumulocityCoreLibrary/Api/LoginOptionsApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public class LoginOptionsApi: AdaptableApi {
/// - 400
/// Bad request – invalid parameters.
/// - Parameters:
/// - tenantId
/// Unique identifier of a Cumulocity IoT tenant.
/// - management
/// If this is set to `true`, the management tenant login options will be returned. > **&#9432; Info:** The `tenantId` parameter must not be present in the request when using the `management` parameter, otherwise it will cause an error.
public func getLoginOptions(tenantId: String? = nil, management: Bool? = nil) throws -> AnyPublisher<C8yLoginOptionCollection, Swift.Error> {
/// - tenantId
/// Unique identifier of a Cumulocity IoT tenant.
public func getLoginOptions(management: Bool? = nil, tenantId: String? = nil) throws -> AnyPublisher<C8yLoginOptionCollection, Swift.Error> {
var queryItems: [URLQueryItem] = []
if let parameter = tenantId { queryItems.append(URLQueryItem(name: "tenantId", value: String(parameter))) }
if let parameter = management { queryItems.append(URLQueryItem(name: "management", value: String(parameter))) }
if let parameter = tenantId { queryItems.append(URLQueryItem(name: "tenantId", value: String(parameter))) }
let builder = URLRequestBuilder()
.set(resourcePath: "/tenant/loginOptions")
.set(httpMethod: "get")
Expand All @@ -55,4 +55,56 @@ public class LoginOptionsApi: AdaptableApi {
return element.data
}).decode(type: C8yLoginOptionCollection.self, decoder: JSONDecoder()).eraseToAnyPublisher()
}

/// Create a login option
/// Create an authentication configuration on your tenant.
///
/// <section><h5>Required roles</h5>
/// ROLE_TENANT_ADMIN <b>OR</b> ROLE_TENANT_MANAGEMENT_ADMIN
/// </section>
///
/// The following table gives an overview of the possible response codes and their meanings.
/// - Returns:
/// - 200
/// A login option was created.
/// - 400
/// Duplicated – The login option already exists.
/// - 401
/// Authentication information is missing or invalid.
/// - 422
/// Unprocessable Entity – invalid payload.
/// - Parameters:
/// - body
public func createLoginOption(body: C8yAuthConfig) throws -> AnyPublisher<C8yAuthConfig, Swift.Error> {
var requestBody = body
requestBody.`self` = nil
let builder = URLRequestBuilder()
.set(resourcePath: "/tenant/loginOptions")
.set(httpMethod: "post")
.add(header: "Content-Type", value: "application/vnd.com.nsn.cumulocity.authconfig+json")
.add(header: "Accept", value: "application/vnd.com.nsn.cumulocity.error+json, application/vnd.com.nsn.cumulocity.authconfig+json")
.set(httpBody: try JSONEncoder().encode(requestBody))
return self.session.dataTaskPublisher(for: adapt(builder: builder).build()).tryMap({ element -> Data in
guard let httpResponse = element.response as? HTTPURLResponse else {
throw URLError(.badServerResponse)
}
guard httpResponse.statusCode != 400 else {
throw Errors.badResponseError(statusCode: httpResponse.statusCode, reason: "Duplicated – The login option already exists.")
}
guard httpResponse.statusCode != 401 else {
let decoder = JSONDecoder()
let error401 = try decoder.decode(C8yError.self, from: element.data)
throw Errors.badResponseError(statusCode: httpResponse.statusCode, reason: error401)
}
guard httpResponse.statusCode != 422 else {
throw Errors.badResponseError(statusCode: httpResponse.statusCode, reason: "Unprocessable Entity – invalid payload.")
}
// generic error fallback
guard (200..<300) ~= httpResponse.statusCode else {
throw Errors.undescribedError(statusCode: httpResponse.statusCode, response: httpResponse)
}

return element.data
}).decode(type: C8yAuthConfig.self, decoder: JSONDecoder()).eraseToAnyPublisher()
}
}
15 changes: 15 additions & 0 deletions Sources/CumulocityCoreLibrary/Api/LoginTokensApi.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// LoginTokensApi.swift
// 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.
//

import Foundation
import Combine

/// API methods to obtain access tokens to the Cumulocity IoT platform in case of OAI-Secure or SSO authentication.
public class LoginTokensApi: AdaptableApi {

}
4 changes: 2 additions & 2 deletions Sources/CumulocityCoreLibrary/Api/RolesApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public class RolesApi: AdaptableApi {
/// The current page of the paginated results.
/// - pageSize
/// Indicates how many entries of the collection shall be returned. The upper limit for one page is 2,000 objects.
public func getGroupRoles(tenantId: String, groupId: Int, currentPage: Int? = nil, pageSize: Int? = nil) throws -> AnyPublisher<[C8yRoleReferenceCollection], Swift.Error> {
public func getGroupRoles(tenantId: String, groupId: Int, currentPage: Int? = nil, pageSize: Int? = nil) throws -> AnyPublisher<C8yRoleReferenceCollection, Swift.Error> {
var queryItems: [URLQueryItem] = []
if let parameter = currentPage { queryItems.append(URLQueryItem(name: "currentPage", value: String(parameter))) }
if let parameter = pageSize { queryItems.append(URLQueryItem(name: "pageSize", value: String(parameter))) }
Expand Down Expand Up @@ -172,7 +172,7 @@ public class RolesApi: AdaptableApi {
}

return element.data
}).decode(type: [C8yRoleReferenceCollection].self, decoder: JSONDecoder()).eraseToAnyPublisher()
}).decode(type: C8yRoleReferenceCollection.self, decoder: JSONDecoder()).eraseToAnyPublisher()
}

/// Assign a role to a specific user group in a specific tenant
Expand Down
41 changes: 41 additions & 0 deletions Sources/CumulocityCoreLibrary/Api/UsersApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -588,4 +588,45 @@ public class UsersApi: AdaptableApi {
return element.data
}).eraseToAnyPublisher()
}

/// Terminate a user's session
/// After logging out, a user has to enter valid credentials again to get access to the platform.
///
/// The request is responsible for removing cookies from the browser and invalidating internal platform access tokens.
///
/// The following table gives an overview of the possible response codes and their meanings.
/// - Returns:
/// - 200
/// The request has succeeded and the user is logged out.
/// - 401
/// Authentication information is missing or invalid.
/// - Parameters:
/// - cookie
/// The authorization cookie storing the access token of the user. This parameter is specific to OAI-Secure authentication.
/// - xXSRFTOKEN
/// Prevents XRSF attack of the authenticated user. This parameter is specific to OAI-Secure authentication.
public func logout(cookie: String? = nil, xXSRFTOKEN: String? = nil) throws -> AnyPublisher<Data, Swift.Error> {
let builder = URLRequestBuilder()
.set(resourcePath: "/user/logout")
.set(httpMethod: "post")
.add(header: "Cookie", value: "\(cookie)")
.add(header: "X-XSRF-TOKEN", value: "\(xXSRFTOKEN)")
.add(header: "Accept", value: "application/json")
return self.session.dataTaskPublisher(for: adapt(builder: builder).build()).tryMap({ element -> Data in
guard let httpResponse = element.response as? HTTPURLResponse else {
throw URLError(.badServerResponse)
}
guard httpResponse.statusCode != 401 else {
let decoder = JSONDecoder()
let error401 = try decoder.decode(C8yError.self, from: element.data)
throw Errors.badResponseError(statusCode: httpResponse.statusCode, reason: error401)
}
// generic error fallback
guard (200..<300) ~= httpResponse.statusCode else {
throw Errors.undescribedError(statusCode: httpResponse.statusCode, response: httpResponse)
}

return element.data
}).eraseToAnyPublisher()
}
}
23 changes: 23 additions & 0 deletions Sources/CumulocityCoreLibrary/Model/C8yAccessToken.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// C8yAccessToken.swift
// 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.
//

import Foundation

/// OAI-Secure access token.
public struct C8yAccessToken: Codable {

/// Access token generated by the Cumulocity IoT platform.
public var accessToken: String?

enum CodingKeys: String, CodingKey {
case accessToken = "access_token"
}

public init() {
}
}
Loading

0 comments on commit 4c17262

Please sign in to comment.