Skip to content

Commit b37c1c6

Browse files
author
Christian Compton
authored
Merge pull request #50 from IBM-Swift/iam
Watson IAM service credential migration
2 parents 4b50eee + 664f2e6 commit b37c1c6

8 files changed

Lines changed: 47 additions & 48 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ The following services are currently supported by this library. Therefore, you c
110110
- [PostgreSQL](https://console.ng.bluemix.net/catalog/services/compose-for-postgresql/)
111111
- [Push SDK](https://console.ng.bluemix.net/catalog/services/push-notifications)
112112
- [Redis](https://console.ng.bluemix.net/catalog/services/redis-cloud)
113-
- [Watson Conversation](https://console.ng.bluemix.net/catalog/services/conversation)
113+
- [Watson Assistant](https://console.ng.bluemix.net/catalog/services/watson-assistant-formerly-conversation)
114114
- [Weather Company Data](https://console.bluemix.net/catalog/services/weather-company-data)
115115

116116
If you don't see listed above the service you intend to use in your Swift application, you can leverage the generic `getDictionary(name: String)` method to get the corresponding credentials:

Sources/CloudEnvironment/NaturalLangUnderstandingCredentials.swift renamed to Sources/CloudEnvironment/NaturalLanguageUnderstandingCredentials.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,34 @@
1414
* limitations under the License.
1515
*/
1616

17-
/// NaturalLangUnderstandingCredentials class
17+
/// NaturalLanguageUnderstandingCredentials class
1818
///
1919
/// Contains the credentials for a Natural Language Understanding service instance.
20-
public class NaturalLangUnderstandingCredentials: Credentials {
21-
// Just a simpler wrapper to provide a type for natural language credentials
20+
public class NaturalLanguageUnderstandingCredentials {
21+
22+
public let apiKey: String
23+
public let url: String
24+
25+
public init(apiKey: String, url: String) {
26+
self.apiKey = apiKey
27+
self.url = url
28+
}
2229
}
2330

2431
extension CloudEnv {
2532

26-
/// Returns a NaturalLangUnderstandingCredentials object with the corresponding credentials.
33+
/// Returns a NaturalLanguageUnderstandingCredentials object with the corresponding credentials.
2734
///
2835
/// - Parameter name: The key to lookup the credentials object.
29-
public func getNaturalLangUnderstandingCredentials(name: String) -> NaturalLangUnderstandingCredentials? {
36+
public func getNaturalLanguageUnderstandingCredentials(name: String) -> NaturalLanguageUnderstandingCredentials? {
3037

3138
guard let credentials = getDictionary(name: name),
32-
let username = credentials["username"] as? String,
33-
let password = credentials["password"] as? String,
39+
let apiKey = credentials["apikey"] as? String,
3440
let url = credentials["url"] as? String else {
3541

3642
return nil
3743
}
3844

39-
return NaturalLangUnderstandingCredentials(
40-
username: username,
41-
password: password,
42-
url: url)
45+
return NaturalLanguageUnderstandingCredentials(apiKey: apiKey, url: url)
4346
}
44-
4547
}

Sources/CloudEnvironment/WatsonConversationCredentials.swift renamed to Sources/CloudEnvironment/WatsonAssistantCredentials.swift

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,33 @@
1414
* limitations under the License.
1515
*/
1616

17-
/// WatsonConversationCredentials class
17+
/// WatsonAssistantCredentials class
1818
///
19-
/// Contains the credentials for a Watson Conversation service instance.
20-
public class WatsonConversationCredentials: Credentials {
21-
// Just a simpler wrapper to provide a type for conversation credentials
19+
/// Contains the credentials for a Watson Assistant service instance.
20+
public class WatsonAssistantCredentials {
21+
22+
public let apiKey: String
23+
public let url: String
24+
25+
public init(apiKey: String, url: String) {
26+
self.apiKey = apiKey
27+
self.url = url
28+
}
2229
}
2330

2431
extension CloudEnv {
2532

26-
/// Returns an WatsonConversationCredentials object with the corresponding credentials.
33+
/// Returns an WatsonAssistantCredentials object with the corresponding credentials.
2734
///
2835
/// - Parameter name: The key to lookup the environment variable.
29-
public func getWatsonConversationCredentials(name: String) -> WatsonConversationCredentials? {
36+
public func getWatsonAssistantCredentials(name: String) -> WatsonAssistantCredentials? {
3037
guard let credentials = getDictionary(name: name),
31-
let username = credentials["username"] as? String,
32-
let password = credentials["password"] as? String,
33-
let url = credentials["url"] as? String else {
38+
let apiKey = credentials["apikey"] as? String,
39+
let url = credentials["url"] as? String else {
3440

3541
return nil
3642
}
3743

38-
return WatsonConversationCredentials(username: username, password: password, url: url)
44+
return WatsonAssistantCredentials(apiKey: apiKey, url: url)
3945
}
40-
4146
}

Tests/CloudEnvironmentTests/NaturalLangUnderstandingTests.swift renamed to Tests/CloudEnvironmentTests/NaturalLanguageUnderstandingTests.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import XCTest
1818
import Configuration
1919
@testable import CloudEnvironment
2020

21-
class NaturalLangUnderstandingTests: XCTestCase {
21+
class NaturalLanguageUnderstandingTests: XCTestCase {
2222

23-
static var allTests : [(String, (NaturalLangUnderstandingTests) -> () throws -> Void)] {
23+
static var allTests : [(String, (NaturalLanguageUnderstandingTests) -> () throws -> Void)] {
2424
return [
2525
("testGetCredentials", testGetCredentials),
2626
]
@@ -31,13 +31,12 @@ class NaturalLangUnderstandingTests: XCTestCase {
3131
// Load test mappings.json file and Cloud Foundry test credentials-- VCAP_SERVICES and VCAP_APPLICATION
3232
let cloudEnv = CloudEnv(mappingsFilePath: "Tests/CloudEnvironmentTests/resources", cloudFoundryFile: "Tests/CloudEnvironmentTests/resources/config_cf_example.json")
3333

34-
guard let credentials = cloudEnv.getNaturalLangUnderstandingCredentials(name: "NLUKey") else {
34+
guard let credentials = cloudEnv.getNaturalLanguageUnderstandingCredentials(name: "NLUKey") else {
3535
XCTFail("Could not load Natural Language Understanding service credentials.")
3636
return
3737
}
3838

39-
XCTAssertEqual(credentials.username, "natural-language-user")
40-
XCTAssertEqual(credentials.password, "natural-language-pwd")
39+
XCTAssertEqual(credentials.apiKey, "natural-language-apikey")
4140
XCTAssertEqual(credentials.url, "https://gateway.watsonplatform.net/natural-language-understanding/api")
4241

4342
}

Tests/CloudEnvironmentTests/WatsonConversationTests.swift renamed to Tests/CloudEnvironmentTests/WatsonAssistantTests.swift

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import XCTest
1818
import Configuration
1919
@testable import CloudEnvironment
2020

21-
class WatsonConversationTests: XCTestCase {
21+
class WatsonAssistantTests: XCTestCase {
2222

23-
static var allTests : [(String, (WatsonConversationTests) -> () throws -> Void)] {
23+
static var allTests : [(String, (WatsonAssistantTests) -> () throws -> Void)] {
2424
return [
2525
("testGetCredentials", testGetCredentials),
2626
]
@@ -31,17 +31,12 @@ class WatsonConversationTests: XCTestCase {
3131
// Load test mappings.json file and Cloud Foundry test credentials-- VCAP_SERVICES and VCAP_APPLICATION
3232
let cloudEnv = CloudEnv(mappingsFilePath: "Tests/CloudEnvironmentTests/resources", cloudFoundryFile: "Tests/CloudEnvironmentTests/resources/config_cf_example.json")
3333

34-
guard let credentials = cloudEnv.getWatsonConversationCredentials(name: "ConversationKey") else {
35-
XCTFail("Could not load Watson Conversation service credentials.")
34+
guard let credentials = cloudEnv.getWatsonAssistantCredentials(name: "AssistantKey") else {
35+
XCTFail("Could not load Watson Assistant service credentials.")
3636
return
3737
}
3838

39-
XCTAssertEqual(credentials.username, "conversation-user", "Watson Conversation service username should match.")
40-
XCTAssertEqual(credentials.password, "conversation-pwd", "Watson Conversation service password should match.")
41-
XCTAssertEqual(credentials.url, "https://gateway.watsonplatform.net/conversation/api", "Watson Conversation service url should match.")
42-
XCTAssertEqual(credentials.port, 443, "Watson Conversation service port should match.")
43-
XCTAssertEqual(credentials.host, "gateway.watsonplatform.net", "Watson Conversation service host should match.")
44-
XCTAssertTrue(credentials.secured, "Watson Conversation service url should be secured.")
39+
XCTAssertEqual(credentials.apiKey, "assistant-apikey", "Watson Assistant service username should match.")
40+
XCTAssertEqual(credentials.url, "https://gateway.watsonplatform.net/assistant/api", "Watson Assistant service url should match.")
4541
}
46-
4742
}

Tests/CloudEnvironmentTests/resources/config_cf_example.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@
4343
"conversation": [
4444
{
4545
"credentials": {
46-
"password": "conversation-pwd",
47-
"url": "https://gateway.watsonplatform.net/conversation/api",
48-
"username": "conversation-user"
46+
"apikey": "assistant-apikey",
47+
"url": "https://gateway.watsonplatform.net/assistant/api"
4948
},
5049
"label": "conversation",
5150
"name": "ConversationService",
@@ -62,9 +61,8 @@
6261
"natural-language-understanding": [
6362
{
6463
"credentials": {
65-
"password": "natural-language-pwd",
64+
"apikey": "natural-language-apikey",
6665
"url": "https://gateway.watsonplatform.net/natural-language-understanding/api",
67-
"username": "natural-language-user"
6866
},
6967
"label": "natural-language-understanding",
7068
"name": "NLUService",

Tests/CloudEnvironmentTests/resources/mappings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
]
5454
}
5555
},
56-
"ConversationKey": {
56+
"AssistantKey": {
5757
"credentials": {
5858
"searchPatterns": [
5959
"cloudfoundry:ConversationService",

Tests/LinuxMain.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ XCTMain([
3030
testCase(PostgreSQLTests.allTests),
3131
testCase(PushSDKTests.allTests),
3232
testCase(RedisTests.allTests),
33-
testCase(WatsonConversationTests.allTests),
34-
testCase(NaturalLangUnderstandingTests.allTests),
33+
testCase(WatsonAssistantTests.allTests),
34+
testCase(NaturalLanguageUnderstandingTests.allTests),
3535
testCase(WeatherCompanyDataTests.allTests),
3636
testCase(EnvironmentVariablesTests.allTests),
3737
testCase(LocalFileTests.allTests),

0 commit comments

Comments
 (0)