

def _set_project_domain_id(self, req, path_parts, env_identity):
    '\n        Try to determine the project domain id and save it as\n        account metadata. Do this for a PUT or POST to the\n        account, and also for a container PUT in case that\n        causes the account to be auto-created.\n        '
    if (PROJECT_DOMAIN_ID_SYSMETA_HEADER in req.headers):
        return
    (version, account, container, obj) = path_parts
    method = req.method
    if (obj or (container and (method != 'PUT')) or (method not in ['PUT', 'POST'])):
        return
    (tenant_id, tenant_name) = env_identity['tenant']
    (exists, sysmeta_id) = self._get_project_domain_id(req.environ)
    (req_has_id, req_id, new_id) = (False, None, None)
    if self._account_matches_tenant(account, tenant_id):
        req_has_id = True
        req_id = env_identity['project_domain'][0]
    if (not exists):
        new_id = (req_id if req_has_id else UNKNOWN_ID)
    elif ((sysmeta_id is None) and (req_id == self.default_domain_id)):
        new_id = req_id
    elif ((sysmeta_id == UNKNOWN_ID) and req_has_id):
        new_id = (req_id or '')
    elif (req_has_id and (sysmeta_id != req_id)):
        self.logger.warning(('Inconsistent project domain id: ' + ('%s in token vs %s in account metadata.' % (req_id, sysmeta_id))))
    if (new_id is not None):
        req.headers[PROJECT_DOMAIN_ID_SYSMETA_HEADER] = new_id

dataset/ETHPy150Open openstack/swift/swift/common/middleware/keystoneauth.py KeystoneAuth._set_project_domain_id/original