From f514750cd0e34dbd4057ecc14c1b684006deed0f Mon Sep 17 00:00:00 2001 From: Johan Forsell Date: Fri, 17 Jun 2016 10:05:33 +0100 Subject: [PATCH] Adding SecurityApi (need to clean up methods). --- .../Api/PodApi/SecurityApi.cs | 124 ++++++++++++++++++ .../Factories/PodApiFactory.cs | 13 ++ .../SymphonyOSS.RestApiClient.csproj | 1 + 3 files changed, 138 insertions(+) create mode 100644 src/SymphonyOSS.RestApiClient/Api/PodApi/SecurityApi.cs diff --git a/src/SymphonyOSS.RestApiClient/Api/PodApi/SecurityApi.cs b/src/SymphonyOSS.RestApiClient/Api/PodApi/SecurityApi.cs new file mode 100644 index 0000000..7021984 --- /dev/null +++ b/src/SymphonyOSS.RestApiClient/Api/PodApi/SecurityApi.cs @@ -0,0 +1,124 @@ +// Licensed to the Symphony Software Foundation (SSF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SSF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace SymphonyOSS.RestApiClient.Api.PodApi +{ + using Authentication; + using Generated.OpenApi.PodApi.Client; + using Generated.OpenApi.PodApi.Model; + + /// + /// Provides methods for managing the company certificates, by encapsulating + /// , + /// adding authentication token management and a custom execution strategy. + /// + public class SecurityApi + { + private readonly Generated.OpenApi.PodApi.Api.SecurityApi _securityApi; + + private readonly IAuthTokens _authTokens; + + private readonly IApiExecutor _apiExecutor; + + /// + /// Initializes a new instance of the class. + /// See for conveniently constructing + /// an instance. + /// + /// Authentication tokens. + /// Api configuration. + /// Execution strategy. + public SecurityApi(IAuthTokens authTokens, Configuration configuration, IApiExecutor apiExecutor) + { + _securityApi = new Generated.OpenApi.PodApi.Api.SecurityApi(configuration); + _authTokens = authTokens; + _apiExecutor = apiExecutor; + } + + /// + /// Create a company trusted or untrusted certificate. + /// + /// Success response. + public SuccessResponse Create(CompanyCert cert) + { + return _apiExecutor.Execute(_securityApi.V1CompanycertCreatePost, _authTokens.SessionToken, cert); + } + + /// + /// Delete a company certificate. + /// + /// Success response. + public SuccessResponse Delete(string fingerPrint) + { + return _apiExecutor.Execute(_securityApi.V1CompanycertDeletePost, _authTokens.SessionToken, new StringId(fingerPrint)); + } + + /// + /// Get the details of a company certificate. + /// + /// Company certificate details. + public CompanyCertDetail Get(string fingerPrint) + { + return _apiExecutor.Execute(_securityApi.V1CompanycertFingerPrintGetGet, fingerPrint, _authTokens.SessionToken); + } + + /// + /// Return a list of all certificates which were verified to the cert whose fingerprint is passed. + /// + /// List of certificates. + public CompanyCertInfoList GetIssued(string fingerPrint) + { + return _apiExecutor.Execute(_securityApi.V1CompanycertFingerPrintIssuedByGet, fingerPrint, _authTokens.SessionToken); + } + + /// + /// Update a company certificate. + /// + /// Success response. + public SuccessResponse Update(string fingerPrint, CompanyCertAttributes certAttributes) + { + return _apiExecutor.Execute(_securityApi.V1CompanycertFingerPrintUpdatePost, fingerPrint, _authTokens.SessionToken, certAttributes); + } + + /// + /// List all trusted certs. + /// + /// List of certificates. + public CompanyCertInfoList Get(int? skip = null, int? limit = null) + { + return _apiExecutor.Execute(_securityApi.V1CompanycertListGet, _authTokens.SessionToken, skip, limit); + } + + /// + /// List all trusted certs. + /// + /// List of certificates. + public CompanyCertInfoList GetPodManaged(int? skip = null, int? limit = null) + { + return _apiExecutor.Execute(_securityApi.V1CompanycertPodmanagedListGet, _authTokens.SessionToken, skip, limit); + } + + /// + /// List all certs of the given types. + /// + /// List of certificates. + public CompanyCertInfoList Get(CompanyCertTypeList typeIdList, int? skip = null, int? limit = null) + { + return _apiExecutor.Execute(_securityApi.V1CompanycertTypeListPost, typeIdList, _authTokens.SessionToken, skip, limit); + } + } +} diff --git a/src/SymphonyOSS.RestApiClient/Factories/PodApiFactory.cs b/src/SymphonyOSS.RestApiClient/Factories/PodApiFactory.cs index b8a1c01..0454702 100644 --- a/src/SymphonyOSS.RestApiClient/Factories/PodApiFactory.cs +++ b/src/SymphonyOSS.RestApiClient/Factories/PodApiFactory.cs @@ -62,6 +62,19 @@ public PresenceApi CreatePresenceApi(SessionManager sessionManager, IApiExecutor return Create(sessionManager, apiExecutor); } + /// + /// Constructs a SecurityApi instance using the provided session manager + /// for authentication. + /// + /// Session manager used for authentication. + /// The executor, if none is provided + /// with a will be used. + /// The SecurityApi instance. + public SecurityApi CreateSecurityApi(SessionManager sessionManager, IApiExecutor apiExecutor = null) + { + return Create(sessionManager, apiExecutor); + } + /// /// Constructs a SessionApi instance using the provided session manager /// for authentication. diff --git a/src/SymphonyOSS.RestApiClient/SymphonyOSS.RestApiClient.csproj b/src/SymphonyOSS.RestApiClient/SymphonyOSS.RestApiClient.csproj index 2825381..77d6001 100644 --- a/src/SymphonyOSS.RestApiClient/SymphonyOSS.RestApiClient.csproj +++ b/src/SymphonyOSS.RestApiClient/SymphonyOSS.RestApiClient.csproj @@ -54,6 +54,7 @@ +