Skip to content

Commit

Permalink
Add AppID service
Browse files Browse the repository at this point in the history
helenmasters committed Mar 1, 2017
1 parent ccaedb3 commit 6715493
Showing 4 changed files with 78 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Sources/CloudFoundryConfig/Extensions.swift
Original file line number Diff line number Diff line change
@@ -117,4 +117,13 @@ extension ConfigurationManager {
}
}

public func getAppIDService(name: String) throws -> AppIDService {

if let service = getService(spec: name),
let appIDService = AppIDService(withService: service) {
return appIDService
} else {
throw ConfigurationManagerError.noServiceWithName(name)
}
}
}
37 changes: 37 additions & 0 deletions Sources/CloudFoundryConfig/Services.swift
Original file line number Diff line number Diff line change
@@ -250,6 +250,43 @@ public class ObjectStorageService: Service {

}

public class AppIDService: Service {

public let clientId: String
public let oauthServerUrl: String
public let profilesUrl: String
public let secret: String
public let tenantId: String
public let version: Int

public init?(withService service: Service) {

guard let credentials = service.credentials,
let clientId = credentials["clientId"] as? String,
let oauthServerUrl = credentials["oauthServerUrl"] as? String,
let profilesUrl = credentials["profilesUrl"] as? String,
let secret = credentials["secret"] as? String,
let tenantId = credentials["tenantId"] as? String,
let version = credentials["version"] as? Int
else {
return nil
}

self.clientId = clientId
self.oauthServerUrl = oauthServerUrl
self.profilesUrl = profilesUrl
self.secret = secret
self.tenantId = tenantId
self.version = version

super.init(name: service.name,
label: service.label,
plan: service.plan,
tags: service.tags,
credentials: service.credentials)
}
}

// other services

public class PostgreSQLService: Service {
8 changes: 8 additions & 0 deletions Tests/CloudFoundryConfigTests/FileLoadTests.swift
Original file line number Diff line number Diff line change
@@ -94,6 +94,14 @@ class FileLoadTests: XCTestCase {
XCTAssertEqual(autoScalingService.appID, "auto-scaling-appID", "Auto-Scaling Service appID should match.")
XCTAssertEqual(autoScalingService.serviceID, "auto-scaling-serviceID", "Auto-Scaling Service serviceID should match.")

let appIDService = try manager.getAppIDService(name: "App ID-qt")
XCTAssertEqual(appIDService.clientId, "<clientId>", "AppID Service clientId should match.")
XCTAssertEqual(appIDService.oauthServerUrl, "https://appid-oauth.stage1.ng.bluemix.net/oauth/v3/ee971e31-eb19-415b-af84-45172c24895c", "AppID oauthServerUrl should match.")
XCTAssertEqual(appIDService.profilesUrl, "https://appid-profiles.stage1.ng.bluemix.net", "AppID Service profilesUrl should match.")
XCTAssertEqual(appIDService.secret, "<secret>", "AppID Service secret should match.")
XCTAssertEqual(appIDService.tenantId, "ee971e31-eb19-415b-af84-45172c24895c", "AppID Service tenantId should match.")
XCTAssertEqual(appIDService.version, 3, "AppID Service version should match.")

} catch {
XCTFail("Could not load configuration. Error: \(error)")
}
24 changes: 24 additions & 0 deletions Tests/CloudFoundryConfigTests/config_example.json
Original file line number Diff line number Diff line change
@@ -41,6 +41,30 @@
]
}
],
"AdvancedMobileAccess": [
{
"credentials": {
"clientId": "<clientId>",
"oauthServerUrl": "https://appid-oauth.stage1.ng.bluemix.net/oauth/v3/ee971e31-eb19-415b-af84-45172c24895c",
"profilesUrl": "https://appid-profiles.stage1.ng.bluemix.net",
"secret": "<secret>",
"tenantId": "ee971e31-eb19-415b-af84-45172c24895c",
"version": 3
},
"label": "AdvancedMobileAccess",
"name": "App ID-qt",
"plan": "Bronze",
"provider": null,
"syslog_drain_url": null,
"tags": [
"security",
"Security",
"mobile",
"ibm_created",
"ibm_dedicated_public"
]
}
],
"alertnotification": [
{
"credentials": {

0 comments on commit 6715493

Please sign in to comment.