def _get_versioned_url(version): if version[-1] != '/': version += '/' # If host_href is not set in barbican conf, then derive it from request url host_part = utils.get_base_url_from_request() if host_part[-1] != '/': host_part += '/' return parse.urljoin(host_part, version)
def validate(self, json_data, parent_schema=None): schema_name = self._full_name(parent_schema) self._assert_schema_is_valid(json_data, schema_name) container_type = json_data.get('type') secret_refs = json_data.get('secret_refs') if not secret_refs: return json_data secret_refs_names = set(secret_ref.get('name', '') for secret_ref in secret_refs) self._assert_validity( len(secret_refs_names) == len(secret_refs), schema_name, u._("Duplicate reference names are not allowed"), "secret_refs") # The combination of container_id and secret_id is expected to be # primary key for container_secret so same secret id (ref) cannot be # used within a container secret_ids = set(self._get_secret_id_from_ref(secret_ref) for secret_ref in secret_refs) self._assert_validity( len(secret_ids) == len(secret_refs), schema_name, u._("Duplicate secret ids are not allowed"), "secret_refs") # Ensure that our secret refs are valid relative to our config, no # spoofing allowed! req_host_href = utils.get_base_url_from_request() for secret_ref in secret_refs: if not secret_ref.get('secret_ref').startswith(req_host_href): raise exception.UnsupportedField( field='secret_ref', schema=schema_name, reason=u._( "Secret_ref does not match the configured hostname, " "please try again" ) ) if container_type == 'rsa': self._validate_rsa(secret_refs_names, schema_name) elif container_type == 'certificate': self._validate_certificate(secret_refs_names, schema_name) return json_data