Skip to content

Commit b4bf44d

Browse files
authored
Merge pull request #6 from rolivieri/master
Migrated library to use newer version of Swift-cfenv.
2 parents 8611354 + e672696 commit b4bf44d

4 files changed

Lines changed: 10 additions & 59 deletions

File tree

Package.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import PackageDescription
33
let package = Package(
44
name: "CloudConfiguration",
55
dependencies: [
6-
.Package(url: "https://github.com/IBM-Swift/Configuration", majorVersion: 0),
7-
.Package(url: "https://github.com/IBM-Swift/Swift-cfenv.git", majorVersion: 2)
6+
.Package(url: "https://github.com/IBM-Swift/Swift-cfenv.git", majorVersion: 3)
87
]
98
)

Sources/CloudFoundryConfig/Extensions.swift

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

17-
18-
1917
import Configuration
20-
2118
import CloudFoundryEnv
2219

2320
/**
@@ -30,118 +27,74 @@ public enum ConfigurationManagerError: Error {
3027

3128
extension ConfigurationManager {
3229

33-
private func findService(name: String) throws -> Service? {
34-
35-
let appEnv = try CloudFoundryEnv.getAppEnv(configManager: self)
36-
return appEnv.getService(spec: name)
37-
38-
}
39-
4030
public func getCloudantService(name: String) throws -> CloudantService {
4131

42-
if let service = try findService(name: name),
32+
if let service = getService(spec: name),
4333
let cloudantService = CloudantService(withService: service) {
4434
return cloudantService
4535
} else {
4636
throw ConfigurationManagerError.noServiceWithName(name)
4737
}
48-
49-
5038
}
5139

5240
public func getMongoDBService(name: String) throws -> MongoDBService {
5341

54-
if let service = try findService(name: name),
42+
if let service = getService(spec: name),
5543
let mongoDBService = MongoDBService(withService: service) {
5644
return mongoDBService
5745
} else {
5846
throw ConfigurationManagerError.noServiceWithName(name)
5947
}
60-
61-
6248
}
6349

6450
public func getRedisService(name: String) throws -> RedisService {
6551

66-
if let service = try findService(name: name),
52+
if let service = getService(spec: name),
6753
let redisService = RedisService(withService: service) {
6854
return redisService
6955
} else {
7056
throw ConfigurationManagerError.noServiceWithName(name)
7157
}
72-
7358
}
7459

7560
public func getPostgreSQLService(name: String) throws -> PostgreSQLService {
7661

77-
if let service = try findService(name: name),
62+
if let service = getService(spec: name),
7863
let postgreSQLService = PostgreSQLService(withService: service) {
7964
return postgreSQLService
8065
} else {
8166
throw ConfigurationManagerError.noServiceWithName(name)
8267
}
83-
8468
}
8569

8670
public func getMySQLService(name: String) throws -> MySQLService {
8771

88-
if let service = try findService(name: name),
72+
if let service = getService(spec: name),
8973
let mySQLService = MySQLService(withService: service) {
9074
return mySQLService
9175
} else {
9276
throw ConfigurationManagerError.noServiceWithName(name)
9377
}
94-
9578
}
9679

9780
public func getDB2Service(name: String) throws -> DB2Service {
9881

99-
if let service = try findService(name: name),
82+
if let service = getService(spec: name),
10083
let myDB2Service = DB2Service(withService: service) {
10184
return myDB2Service
10285
} else {
10386
throw ConfigurationManagerError.noServiceWithName(name)
10487
}
105-
10688
}
10789

10890
public func getAlertNotificationService(name: String) throws -> AlertNotificationService {
10991

110-
if let service = try findService(name: name),
92+
if let service = getService(spec: name),
11193
let alertNotificationService = AlertNotificationService(withService: service) {
11294
return alertNotificationService
11395
} else {
11496
throw ConfigurationManagerError.noServiceWithName(name)
11597
}
116-
117-
}
118-
119-
public var applicationPort: Int {
120-
121-
if let port = try? CloudFoundryEnv.getAppEnv().port {
122-
return port
123-
} else {
124-
return 8080
125-
}
126-
127-
}
128-
}
129-
130-
131-
extension CloudFoundryEnv {
132-
133-
public static func getAppEnv(configManager: ConfigurationManager) throws -> AppEnv {
134-
135-
let servs = configManager["VCAP_SERVICES"]
136-
137-
let app = configManager["VCAP_APPLICATION"]
138-
var vcap: [String:Any] = [:]
139-
140-
vcap["application"] = app
141-
vcap["services"] = servs
142-
var config: [String:Any] = [:]
143-
config["vcap"] = vcap
144-
return try AppEnv(options: config)
14598
}
14699

147100
}

Sources/CloudFoundryConfig/Services.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import Foundation
18-
1918
import CloudFoundryEnv
2019

2120
public class CloudantService: Service {

Tests/CloudFoundryConfigTests/FileLoadTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import Foundation
1919
import Configuration
2020
@testable import CloudFoundryConfig
2121

22-
2322
class FileLoadTests: XCTestCase {
2423

2524
static var allTests : [(String, (FileLoadTests) -> () throws -> Void)] {
@@ -35,7 +34,8 @@ class FileLoadTests: XCTestCase {
3534
do {
3635
// Modify relative path for your system, make more dynamic later
3736
let filePath = URL(fileURLWithPath: #file).appendingPathComponent("../config_example.json").standardized
38-
try manager.load(url: filePath)
37+
let loaded = manager.load(url: filePath)
38+
XCTAssertTrue(loaded)
3939

4040
let cloudantService = try manager.getCloudantService(name: "CloudantService")
4141

0 commit comments

Comments
 (0)