in webaction/webaction.go [196:248]
func ValidateRequireWhiskAuthAnnotationValue(actionName string, value interface{}) (string, error) {
var isValid = false
var enabled = wski18n.FEATURE_DISABLED
switch value.(type) {
case string:
secureValue := value.(string)
// assure the user-supplied token is valid (i.e., for now a non-empty string)
if len(secureValue) != 0 && secureValue != "<nil>" {
isValid = true
enabled = wski18n.FEATURE_ENABLED
}
case int:
secureValue := value.(int)
// FYI, the CLI defines MAX_JS_INT = 1<<53 - 1 (i.e., 9007199254740991)
// NOTE: For JS, the largest exact integral value is 253-1, or 9007199254740991.
// In ES6, this is defined as Number MAX_SAFE_INTEGER.
// However, in JS, the bitwise operators and shift operators operate on 32-bit ints,
// so in that case, the max safe integer is 231-1, or 2147483647
// We also disallow negative integers
// NOTE: when building for 386 archs. we need to assure comparison with MAX_JS_INT does not
// "blow up" and must allow the compiler to compare an untyped int (secureValue) to effectively
// an int64... so for the comparison we MUST force a type conversion to avoid "int" size mismatch
if int64(secureValue) < MAX_JS_INT && secureValue > 0 {
isValid = true
enabled = wski18n.FEATURE_ENABLED
}
case bool:
secureValue := value.(bool)
isValid = true
if secureValue {
enabled = wski18n.FEATURE_ENABLED
}
}
if !isValid {
errMsg := wski18n.T(wski18n.ID_ERR_WEB_ACTION_REQUIRE_AUTH_TOKEN_INVALID_X_action_X_key_X_value,
map[string]interface{}{
wski18n.KEY_ACTION: actionName,
wski18n.KEY_KEY: REQUIRE_WHISK_AUTH,
wski18n.KEY_VALUE: fmt.Sprintf("%v", value)})
return errMsg, wskderrors.NewActionSecureKeyError(errMsg)
}
// Emit an affirmation that security token will be applied to the action
msg := wski18n.T(wski18n.ID_VERBOSE_ACTION_AUTH_X_action_X_value_X,
map[string]interface{}{
wski18n.KEY_ACTION: actionName,
wski18n.KEY_VALUE: enabled})
wskprint.PrintlnOpenWhiskVerbose(utils.Flags.Verbose, msg)
return msg, nil
}