@@ -492,58 +492,32 @@ def __getattr__(self, config_property):
492492
493493 """
494494
495- if not self .is_valid_platform ():
496- raise NotValidPlatformException (
497- 'You are not running on Platform.sh, so the {0} variable is not available.' .format (config_property )
498- )
499495 is_build_var = config_property in self ._directVariables .keys ()
500496 is_runtime_var = config_property in self ._directVariablesRuntime .keys ()
501497
502498 # For now, all unprefixed variables are also runtime variables. If that ever changes this logic will change
503499 # with it.
504500 is_unprefixed_var = config_property in self ._unPrefixedVariablesRuntime .keys ()
505501
506- if self .in_build () and is_runtime_var :
507- raise BuildTimeVariableAccessException (
508- 'The {0} variable is not available during build time.' .format (config_property )
509- )
510502 if is_build_var :
511- return self [self ._directVariables [config_property ]]
512- if is_runtime_var :
513- return self [self ._directVariablesRuntime [config_property ]]
514- if is_unprefixed_var :
515- return self ._environmentVariables .get (self ._unPrefixedVariablesRuntime [config_property ])
516- raise AttributeError ('No such variable defined: ' .format (config_property ))
517-
518- def isset (self , config_property ):
519- """Checks whether a configuration property is set.
520-
521- Args:
522- config_property:
523- A (magic) property name.
524-
525- Returns:
526- bool:
527- True if the property exists and is not None, False otherwise.
528-
529- """
530-
531- if not self .is_valid_platform ():
532- return False
533-
534- is_build_var = config_property in self ._directVariables .keys ()
535- is_runtime_var = config_property in self ._directVariablesRuntime .keys ()
536-
537- # For now, all unprefixed variables are also runtime variables. If that ever changes this logic will change
538- # with it.
539- is_unprefixed_var = config_property in self ._unPrefixedVariablesRuntime .keys ()
540-
541- if self .in_build ():
542- return is_build_var and config_property is not None
543- if is_build_var or is_runtime_var or is_unprefixed_var :
544- return config_property is not None
545- return False
503+ value = self [self ._directVariables [config_property ]]
504+ elif is_runtime_var :
505+ value = self [self ._directVariablesRuntime [config_property ]]
506+ elif is_unprefixed_var :
507+ value = self ._environmentVariables .get (self ._unPrefixedVariablesRuntime [config_property ])
508+ else :
509+ raise AttributeError ('No such variable defined: {}' .format (config_property ))
510+
511+ if not value :
512+ if self .in_build () and (is_runtime_var or is_unprefixed_var ):
513+ raise BuildTimeVariableAccessException (
514+ 'The {} variable is not available during build time.' .format (config_property )
515+ )
516+ raise NotValidPlatformException (
517+ 'The {} variable is not defined. Are you sure you\' re running on Platform.sh?' .format (config_property )
518+ )
546519
520+ return value
547521
548522def pymongo_formatter (credentials ):
549523 """Returns a DSN for a pymongo-MongoDB connection.
0 commit comments