Skip to content

Commit 9095400

Browse files
committed
Add validation logic in loop
1 parent f670a91 commit 9095400

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

r/sparkr/R/osconfig.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ CloudObjectStorage <- setRefClass("CloudObjectStorage",
138138
validateInput(credentials, cosType, authMethod)
139139

140140
# set up hadoop config
141-
142141
if (is.null(credentials["endpoint"][[1]])) {
143142
stop("Attribute endpoint in credentials is missing!")
144143
}
@@ -173,8 +172,10 @@ CloudObjectStorage <- setRefClass("CloudObjectStorage",
173172
requiredKeys = get_required_key_array(cosType, authMethod)
174173

175174
# check the existence of all required values in credentials
176-
for (name in names(requiredKeys)) {
177-
175+
for (key in requiredKeys) {
176+
if (!key %in% credentials) {
177+
stop("Invalid input: missing required input [" + key + "]!")
178+
}
178179
}
179180

180181
},
@@ -186,14 +187,14 @@ CloudObjectStorage <- setRefClass("CloudObjectStorage",
186187

187188
if (cosType == "bluemix_cos") {
188189
if (authMethod == "api_key") {
189-
return requiredKeyListIamApiKey
190+
return (requiredKeyListIamApiKey)
190191
} else if (authMethod == "iam_token") {
191-
return requiredKeyListIamToken
192+
return (requiredKeyListIamToken)
192193
} else {
193194
stop("Invalid input: authMethod. authMethod is optional but if set, it should have one of the following values: api_key, iam_token")
194195
}
195196
} else if (cosType == "softlayer_cos") {
196-
return requiredKeySoftlayerCos
197+
return (requiredKeySoftlayerCos)
197198
} else {
198199
stop("Invalid input: cosType. cosType is optional but if set, it should have one of the following values: softlayer_cos, bluemix_cos")
199200
}

0 commit comments

Comments
 (0)