Skip to content

Commit 0d829ae

Browse files
committed
Add implementation of the validation function.
1 parent 0792d63 commit 0d829ae

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

scala/src/main/scala/Osconfig.scala

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ class bluemix(sc: SparkContext, name: String, creds: HashMap[String, String],
150150
if a configuration name is not passed the default one will be used "service".
151151
*/
152152
class CloudObjectStorage(sc: SparkContext, credentials: HashMap[String, String],
153-
configurationName: String = "", cos_type="softlayer_cos",
154-
auth_method="api_key") {
153+
configurationName: String = "", cosType="softlayer_cos",
154+
authMethod="api_key") {
155155

156156
// check for valid credentials
157-
_validate_credentials(credentials, cos_type, auth_method)
157+
_validate_credentials(credentials, cosType, authMethod)
158158

159159
val requiredValues = Array("endPoint", "accessKey", "secretKey")
160160
for ( key <- requiredValues ) {
@@ -179,8 +179,28 @@ class CloudObjectStorage(sc: SparkContext, credentials: HashMap[String, String],
179179
}
180180
}
181181

182-
private def _validate_credentials() {
182+
private def _validate_credentials(credentials, cosType, authMethod) : Array {
183+
val requiredKeys = _get_required_key_array()
184+
}
183185

186+
private def _get_required_key_array(credentials, cosType, authMethod) {
187+
val required_key_softlayer_cos = Array("endPoint", "accessKey", "secretKey")
188+
val required_key_list_iam_api_key = Array("endPoint", "apiKey", "serviceId")
189+
val required_key_list_iam_token = Array("endPoint", "iamToken", "serviceId")
190+
191+
if (cosType == "bluemix_cos") {
192+
if (authMethod == "api_key") {
193+
return required_key_list_iam_api_key
194+
} else if (authMethod == "iam_token") {
195+
return required_key_list_iam_token
196+
} else {
197+
throw new IllegalArgumentException("Invalid input: authMethod. authMethod is optional but if set, it should have one of the following values: api_key, iam_token")
198+
}
199+
} else if (cosType == "softlayer_cos") {
200+
return required_key_softlayer_cos
201+
} else {
202+
throw new IllegalArgumentException("Invalid input: cosType. cosType is optional but if set, it should have one of the following values: softlayer_cos, bluemix_cos")
203+
}
184204
}
185205

186206
def url(bucketName: String, objectName: String) : String = {

0 commit comments

Comments
 (0)