4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 from cmframework.apis import cmvalidator
20 from cmdatahandlers.api import validation
23 class UsersValidation(cmvalidator.CMValidator):
24 domain = 'cloud.users'
26 def get_subscription_info(self):
27 logging.debug('get_subscription info called')
28 return r'^cloud\.users$'
30 def validate_set(self, dict_key_value):
31 user_attr = 'admin_user_name'
32 passwd_attr = 'admin_user_password'
33 init_user_attr = 'initial_user_name'
34 init_passwd_attr = 'initial_user_password'
36 logging.debug('validate_set called with %s' % str(dict_key_value))
38 value_str = dict_key_value.get(self.domain)
39 value_dict = {} if not value_str else json.loads(value_str)
41 raise validation.ValidationError('No value for %s' % self.domain)
42 if not isinstance(value_dict, dict):
43 raise validation.ValidationError('%s value is not a dict' % self.domain)
45 utils = validation.ValidationUtils()
46 user = value_dict.get(user_attr)
48 utils.validate_username(user)
50 raise validation.ValidationError('Missing %s' % user_attr)
51 um_user = value_dict.get(init_user_attr)
53 utils.validate_username(um_user)
55 raise validation.ValidationError('Missing %s' % init_user_attr)
57 if not value_dict.get(passwd_attr):
58 raise validation.ValidationError('Missing %s' % passwd_attr)
59 if not value_dict.get(init_passwd_attr):
60 raise validation.ValidationError('Missing %s' % init_passwd_attr)
62 def validate_delete(self, dict_key_value):
63 logging.debug('validate_delete called with %s' % str(dict_key_value))
64 raise validation.ValidationError('%s cannot be deleted' % self.domain)