CloudEnv
public class CloudEnv
A convenience class for obtaining environment variables that are mapped to JSON strings. It is mainly used for obtaining credentials for services so Swift applications can be written in a platform agnostic way.
There is a lot of information in the README
explaining how you can use cloudEnv to access credentials for your services; more specific information is listed in the
API documentation below.
-
Name of the mappings file. This is set to
mappings.json
.Declaration
Swift
public static let mappingsFile = "mappings.json" -
Port number the application can listen to.
Declaration
Swift
public var port: Int -
URL that can be assigned to the application.
Declaration
Swift
public var url: String -
Initialize an instance of
CloudEnv.Usage Example:
let cloudEnv = CloudEnv()The example below shows how to load configuration from both a
mappings.jsonfile and a Cloud Foundry credentials file when neither are in the default directory.let cloudEnv = CloudEnv(mappingsFilePath: "resources/mappings", cloudFoundryFile: "resources cfresources/cf.json")Declaration
Swift
public init(mappingsFilePath: String? = nil, cloudFoundryFile: String? = nil)Parameters
mappingsFilePathOptional. The path to the
mappings.jsonfile; this path should be relative to the root folder of the Swift application.cloudFoundryFileOptional. The path to a JSON file that contains values for Cloud Foundry environment variables (mainly used for testing); this path should be relative to the current working directory (which in most cases is the folder of the Swift application).
-
Returns the corresponding JSON dictionary value in a string.
If the service you intend to use in your Swift application is not one which we explicitly support, you can leverage the generic
getString(name: String)method to get the corresponding credentials.Usage Example:
let cloudEnv = CloudEnv() if let credentials = cloudEnv.getString(name: "service1-credentials") { // You can now get the corresponding values from the credentials string. // The result string will follow JSON notation. }Declaration
Swift
public func getString(name: String) -> String?Parameters
nameThe key to lookup the environment variable.
-
Returns the corresponding dictionary value.
If the service you intend to use in your Swift application is not one which we explicitly support, you can leverage the generic
getDictionary(name: String)method to get the corresponding credentials.Usage Example:
let cloudEnv = CloudEnv() if let credentials: [String:Any] = cloudEnv.getDictionary(name: "service1-credentials") { // You can now get the corresponding values from the dictionary. }Declaration
Swift
public func getDictionary(name: String) -> [String : Any]?Parameters
nameThe key to lookup the environment variable.
-
Returns an AlertNotificationCredentials object with the corresponding credentials.
Usage Example:
let cloudEnv = CloudEnv() credentials = cloudEnv.getAlertNotificationCredentials(name: "AlertNotificationKey")Declaration
Swift
public func getAlertNotificationCredentials (name: String) -> AlertNotificationCredentials?Parameters
nameThe key to lookup the environment variable.
-
Returns an AppIDCredentials object with the corresponding credentials.
Usage Example:
let cloudEnv = CloudEnv() credentials = cloudEnv.getAppIDCredentials(name: "AppIDKey")Declaration
Swift
public func getAppIDCredentials(name: String) -> AppIDCredentials?Parameters
nameThe key to lookup the environment variable.
-
Returns an AutoScalingCredentials object with the corresponding credentials.
Usage Example:
let cloudEnv = CloudEnv() credentials = cloudEnv.getAutoScalingCredentials(name: "AutoScalingKey")Declaration
Swift
public func getAutoScalingCredentials (name: String) -> AutoScalingCredentials?Parameters
nameThe key to lookup the environment variable.
-
Returns a CloudFunctionsCredentials object with the corresponding credentials.
Usage Example:
let cloudEnv = CloudEnv() credentials = cloudEnv.getCloudFunctionsCredentials(name: "CloudFunctionsKey")Declaration
Swift
public func getCloudFunctionsCredentials(name: String) -> CloudFunctionsCredentials?Parameters
nameThe key to lookup the credentials.
-
Returns a CloudantCredentials object with the corresponding credentials.
Usage Example:
let cloudEnv = CloudEnv() credentials = cloudEnv.getCloudantCredentials(name: "CloudantKey")Declaration
Swift
public func getCloudantCredentials(name: String) -> CloudantCredentials?Parameters
nameThe key to lookup the environment variable.
-
Returns an DB2Credentials object with the corresponding credentials.
Usage Example:
let cloudEnv = CloudEnv() credentials = cloudEnv.getDB2Credentials(name: "DB2Key")Declaration
Swift
public func getDB2Credentials (name: String) -> DB2Credentials?Parameters
nameThe key to lookup the environment variable.
-
Returns a HyperSecureDBaaSCredentials object with the corresponding credentials.
Usage Example:
let cloudEnv = CloudEnv() credentials = cloudEnv.getHyperSecureDBaaSCredentials(name: "HyperSecureDBaaSKey")Declaration
Swift
public func getHyperSecureDBaaSCredentials(name: String) -> HyperSecureDBaaSCredentials?Parameters
nameThe key to lookup the credentials object.
-
Returns a MongoDBCredentials object with the corresponding credentials.
Usage Example:
let cloudEnv = CloudEnv() credentials = cloudEnv.getMongoDBCredentials(name: "MongoDBKey")Declaration
Swift
public func getMongoDBCredentials(name: String) -> MongoDBCredentials?Parameters
nameThe key to lookup the credentials object.
-
Returns an MySQLCredentials object with the corresponding credentials.
Usage Example:
let cloudEnv = CloudEnv() credentials = cloudEnv.getMySQLCredentials(name: "MySQLKey")Declaration
Swift
public func getMySQLCredentials (name: String) -> MySQLCredentials?Parameters
nameThe key to lookup the environment variable.
-
Returns a NaturalLanguageUnderstandingCredentials object with the corresponding credentials.
Usage Example:
let cloudEnv = CloudEnv() credentials = cloudEnv.getNaturalLanguageUnderstandingCredentials(name: "NaturalLanguageUnderstandingKey")Declaration
Swift
public func getNaturalLanguageUnderstandingCredentials(name: String) -> NaturalLanguageUnderstandingCredentials?Parameters
nameThe key to lookup the credentials object.
-
Returns an ObjectStorageCredentials object with the corresponding credentials.
Usage Example:
let cloudEnv = CloudEnv() credentials = cloudEnv.getObjectStorageCredentials(name: "ObjectStorageKey")Declaration
Swift
public func getObjectStorageCredentials(name: String) -> ObjectStorageCredentials?Parameters
nameThe key to lookup the environment variable.
-
Returns an PostgreSQLCredentials object with the corresponding credentials.
Usage Example:
let cloudEnv = CloudEnv() credentials = cloudEnv.getPostgreSQLCredentials(name: "PostgreSQLKey")Declaration
Swift
public func getPostgreSQLCredentials(name: String) -> PostgreSQLCredentials?Parameters
nameThe key to lookup the environment variable.
-
Returns a PushSDKCredentials object with the corresponding credentials.
Usage Example:
let cloudEnv = CloudEnv() credentials = cloudEnv.getPushSDKCredentials(name: "PushNotificationKey")Declaration
Swift
public func getPushSDKCredentials(name: String) -> PushSDKCredentials?Parameters
nameThe key to lookup the credentials.
-
Returns an RedisCredentials object with the corresponding credentials.
Usage Example:
let cloudEnv = CloudEnv() credentials = cloudEnv.getRedisCredentials(name: "RedisKey")Declaration
Swift
public func getRedisCredentials(name: String) -> RedisCredentials?Parameters
nameThe key to lookup the environment variable.
-
Returns an WatsonAssistantCredentials object with the corresponding credentials.
Usage Example:
let cloudEnv = CloudEnv() credentials = cloudEnv.getWatsonAssistantCredentials(name: "WatsonAssistantCredentialsKey")Declaration
Swift
public func getWatsonAssistantCredentials(name: String) -> WatsonAssistantCredentials?Parameters
nameThe key to lookup the environment variable.
-
Returns an WeatherCompanyDataCredentials object with the corresponding credentials.
Usage Example:
let cloudEnv = CloudEnv() credentials = cloudEnv.getWeatherCompanyDataCredentials(name: "WeatherCompanyDataKey")Declaration
Swift
public func getWeatherCompanyDataCredentials(name: String) -> WeatherCompanyDataCredentials?Parameters
nameThe key to lookup the environment variable.
View on GitHub
CloudEnv Class Reference