From 8b249a6def2dc8423130758d90ed33cc0298d57c Mon Sep 17 00:00:00 2001 From: Ajiemar Santiago Date: Wed, 11 Jul 2018 15:39:30 -0500 Subject: [PATCH 1/8] feat(datamodel): Add datamodels for Credentials operations --- Scripts/Services/Discovery/v1/DataModels.cs | 541 ++++++++++++++++++++ 1 file changed, 541 insertions(+) diff --git a/Scripts/Services/Discovery/v1/DataModels.cs b/Scripts/Services/Discovery/v1/DataModels.cs index 88de91272..c99b278a2 100644 --- a/Scripts/Services/Discovery/v1/DataModels.cs +++ b/Scripts/Services/Discovery/v1/DataModels.cs @@ -16,6 +16,9 @@ */ using FullSerializer; +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; using System.Text; namespace IBM.Watson.DeveloperCloud.Services.Discovery.v1 @@ -322,6 +325,11 @@ public class Configuration /// An array describing the configuration's document normalization settings. /// public NormalizationOperation[] normalizations { get; set; } + /// + /// Object containing source parameters for the configuration. + /// + [fsProperty("source")] + public Source Source { get; set; } } /// @@ -776,6 +784,11 @@ public class Collection /// Object providing information about the documents in the collection. /// public DocumentCounts document_counts { get; set; } + /// + /// Object containing source crawl status information. + /// + [fsProperty("source_crawl")] + public SourceStatus SourceCrawl { get; set; } } /// @@ -917,6 +930,12 @@ public class QueryResponse /// Query aggregations. /// public QueryAggregation aggregations { get; set; } + /// + /// The session token for this query. The session token can be used to add events associated with this query to + /// the query and event log. + /// + [fsProperty("session_token")] + public string SessionToken { get; set; } public override string ToString() { @@ -965,6 +984,24 @@ public class QueryResult public double score { get; set; } } + /// + /// Metadata of a query result. + /// + [fsObject] + public class QueryResultResultMetadata + { + /// + /// The raw score of the result. A higher score indicates a greater match to the query parameters. + /// + [fsProperty("score")] + public double? Score { get; set; } + /// + /// The confidence score of the result's analysis. A higher score indicates greater confidence. + /// + [fsProperty("confidence")] + public double? Confidence { get; set; } + } + /// /// Query aggregation. /// @@ -1005,4 +1042,508 @@ public class AggregationResult public double matching_results { get; set; } } #endregion + + #region Credentials + [fsObject] + /// + /// CredentialsList. + /// + public class CredentialsList + { + /// + /// An array of credential definitions that were created for this instance. + /// + [fsProperty("credentials")] + public List Credentials { get; set; } + } + + [fsObject] + /// + /// Object containing credential information. + /// + public class Credentials + { + /// + /// The source that this credentials object connects to. + /// - `box` indicates the credentials are used to connect an instance of Enterprise Box. + /// - `salesforce` indicates the credentials are used to connect to Salesforce. + /// - `sharepoint` indicates the credentials are used to connect to Microsoft SharePoint Online. + /// + public enum SourceTypeEnum + { + + /// + /// Enum BOX for box + /// + [EnumMember(Value = "box")] + BOX, + + /// + /// Enum SALESFORCE for salesforce + /// + [EnumMember(Value = "salesforce")] + SALESFORCE, + + /// + /// Enum SHAREPOINT for sharepoint + /// + [EnumMember(Value = "sharepoint")] + SHAREPOINT + } + + /// + /// The source that this credentials object connects to. + /// - `box` indicates the credentials are used to connect an instance of Enterprise Box. + /// - `salesforce` indicates the credentials are used to connect to Salesforce. + /// - `sharepoint` indicates the credentials are used to connect to Microsoft SharePoint Online. + /// + [fsProperty("source_type")] + public SourceTypeEnum? SourceType { get; set; } + /// + /// Unique identifier for this set of credentials. + /// + [fsProperty("credential_id")] + public virtual string CredentialId { get; private set; } + /// + /// Object containing details of the stored credentials. + /// + /// Obtain credentials for your source from the administrator of the source. + /// + [fsProperty("credential_details")] + public CredentialDetails CredentialDetails { get; set; } + } + + + [fsObject] + /// + /// Object containing details of the stored credentials. + /// + /// Obtain credentials for your source from the administrator of the source. + /// + public class CredentialDetails + { + /// + /// The authentication method for this credentials definition. The **credential_type** specified must be + /// supported by the **source_type**. The following combinations are possible: + /// + /// - `\"source_type\": \"box\"` - valid `credential_type`s: `oauth2` + /// - `\"source_type\": \"salesforce\"` - valid `credential_type`s: `username_password` + /// - `\"source_type\": \"sharepoint\"` - valid `credential_type`s: `saml`. + /// + public enum CredentialTypeEnum + { + + /// + /// Enum OAUTH2 for oauth2 + /// + [EnumMember(Value = "oauth2")] + OAUTH2, + + /// + /// Enum SAML for saml + /// + [EnumMember(Value = "saml")] + SAML, + + /// + /// Enum USERNAME_PASSWORD for username_password + /// + [EnumMember(Value = "username_password")] + USERNAME_PASSWORD + } + + /// + /// The authentication method for this credentials definition. The **credential_type** specified must be + /// supported by the **source_type**. The following combinations are possible: + /// + /// - `\"source_type\": \"box\"` - valid `credential_type`s: `oauth2` + /// - `\"source_type\": \"salesforce\"` - valid `credential_type`s: `username_password` + /// - `\"source_type\": \"sharepoint\"` - valid `credential_type`s: `saml`. + /// + [fsProperty("credential_type")] + public CredentialTypeEnum? CredentialType { get; set; } + /// + /// The **client_id** of the source that these credentials connect to. Only valid, and required, with a + /// **credential_type** of `oauth2`. + /// + [fsProperty("client_id")] + public string ClientId { get; set; } + /// + /// The **enterprise_id** of the Box site that these credentials connect to. Only valid, and required, with a + /// **source_type** of `box`. + /// + [fsProperty("enterprise_id")] + public string EnterpriseId { get; set; } + /// + /// The **url** of the source that these credentials connect to. Only valid, and required, with a + /// **credential_type** of `username_password`. + /// + [fsProperty("url")] + public string Url { get; set; } + /// + /// The **username** of the source that these credentials connect to. Only valid, and required, with a + /// **credential_type** of `saml` and `username_password`. + /// + [fsProperty("username")] + public string Username { get; set; } + /// + /// The **organization_url** of the source that these credentials connect to. Only valid, and required, with a + /// **credential_type** of `saml`. + /// + [fsProperty("organization_url")] + public string OrganizationUrl { get; set; } + /// + /// The **site_collection.path** of the source that these credentials connect to. Only valid, and required, with + /// a **source_type** of `sharepoint`. + /// + [fsProperty("site_collection.path")] + public string SiteCollectionPath { get; set; } + /// + /// The **client_secret** of the source that these credentials connect to. Only valid, and required, with a + /// **credential_type** of `oauth2`. This value is never returned and is only used when creating or modifying + /// **credentials**. + /// + [fsProperty("client_secret")] + public string ClientSecret { get; set; } + /// + /// The **public_key_id** of the source that these credentials connect to. Only valid, and required, with a + /// **credential_type** of `oauth2`. This value is never returned and is only used when creating or modifying + /// **credentials**. + /// + [fsProperty("public_key_id")] + public string PublicKeyId { get; set; } + /// + /// The **private_key** of the source that these credentials connect to. Only valid, and required, with a + /// **credential_type** of `oauth2`. This value is never returned and is only used when creating or modifying + /// **credentials**. + /// + [fsProperty("private_key")] + public string PrivateKey { get; set; } + /// + /// The **passphrase** of the source that these credentials connect to. Only valid, and required, with a + /// **credential_type** of `oauth2`. This value is never returned and is only used when creating or modifying + /// **credentials**. + /// + [fsProperty("passphrase")] + public string Passphrase { get; set; } + /// + /// The **password** of the source that these credentials connect to. Only valid, and required, with + /// **credential_type**s of `saml` and `username_password`. + /// + /// **Note:** When used with a **source_type** of `salesforce`, the password consists of the Salesforce password + /// and a valid Salesforce security token concatenated. This value is never returned and is only used when + /// creating or modifying **credentials**. + /// + [fsProperty("password")] + public string Password { get; set; } + } + + [fsObject] + /// + /// Object returned after credentials are deleted. + /// + public class DeleteCredentials + { + /// + /// The status of the deletion request. + /// + public enum StatusEnum + { + + /// + /// Enum DELETED for deleted + /// + [EnumMember(Value = "deleted")] + DELETED + } + + /// + /// The status of the deletion request. + /// + [fsProperty("status")] + public StatusEnum? Status { get; set; } + /// + /// The unique identifier of the credentials that have been deleted. + /// + [fsProperty("credential_id")] + public string CredentialId { get; set; } + } + + /// + /// Object containing source parameters for the configuration. + /// + [fsObject] + public class Source + { + /// + /// The type of source to connect to. + /// - `box` indicates the configuration is to connect an instance of Enterprise Box. + /// - `salesforce` indicates the configuration is to connect to Salesforce. + /// - `sharepoint` indicates the configuration is to connect to Microsoft SharePoint Online. + /// + public enum TypeEnum + { + + /// + /// Enum BOX for box + /// + [EnumMember(Value = "box")] + BOX, + + /// + /// Enum SALESFORCE for salesforce + /// + [EnumMember(Value = "salesforce")] + SALESFORCE, + + /// + /// Enum SHAREPOINT for sharepoint + /// + [EnumMember(Value = "sharepoint")] + SHAREPOINT + } + + /// + /// The type of source to connect to. + /// - `box` indicates the configuration is to connect an instance of Enterprise Box. + /// - `salesforce` indicates the configuration is to connect to Salesforce. + /// - `sharepoint` indicates the configuration is to connect to Microsoft SharePoint Online. + /// + [fsProperty("type")] + public TypeEnum? Type { get; set; } + /// + /// The **credential_id** of the credentials to use to connect to the source. Credentials are defined using the + /// **credentials** method. The **source_type** of the credentials used must match the **type** field specified + /// in this object. + /// + [fsProperty("credential_id")] + public string CredentialId { get; set; } + /// + /// Object containing the schedule information for the source. + /// + [fsProperty("schedule")] + public SourceSchedule Schedule { get; set; } + /// + /// The **options** object defines which items to crawl from the source system. + /// + [fsProperty("options")] + public SourceOptions Options { get; set; } + } + + /// + /// The **options** object defines which items to crawl from the source system. + /// + [fsObject] + public class SourceOptions + { + /// + /// Array of folders to crawl from the Box source. Only valid, and required, when the **type** field of the + /// **source** object is set to `box`. + /// + [fsProperty("folders")] + public List Folders { get; set; } + /// + /// Array of Salesforce document object types to crawl from the Salesforce source. Only valid, and required, + /// when the **type** field of the **source** object is set to `salesforce`. + /// + [fsProperty("objects")] + public List Objects { get; set; } + /// + /// Array of Microsoft SharePointoint Online site collections to crawl from the SharePoint source. Only valid + /// and required when the **type** field of the **source** object is set to `sharepoint`. + /// + [fsProperty("site_collections")] + public List SiteCollections { get; set; } + } + + /// + /// Object that defines a box folder to crawl with this configuration. + /// + [fsObject] + public class SourceOptionsFolder + { + /// + /// The Box user ID of the user who owns the folder to crawl. + /// + [fsProperty("owner_user_id")] + public string OwnerUserId { get; set; } + /// + /// The Box folder ID of the folder to crawl. + /// + [fsProperty("folder_id")] + public string FolderId { get; set; } + /// + /// The maximum number of documents to crawl for this folder. By default, all documents in the folder are + /// crawled. + /// + [fsProperty("limit")] + public long? Limit { get; set; } + } + + /// + /// Object that defines a Salesforce document object type crawl with this configuration. + /// + [fsObject] + public class SourceOptionsObject + { + /// + /// The name of the Salesforce document object to crawl. For example, `case`. + /// + [fsProperty("name")] + public string Name { get; set; } + /// + /// The maximum number of documents to crawl for this document object. By default, all documents in the document + /// object are crawled. + /// + [fsProperty("limit")] + public long? Limit { get; set; } + } + + /// + /// Object that defines a Microsoft SharePoint site collection to crawl with this configuration. + /// + [fsObject] + public class SourceOptionsSiteColl + { + /// + /// The Microsoft SharePoint Online site collection path to crawl. The path must be be relative to the + /// **organization_url** that was specified in the credentials associated with this source configuration. + /// + [fsProperty("site_collection_path")] + public string SiteCollectionPath { get; set; } + /// + /// The maximum number of documents to crawl for this site collection. By default, all documents in the site + /// collection are crawled. + /// + [fsProperty("limit")] + public long? Limit { get; set; } + } + + /// + /// Object containing the schedule information for the source. + /// + [fsObject] + public class SourceSchedule + { + /// + /// The crawl schedule in the specified **time_zone**. + /// + /// - `daily`: Runs every day between 00:00 and 06:00. + /// - `weekly`: Runs every week on Sunday between 00:00 and 06:00. + /// - `monthly`: Runs the on the first Sunday of every month between 00:00 and 06:00. + /// + public enum FrequencyEnum + { + + /// + /// Enum DAILY for daily + /// + [EnumMember(Value = "daily")] + DAILY, + + /// + /// Enum WEEKLY for weekly + /// + [EnumMember(Value = "weekly")] + WEEKLY, + + /// + /// Enum MONTHLY for monthly + /// + [EnumMember(Value = "monthly")] + MONTHLY + } + + /// + /// The crawl schedule in the specified **time_zone**. + /// + /// - `daily`: Runs every day between 00:00 and 06:00. + /// - `weekly`: Runs every week on Sunday between 00:00 and 06:00. + /// - `monthly`: Runs the on the first Sunday of every month between 00:00 and 06:00. + /// + [fsProperty("frequency")] + public FrequencyEnum? Frequency { get; set; } + /// + /// When `true`, the source is re-crawled based on the **frequency** field in this object. When `false` the + /// source is not re-crawled; When `false` and connecting to Salesforce the source is crawled annually. + /// + [fsProperty("enabled")] + public bool? Enabled { get; set; } + /// + /// The time zone to base source crawl times on. Possible values correspond to the IANA (Internet Assigned + /// Numbers Authority) time zones list. + /// + [fsProperty("time_zone")] + public string TimeZone { get; set; } + } + + /// + /// Object containing source crawl status information. + /// + [fsObject] + public class SourceStatus + { + /// + /// The current status of the source crawl for this collection. This field returns `not_configured` if the + /// default configuration for this source does not have a **source** object defined. + /// + /// - `running` indicates that a crawl to fetch more documents is in progress. + /// - `complete` indicates that the crawl has completed with no errors. + /// - `complete_with_notices` indicates that some notices were generated during the crawl. Notices can be + /// checked by using the **notices** query method. + /// - `stopped` indicates that the crawl has stopped but is not complete. + /// + public enum StatusEnum + { + + /// + /// Enum RUNNING for running + /// + [EnumMember(Value = "running")] + RUNNING, + + /// + /// Enum COMPLETE for complete + /// + [EnumMember(Value = "complete")] + COMPLETE, + + /// + /// Enum COMPLETE_WITH_NOTICES for complete_with_notices + /// + [EnumMember(Value = "complete_with_notices")] + COMPLETE_WITH_NOTICES, + + /// + /// Enum STOPPED for stopped + /// + [EnumMember(Value = "stopped")] + STOPPED, + + /// + /// Enum NOT_CONFIGURED for not_configured + /// + [EnumMember(Value = "not_configured")] + NOT_CONFIGURED + } + + /// + /// The current status of the source crawl for this collection. This field returns `not_configured` if the + /// default configuration for this source does not have a **source** object defined. + /// + /// - `running` indicates that a crawl to fetch more documents is in progress. + /// - `complete` indicates that the crawl has completed with no errors. + /// - `complete_with_notices` indicates that some notices were generated during the crawl. Notices can be + /// checked by using the **notices** query method. + /// - `stopped` indicates that the crawl has stopped but is not complete. + /// + [fsProperty("status")] + public StatusEnum? Status { get; set; } + /// + /// Date in UTC format indicating when the last crawl was attempted. If `null`, no crawl was completed. + /// + [fsProperty("last_updated")] + public DateTime LastUpdated { get; set; } + } + #endregion } From d6534e2bdd95e81617146947b13e0716828d1124 Mon Sep 17 00:00:00 2001 From: Ajiemar Santiago Date: Wed, 11 Jul 2018 17:31:58 -0500 Subject: [PATCH 2/8] refactor(datamodel): Update enums in datamodel --- Scripts/Services/Discovery/v1/DataModels.cs | 40 ++++++++++----------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Scripts/Services/Discovery/v1/DataModels.cs b/Scripts/Services/Discovery/v1/DataModels.cs index c99b278a2..d9dc1ed5d 100644 --- a/Scripts/Services/Discovery/v1/DataModels.cs +++ b/Scripts/Services/Discovery/v1/DataModels.cs @@ -1054,14 +1054,14 @@ public class CredentialsList /// An array of credential definitions that were created for this instance. /// [fsProperty("credentials")] - public List Credentials { get; set; } + public List Credentials { get; set; } } [fsObject] /// /// Object containing credential information. /// - public class Credentials + public class SourceCredentials { /// /// The source that this credentials object connects to. @@ -1076,19 +1076,19 @@ public enum SourceTypeEnum /// Enum BOX for box /// [EnumMember(Value = "box")] - BOX, + box, /// /// Enum SALESFORCE for salesforce /// [EnumMember(Value = "salesforce")] - SALESFORCE, + salesforce, /// /// Enum SHAREPOINT for sharepoint /// [EnumMember(Value = "sharepoint")] - SHAREPOINT + sharepoint } /// @@ -1137,19 +1137,19 @@ public enum CredentialTypeEnum /// Enum OAUTH2 for oauth2 /// [EnumMember(Value = "oauth2")] - OAUTH2, + oauth2, /// /// Enum SAML for saml /// [EnumMember(Value = "saml")] - SAML, + saml, /// /// Enum USERNAME_PASSWORD for username_password /// [EnumMember(Value = "username_password")] - USERNAME_PASSWORD + username_password } /// @@ -1254,7 +1254,7 @@ public enum StatusEnum /// Enum DELETED for deleted /// [EnumMember(Value = "deleted")] - DELETED + deleted } /// @@ -1288,19 +1288,19 @@ public enum TypeEnum /// Enum BOX for box /// [EnumMember(Value = "box")] - BOX, + box, /// /// Enum SALESFORCE for salesforce /// [EnumMember(Value = "salesforce")] - SALESFORCE, + salesforce, /// /// Enum SHAREPOINT for sharepoint /// [EnumMember(Value = "sharepoint")] - SHAREPOINT + sharepoint } /// @@ -1439,19 +1439,19 @@ public enum FrequencyEnum /// Enum DAILY for daily /// [EnumMember(Value = "daily")] - DAILY, + daily, /// /// Enum WEEKLY for weekly /// [EnumMember(Value = "weekly")] - WEEKLY, + weekly, /// /// Enum MONTHLY for monthly /// [EnumMember(Value = "monthly")] - MONTHLY + monthly } /// @@ -1500,31 +1500,31 @@ public enum StatusEnum /// Enum RUNNING for running /// [EnumMember(Value = "running")] - RUNNING, + running, /// /// Enum COMPLETE for complete /// [EnumMember(Value = "complete")] - COMPLETE, + complete, /// /// Enum COMPLETE_WITH_NOTICES for complete_with_notices /// [EnumMember(Value = "complete_with_notices")] - COMPLETE_WITH_NOTICES, + complete_with_notices, /// /// Enum STOPPED for stopped /// [EnumMember(Value = "stopped")] - STOPPED, + stopped, /// /// Enum NOT_CONFIGURED for not_configured /// [EnumMember(Value = "not_configured")] - NOT_CONFIGURED + not_configured } /// From d4c7a29666a16df9d393d73d661b2d3f48deae3b Mon Sep 17 00:00:00 2001 From: Ajiemar Santiago Date: Wed, 11 Jul 2018 17:34:47 -0500 Subject: [PATCH 3/8] refactor: autoformat Discovery.cs --- Scripts/Services/Discovery/v1/Discovery.cs | 76 +++++++++++----------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/Scripts/Services/Discovery/v1/Discovery.cs b/Scripts/Services/Discovery/v1/Discovery.cs index 42103fdab..f9903a86b 100644 --- a/Scripts/Services/Discovery/v1/Discovery.cs +++ b/Scripts/Services/Discovery/v1/Discovery.cs @@ -155,9 +155,9 @@ public bool GetEnvironments(SuccessCallback successCall req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary() : customData; - if(req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { - foreach(KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) { req.Headers.Add(kvp.Key, kvp.Value); } @@ -277,9 +277,9 @@ public bool AddEnvironment(SuccessCallback successCallback, FailCal req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary() : customData; - if(req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { - foreach(KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) { req.Headers.Add(kvp.Key, kvp.Value); } @@ -378,9 +378,9 @@ public bool GetEnvironment(SuccessCallback successCallback, FailCal req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary() : customData; - if(req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { - foreach(KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) { req.Headers.Add(kvp.Key, kvp.Value); } @@ -475,9 +475,9 @@ public bool DeleteEnvironment(SuccessCallback success req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary() : customData; - if(req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { - foreach(KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) { req.Headers.Add(kvp.Key, kvp.Value); } @@ -574,9 +574,9 @@ private void OnDeleteEnvironmentResponse(RESTConnector.Request req, RESTConnecto req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary() : customData; - if(req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { - foreach(KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) { req.Headers.Add(kvp.Key, kvp.Value); } @@ -712,9 +712,9 @@ public bool AddConfiguration(SuccessCallback successCallback, Fai req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary() : customData; - if(req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { - foreach(KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) { req.Headers.Add(kvp.Key, kvp.Value); } @@ -815,9 +815,9 @@ public bool GetConfiguration(SuccessCallback successCallback, Fai req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary() : customData; - if(req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { - foreach(KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) { req.Headers.Add(kvp.Key, kvp.Value); } @@ -915,9 +915,9 @@ public bool DeleteConfiguration(SuccessCallback suc req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary() : customData; - if(req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { - foreach(KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) { req.Headers.Add(kvp.Key, kvp.Value); } @@ -1084,9 +1084,9 @@ private void OnDeleteConfigurationResponse(RESTConnector.Request req, RESTConnec req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary() : customData; - if(req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { - foreach(KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) { req.Headers.Add(kvp.Key, kvp.Value); } @@ -1207,9 +1207,9 @@ private void OnPreviewConfigurationResponse(RESTConnector.Request req, RESTConne req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary() : customData; - if(req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { - foreach(KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) { req.Headers.Add(kvp.Key, kvp.Value); } @@ -1341,9 +1341,9 @@ public bool AddCollection(SuccessCallback successCallback, FailCa req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary() : customData; - if(req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { - foreach(KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) { req.Headers.Add(kvp.Key, kvp.Value); } @@ -1444,9 +1444,9 @@ public bool GetCollection(SuccessCallback successCallback, FailCallb req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary() : customData; - if(req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { - foreach(KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) { req.Headers.Add(kvp.Key, kvp.Value); } @@ -1544,9 +1544,9 @@ public bool DeleteCollection(SuccessCallback successCa req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary() : customData; - if(req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { - foreach(KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) { req.Headers.Add(kvp.Key, kvp.Value); } @@ -1645,9 +1645,9 @@ public bool GetFields(SuccessCallback successCallback, FailCa req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary() : customData; - if(req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { - foreach(KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) { req.Headers.Add(kvp.Key, kvp.Value); } @@ -1918,9 +1918,9 @@ private void OnGetFieldsResponse(RESTConnector.Request req, RESTConnector.Respon req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary() : customData; - if(req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { - foreach(KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) { req.Headers.Add(kvp.Key, kvp.Value); } @@ -2033,9 +2033,9 @@ public bool DeleteDocument(SuccessCallback successCallba req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary() : customData; - if(req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { - foreach(KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) { req.Headers.Add(kvp.Key, kvp.Value); } @@ -2137,9 +2137,9 @@ public bool GetDocument(SuccessCallback successCallback, FailCal req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary() : customData; - if(req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { - foreach(KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) { req.Headers.Add(kvp.Key, kvp.Value); } @@ -2404,9 +2404,9 @@ private void OnGetDocumentResponse(RESTConnector.Request req, RESTConnector.Resp req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary() : customData; - if(req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { - foreach(KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) { req.Headers.Add(kvp.Key, kvp.Value); } @@ -2531,9 +2531,9 @@ public bool Query(SuccessCallback successCallback, FailCallback f req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary() : customData; - if(req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { - foreach(KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) { req.Headers.Add(kvp.Key, kvp.Value); } From 40e2e3ce51e0def5ef45f06a8a455827ae99cc64 Mon Sep 17 00:00:00 2001 From: Ajiemar Santiago Date: Wed, 11 Jul 2018 17:35:14 -0500 Subject: [PATCH 4/8] feat(discovery): abstract Credentials operations --- Scripts/Services/Discovery/v1/Discovery.cs | 421 +++++++++++++++++++++ 1 file changed, 421 insertions(+) diff --git a/Scripts/Services/Discovery/v1/Discovery.cs b/Scripts/Services/Discovery/v1/Discovery.cs index f9903a86b..844225392 100644 --- a/Scripts/Services/Discovery/v1/Discovery.cs +++ b/Scripts/Services/Discovery/v1/Discovery.cs @@ -51,6 +51,8 @@ public class Discovery : IWatsonService private const string Documents = "/v1/environments/{0}/collections/{1}/documents"; private const string Document = "/v1/environments/{0}/collections/{1}/documents/{2}"; private const string QueryCollection = "/v1/environments/{0}/collections/{1}/query"; + private const string CredentialsEndpoint = "/v1/environments/{0}/credentials"; + private const string CredentialEndpoint = "/v1/environments/{0}/credentials/{1}"; #endregion #region Public Properties @@ -2723,6 +2725,425 @@ private void OnDeleteUserDataResponse(RESTConnector.Request req, RESTConnector.R } #endregion + #region Credentials + #region List Credentials + /// + /// List all the source credentials that have been created for this service instance. + /// Note: All credentials are sent over an encrypted connection and encrypted at rest. + /// + /// The success callback. + /// The fail callback. + /// Optional custom data. + /// True if the call succeeds, false if the call is unsuccessful. + public bool ListCredentials(SuccessCallback successCallback, FailCallback failCallback, string environmentId, Dictionary customData = null) + { + if (successCallback == null) + throw new ArgumentNullException("successCallback"); + if (failCallback == null) + throw new ArgumentNullException("failCallback"); + if (string.IsNullOrEmpty(environmentId)) + throw new ArgumentException("environmentId"); + + ListCredentialsRequest req = new ListCredentialsRequest(); + req.SuccessCallback = successCallback; + req.FailCallback = failCallback; + req.CustomData = customData == null ? new Dictionary() : customData; + req.Headers["Content-Type"] = "application/json"; + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + { + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + { + req.Headers.Add(kvp.Key, kvp.Value); + } + } + req.Parameters["version"] = VersionDate; + req.OnResponse = OnListCredentialsResponse; + + RESTConnector connector = RESTConnector.GetConnector(Credentials, string.Format(CredentialsEndpoint, environmentId)); + if (connector == null) + return false; + + return connector.Send(req); + } + + private class ListCredentialsRequest : RESTConnector.Request + { + /// + /// The success callback. + /// + public SuccessCallback SuccessCallback { get; set; } + /// + /// The fail callback. + /// + public FailCallback FailCallback { get; set; } + /// + /// Custom data. + /// + public Dictionary CustomData { get; set; } + } + + private void OnListCredentialsResponse(RESTConnector.Request req, RESTConnector.Response resp) + { + CredentialsList result = new CredentialsList(); + fsData data = null; + Dictionary customData = ((ListCredentialsRequest)req).CustomData; + customData.Add(Constants.String.RESPONSE_HEADERS, resp.Headers); + + if (resp.Success) + { + try + { + fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data); + if (!r.Succeeded) + throw new WatsonException(r.FormattedMessages); + + object obj = result; + r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); + if (!r.Succeeded) + throw new WatsonException(r.FormattedMessages); + + customData.Add("json", data); + } + catch (Exception e) + { + Log.Error("Discovery.OnListCredentialsResponse()", "Exception: {0}", e.ToString()); + resp.Success = false; + } + } + + if (resp.Success) + { + if (((ListCredentialsRequest)req).SuccessCallback != null) + ((ListCredentialsRequest)req).SuccessCallback(result, customData); + } + else + { + if (((ListCredentialsRequest)req).FailCallback != null) + ((ListCredentialsRequest)req).FailCallback(resp.Error, customData); + } + } + #endregion + + #region CreateCredentials + /// + /// Create credentials. + /// + /// Creates a set of credentials to connect to a remote source. Created credentials are used in a configuration + /// to associate a collection with the remote source. + /// + /// **Note:** All credentials are sent over an encrypted connection and encrypted at rest. + /// + /// The function that is called when the operation is successful. + /// The function that is called when the operation fails. + /// The ID of the environment. + /// An object that defines an individual set of source credentials. + /// A Dictionary of data that will be passed to the callback. The raw json output from the REST call will be passed in this object as the value of the 'json' key. + /// Credentials + public bool CreateCredentials(SuccessCallback successCallback, FailCallback failCallback, string environmentId, SourceCredentials credentialsParameter, Dictionary customData = null) + { + if (successCallback == null) + throw new ArgumentNullException("successCallback"); + if (failCallback == null) + throw new ArgumentNullException("failCallback"); + if (string.IsNullOrEmpty(environmentId)) + throw new ArgumentNullException("environmentId"); + if (credentialsParameter == null) + throw new ArgumentNullException("credentialsParameter"); + + CreateCredentialsRequest req = new CreateCredentialsRequest(); + req.SuccessCallback = successCallback; + req.FailCallback = failCallback; + req.CustomData = customData == null ? new Dictionary() : customData; + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + { + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + { + req.Headers.Add(kvp.Key, kvp.Value); + } + } + req.Parameters["version"] = VersionDate; + req.Headers["Content-Type"] = "application/json"; + fsData data = null; + _serializer.TrySerialize(credentialsParameter, out data); + string json = data.ToString().Replace('\"', '"'); + req.Send = Encoding.UTF8.GetBytes(json); + req.OnResponse = OnCreateCredentialsResponse; + + RESTConnector connector = RESTConnector.GetConnector(Credentials, string.Format(CredentialsEndpoint, environmentId)); + if (connector == null) + return false; + + return connector.Send(req); + } + + private class CreateCredentialsRequest : RESTConnector.Request + { + /// + /// The success callback. + /// + public SuccessCallback SuccessCallback { get; set; } + /// + /// The fail callback. + /// + public FailCallback FailCallback { get; set; } + /// + /// Custom data. + /// + public Dictionary CustomData { get; set; } + } + + private void OnCreateCredentialsResponse(RESTConnector.Request req, RESTConnector.Response resp) + { + SourceCredentials result = new SourceCredentials(); + fsData data = null; + Dictionary customData = ((CreateCredentialsRequest)req).CustomData; + customData.Add(Constants.String.RESPONSE_HEADERS, resp.Headers); + + if (resp.Success) + { + try + { + fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data); + if (!r.Succeeded) + throw new WatsonException(r.FormattedMessages); + + object obj = result; + r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); + if (!r.Succeeded) + throw new WatsonException(r.FormattedMessages); + } + catch (Exception e) + { + Log.Error("Assistant.OnCreateCredentialsResponse()", "Exception: {0}", e.ToString()); + resp.Success = false; + } + } + + customData.Add("json", data); + + if (resp.Success) + { + if (((CreateCredentialsRequest)req).SuccessCallback != null) + ((CreateCredentialsRequest)req).SuccessCallback(result, customData); + } + else + { + if (((CreateCredentialsRequest)req).FailCallback != null) + ((CreateCredentialsRequest)req).FailCallback(resp.Error, customData); + } + } + #endregion + + #region Delete Credentials + /// + /// Delete credentials. + /// + /// Deletes a set of stored credentials from your Discovery instance. + /// + /// The success callback. + /// The fail callback. + /// The ID of the environment. + /// The unique identifier for a set of source credentials. + /// Custom data object to pass data including custom request headers. + /// DeleteCredentials + public bool DeleteCredentials(SuccessCallback successCallback, FailCallback failCallback, string environmentID, string credentialId, Dictionary customData = null) + { + if (successCallback == null) + throw new ArgumentNullException("successCallback"); + if (failCallback == null) + throw new ArgumentNullException("failCallback"); + if (string.IsNullOrEmpty(environmentID)) + throw new ArgumentNullException("environmentID"); + if (string.IsNullOrEmpty(credentialId)) + throw new ArgumentNullException("credentialId"); + + DeleteCredentialsRequest req = new DeleteCredentialsRequest(); + req.SuccessCallback = successCallback; + req.FailCallback = failCallback; + req.CustomData = customData == null ? new Dictionary() : customData; + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + { + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + { + req.Headers.Add(kvp.Key, kvp.Value); + } + } + req.Parameters["version"] = VersionDate; + req.OnResponse = OnDeleteCredentialsResponse; + req.Delete = true; + + RESTConnector connector = RESTConnector.GetConnector(Credentials, string.Format(CredentialEndpoint, environmentID, credentialId)); + if (connector == null) + return false; + + return connector.Send(req); + } + + private class DeleteCredentialsRequest : RESTConnector.Request + { + /// + /// The success callback. + /// + public SuccessCallback SuccessCallback { get; set; } + /// + /// The fail callback. + /// + public FailCallback FailCallback { get; set; } + /// + /// Custom data. + /// + public Dictionary CustomData { get; set; } + } + + private void OnDeleteCredentialsResponse(RESTConnector.Request req, RESTConnector.Response resp) + { + DeleteCredentials result = new DeleteCredentials(); + fsData data = null; + Dictionary customData = ((DeleteCredentialsRequest)req).CustomData; + customData.Add(Constants.String.RESPONSE_HEADERS, resp.Headers); + + if (resp.Success) + { + try + { + fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data); + if (!r.Succeeded) + throw new WatsonException(r.FormattedMessages); + + object obj = result; + r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); + if (!r.Succeeded) + throw new WatsonException(r.FormattedMessages); + + customData.Add("json", data); + } + catch (Exception e) + { + Log.Error("Discovery.OnDeleteCredentialsResponse()", "OnDeleteCredentialsResponse Exception: {0}", e.ToString()); + resp.Success = false; + } + } + + if (resp.Success) + { + if (((DeleteCredentialsRequest)req).SuccessCallback != null) + ((DeleteCredentialsRequest)req).SuccessCallback(result, customData); + } + else + { + if (((DeleteCredentialsRequest)req).FailCallback != null) + ((DeleteCredentialsRequest)req).FailCallback(resp.Error, customData); + } + } + #endregion + + #region GetCredential + /// + /// View Credentials. + /// + /// Returns details about the specified credentials. + /// + /// **Note:** Secure credential information such as a password or SSH key is never returned and must be + /// obtained from the source system. + /// + /// The success callback. + /// The fail callback. + /// The ID of the environment. + /// The unique identifier for a set of source credentials. + /// Custom data object to pass data including custom request headers. + /// Credentials + public bool GetCredential(SuccessCallback successCallback, FailCallback failCallback, string environmentID, string credentialId, Dictionary customData = null) + { + if (successCallback == null) + throw new ArgumentNullException("successCallback"); + if (failCallback == null) + throw new ArgumentNullException("failCallback"); + if (string.IsNullOrEmpty(environmentID)) + throw new ArgumentNullException("environmentID"); + if (string.IsNullOrEmpty(credentialId)) + throw new ArgumentNullException("credentialId"); + + GetCredentialRequest req = new GetCredentialRequest(); + req.SuccessCallback = successCallback; + req.FailCallback = failCallback; + req.CustomData = customData == null ? new Dictionary() : customData; + req.Headers["Content-Type"] = "application/json"; + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + { + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + { + req.Headers.Add(kvp.Key, kvp.Value); + } + } + req.Parameters["version"] = VersionDate; + req.OnResponse = OnGetCredentialResponse; + + RESTConnector connector = RESTConnector.GetConnector(Credentials, string.Format(CredentialEndpoint, environmentID, credentialId)); + if (connector == null) + return false; + + return connector.Send(req); + } + + private class GetCredentialRequest : RESTConnector.Request + { + /// + /// The success callback. + /// + public SuccessCallback SuccessCallback { get; set; } + /// + /// The fail callback. + /// + public FailCallback FailCallback { get; set; } + /// + /// Custom data. + /// + public Dictionary CustomData { get; set; } + } + + private void OnGetCredentialResponse(RESTConnector.Request req, RESTConnector.Response resp) + { + SourceCredentials result = new SourceCredentials(); + fsData data = null; + Dictionary customData = ((GetCredentialRequest)req).CustomData; + customData.Add(Constants.String.RESPONSE_HEADERS, resp.Headers); + + if (resp.Success) + { + try + { + fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data); + if (!r.Succeeded) + throw new WatsonException(r.FormattedMessages); + + object obj = result; + r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); + if (!r.Succeeded) + throw new WatsonException(r.FormattedMessages); + + customData.Add("json", data); + } + catch (Exception e) + { + Log.Error("Discovery.OnGetCredentialResponse()", "OnGetCredentialResponse Exception: {0}", e.ToString()); + resp.Success = false; + } + } + + if (resp.Success) + { + if (((GetCredentialRequest)req).SuccessCallback != null) + ((GetCredentialRequest)req).SuccessCallback(result, customData); + } + else + { + if (((GetCredentialRequest)req).FailCallback != null) + ((GetCredentialRequest)req).FailCallback(resp.Error, customData); + } + } + #endregion + #endregion + #region IWatsonService Interface /// public string GetServiceID() From 74afbeb0cf57c034c07ccc0412d3c290b7d12eb9 Mon Sep 17 00:00:00 2001 From: Ajiemar Santiago Date: Wed, 11 Jul 2018 17:36:23 -0500 Subject: [PATCH 5/8] feat(examples): add examples for new Discovery Credentials endpoints --- .../Scripts/ExampleDiscovery.cs | 81 ++++++++++++++++++- Scripts/Services/Discovery/v1/Model.meta | 8 ++ 2 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 Scripts/Services/Discovery/v1/Model.meta diff --git a/Examples/ServiceExamples/Scripts/ExampleDiscovery.cs b/Examples/ServiceExamples/Scripts/ExampleDiscovery.cs index 14f2ecc55..cc639af2b 100644 --- a/Examples/ServiceExamples/Scripts/ExampleDiscovery.cs +++ b/Examples/ServiceExamples/Scripts/ExampleDiscovery.cs @@ -83,6 +83,12 @@ public class ExampleDiscovery : MonoBehaviour private bool _readyToContinue = false; private float _waitTime = 10f; + private bool _listCredentialsTested = false; + private bool _createCredentialsTested = false; + private bool _getCredentialTested = false; + private bool _deleteCredentialsTested = false; + private string _createdCredentialId = null; + private void Start() { LogSystem.InstallDefaultReactors(); @@ -285,9 +291,47 @@ private IEnumerator Examples() while (!_isEnvironmentReady) yield return null; + // List Credentials + Log.Debug("TestDiscovery.RunTest()", "Attempting to list credentials"); + _service.ListCredentials(OnListCredentials, OnFail, _environmentId); + while (!_listCredentialsTested) + yield return null; + + // Create Credentials + Log.Debug("TestDiscovery.RunTest()", "Attempting to create credentials"); + SourceCredentials credentialsParameter = new SourceCredentials() + { + SourceType = SourceCredentials.SourceTypeEnum.box, + CredentialDetails = new CredentialDetails() + { + CredentialType = CredentialDetails.CredentialTypeEnum.oauth2, + EnterpriseId = "myEnterpriseId", + ClientId = "myClientId", + ClientSecret = "myClientSecret", + PublicKeyId = "myPublicIdKey", + Passphrase = "myPassphrase", + PrivateKey = "myPrivateKey" + } + }; + _service.CreateCredentials(OnCreateCredentials, OnFail, _environmentId, credentialsParameter); + while (!_createCredentialsTested) + yield return null; + + // Get Credential + Log.Debug("TestDiscovery.RunTest()", "Attempting to get credential"); + _service.GetCredential(OnGetCredential, OnFail, _environmentId, _createdCredentialId); + while (!_getCredentialTested) + yield return null; + + // DeleteCredential + Log.Debug("TestDiscovery.RunTest()", "Attempting to delete credential"); + _service.DeleteCredentials(OnDeleteCredentials, OnFail, _environmentId, _createdCredentialId); + while (!_deleteCredentialsTested) + yield return null; + Log.Debug("TestDiscovery.RunTest()", "Discovery examples complete."); } - + #region Check State private IEnumerator CheckEnvironmentState(float waitTime) { @@ -327,13 +371,22 @@ private IEnumerator Delay(float waitTime) private void OnGetEnvironments(GetEnvironmentsResponse resp, Dictionary customData) { Log.Debug("ExampleDiscovery.OnGetEnvironments()", "Discovery - GetEnvironments Response: {0}", customData["json"].ToString()); + + foreach(var environment in resp.environments) + { + if (environment.read_only == false) + { + Log.Debug("ExampleDiscovery.OnGetEnvironments()", "setting environment to {0}", environment.environment_id); + _environmentId = environment.environment_id; + } + } + _getEnvironmentsTested = true; } private void OnGetEnvironment(Environment resp, Dictionary customData) { Log.Debug("ExampleDiscovery.OnGetEnvironment()", "Discovery - GetEnvironment Response: {0}", customData["json"].ToString()); - _environmentId = resp.environment_id; _getEnvironmentTested = true; } @@ -437,6 +490,30 @@ private void OnQuery(QueryResponse resp, Dictionary customData) _queryTested = true; } + private void OnListCredentials(CredentialsList response, Dictionary customData) + { + Log.Debug("ExampleDiscovery.OnListCredentials()", "Response: {0}", customData["json"].ToString()); + _listCredentialsTested = true; + } + private void OnCreateCredentials(SourceCredentials response, Dictionary customData) + { + Log.Debug("ExampleDiscovery.OnCreateCredentials()", "Response: {0}", customData["json"].ToString()); + _createdCredentialId = response.CredentialId; + _createCredentialsTested = true; + } + + private void OnGetCredential(SourceCredentials response, Dictionary customData) + { + Log.Debug("ExampleDiscovery.OnGetCredential()", "Response: {0}", customData["json"].ToString()); + _getCredentialTested = true; + } + + private void OnDeleteCredentials(DeleteCredentials response, Dictionary customData) + { + Log.Debug("ExampleDiscovery.OnDeleteCredentials()", "Response: {0}", customData["json"].ToString()); + _deleteCredentialsTested = true; + } + private void OnFail(RESTConnector.Error error, Dictionary customData) { Log.Error("ExampleDiscovery.OnFail()", "Error received: {0}", error.ToString()); diff --git a/Scripts/Services/Discovery/v1/Model.meta b/Scripts/Services/Discovery/v1/Model.meta new file mode 100644 index 000000000..6a677c46f --- /dev/null +++ b/Scripts/Services/Discovery/v1/Model.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9b98a92f8338528479c9cc7a1361dbaa +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From a539d72d77b78358521422d0d1b295492c808e27 Mon Sep 17 00:00:00 2001 From: Ajiemar Santiago Date: Wed, 11 Jul 2018 20:06:58 -0500 Subject: [PATCH 6/8] test(discovery): add integration tests for Credentials endpoints --- Scripts/UnitTests/TestDiscovery.cs | 79 +++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 2 deletions(-) diff --git a/Scripts/UnitTests/TestDiscovery.cs b/Scripts/UnitTests/TestDiscovery.cs index 4ff5d8746..815756dee 100644 --- a/Scripts/UnitTests/TestDiscovery.cs +++ b/Scripts/UnitTests/TestDiscovery.cs @@ -70,6 +70,12 @@ public class TestDiscovery : UnitTest private bool _deleteUserDataTested = false; private bool _readyToContinue = false; + private bool _listCredentialsTested = false; + private bool _createCredentialsTested = false; + private bool _getCredentialTested = false; + private bool _deleteCredentialsTested = false; + private string _createdCredentialId = null; + public override IEnumerator RunTest() { LogSystem.InstallDefaultReactors(); @@ -215,6 +221,44 @@ public override IEnumerator RunTest() while (!_queryTested) yield return null; + // List Credentials + Log.Debug("TestDiscovery.RunTest()", "Attempting to list credentials"); + _discovery.ListCredentials(OnListCredentials, OnFail, _environmentId); + while (!_listCredentialsTested) + yield return null; + + // Create Credentials + Log.Debug("TestDiscovery.RunTest()", "Attempting to create credentials"); + SourceCredentials credentialsParameter = new SourceCredentials() + { + SourceType = SourceCredentials.SourceTypeEnum.box, + CredentialDetails = new CredentialDetails() + { + CredentialType = CredentialDetails.CredentialTypeEnum.oauth2, + EnterpriseId = "myEnterpriseId", + ClientId = "myClientId", + ClientSecret = "myClientSecret", + PublicKeyId = "myPublicIdKey", + Passphrase = "myPassphrase", + PrivateKey = "myPrivateKey" + } + }; + _discovery.CreateCredentials(OnCreateCredentials, OnFail, _environmentId, credentialsParameter); + while (!_createCredentialsTested) + yield return null; + + // Get Credential + Log.Debug("TestDiscovery.RunTest()", "Attempting to get credential"); + _discovery.GetCredential(OnGetCredential, OnFail, _environmentId, _createdCredentialId); + while (!_getCredentialTested) + yield return null; + + // DeleteCredential + Log.Debug("TestDiscovery.RunTest()", "Attempting to delete credential"); + _discovery.DeleteCredentials(OnDeleteCredentials, OnFail, _environmentId, _createdCredentialId); + while (!_deleteCredentialsTested) + yield return null; + // Delete Document Log.Debug("TestDiscovery.RunTest()", "Attempting to delete document {0}", _createdDocumentID); if (!_discovery.DeleteDocument(OnDeleteDocument, OnFail, _environmentId, _createdCollectionID, _createdDocumentID)) @@ -310,7 +354,14 @@ private IEnumerator Delay(float waitTime) private void OnGetEnvironments(GetEnvironmentsResponse resp, Dictionary customData) { Log.Debug("TestDiscovery.OnGetEnvironments()", "Discovery - GetEnvironments Response: {0}", customData["json"].ToString()); - _environmentId = resp.environments[0].environment_id; + foreach (var environment in resp.environments) + { + if (environment.read_only == false) + { + Log.Debug("TestDiscovery.OnGetEnvironments()", "setting environment to {0}", environment.environment_id); + _environmentId = environment.environment_id; + } + } Test(resp != null); _getEnvironmentsTested = true; } @@ -442,11 +493,35 @@ private void OnQuery(QueryResponse resp, Dictionary customData) private void OnDeleteUserData(object response, Dictionary customData) { - Log.Debug("ExampleAssistant.OnDeleteUserData()", "Response: {0}", customData["json"].ToString()); + Log.Debug("TestDiscovery.OnDeleteUserData()", "Response: {0}", customData["json"].ToString()); Test(response != null); _deleteUserDataTested = true; } + private void OnListCredentials(CredentialsList response, Dictionary customData) + { + Log.Debug("TestDiscovery.OnListCredentials()", "Response: {0}", customData["json"].ToString()); + _listCredentialsTested = true; + } + private void OnCreateCredentials(SourceCredentials response, Dictionary customData) + { + Log.Debug("TestDiscovery.OnCreateCredentials()", "Response: {0}", customData["json"].ToString()); + _createdCredentialId = response.CredentialId; + _createCredentialsTested = true; + } + + private void OnGetCredential(SourceCredentials response, Dictionary customData) + { + Log.Debug("TestDiscovery.OnGetCredential()", "Response: {0}", customData["json"].ToString()); + _getCredentialTested = true; + } + + private void OnDeleteCredentials(DeleteCredentials response, Dictionary customData) + { + Log.Debug("TestDiscovery.OnDeleteCredentials()", "Response: {0}", customData["json"].ToString()); + _deleteCredentialsTested = true; + } + private void OnFail(RESTConnector.Error error, Dictionary customData) { Log.Error("TestDiscovery.OnFail()", "Error received: {0}", error.ToString()); From 5a97842bc1deee56a3d80c5365af5579d25d9ba9 Mon Sep 17 00:00:00 2001 From: Ajiemar Santiago Date: Thu, 12 Jul 2018 07:52:16 -0500 Subject: [PATCH 7/8] refactor(examples):autoformat discovery examples --- Examples/ServiceExamples/Scripts/ExampleDiscovery.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Examples/ServiceExamples/Scripts/ExampleDiscovery.cs b/Examples/ServiceExamples/Scripts/ExampleDiscovery.cs index cc639af2b..0cfec981f 100644 --- a/Examples/ServiceExamples/Scripts/ExampleDiscovery.cs +++ b/Examples/ServiceExamples/Scripts/ExampleDiscovery.cs @@ -331,7 +331,7 @@ private IEnumerator Examples() Log.Debug("TestDiscovery.RunTest()", "Discovery examples complete."); } - + #region Check State private IEnumerator CheckEnvironmentState(float waitTime) { @@ -372,7 +372,7 @@ private void OnGetEnvironments(GetEnvironmentsResponse resp, Dictionary Date: Thu, 12 Jul 2018 07:52:51 -0500 Subject: [PATCH 8/8] refactor(tests): autoformat discovery tests --- Scripts/UnitTests/TestDiscovery.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/UnitTests/TestDiscovery.cs b/Scripts/UnitTests/TestDiscovery.cs index 815756dee..b8530572d 100644 --- a/Scripts/UnitTests/TestDiscovery.cs +++ b/Scripts/UnitTests/TestDiscovery.cs @@ -114,7 +114,7 @@ public override IEnumerator RunTest() // Create credential and instantiate service Credentials credentials = new Credentials(_username, _password, _url); - + _discovery = new Discovery(credentials); _discovery.VersionDate = _discoveryVersionDate; _filePathToIngest = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/Discovery/constitution.pdf";