예제 #1
0
    def get_note_with_access_check(self, context, note_id):
        """Retrieve the note and checks user access to the note

        :param context: the request context
        :param note_id: the id of the note to retrieve.
        :returns: the note
        """
        try:
            note = notes_helper.get_note(note_id)
            note_type = notes_helper.get_note_assoc_id_type(note)
            if note_type not in NOTE_TYPE_RBAC:
                raise ApiError(
                    title="Unable to check permission for note type",
                    description=(
                        "Shipyard is not correctly identifying note type "
                        "for note {}".format(note_id)),
                    status=falcon.HTTP_500,
                    retry=False)
            policy.check_auth(context, NOTE_TYPE_RBAC[note_type])
            return note
        except NoteNotFoundError:
            raise ApiError(
                title="No note found",
                description=("Note {} is not found".format(note_id)),
                status=falcon.HTTP_404)
예제 #2
0
    def on_get(self, req, resp, collection_id):
        """
        Returns a collection of documents
        """
        version = (req.params.get('version') or 'buffer')
        cleartext_secrets = req.get_param_as_bool('cleartext-secrets') or False
        self._validate_version_parameter(version)
        helper = ConfigdocsHelper(req.context)

        # Check access to cleartext_secrets
        if cleartext_secrets:
            policy.check_auth(req.context, policy.GET_CONFIGDOCS_CLRTXT)

        # Not reformatting to JSON or YAML since just passing through
        resp.body = self.get_collection(
            helper=helper, collection_id=collection_id, version=version,
            cleartext_secrets=cleartext_secrets)
        resp.append_header('Content-Type', 'application/x-yaml')
        resp.status = falcon.HTTP_200
예제 #3
0
    def on_get(self, req, resp):
        """
        Returns the whole set of rendered documents
        """
        version = (req.params.get('version') or 'buffer')
        cleartext_secrets = req.get_param_as_bool('cleartext-secrets') or False
        self._validate_version_parameter(version)
        helper = ConfigdocsHelper(req.context)

        # Check access to cleartext_secrets
        if cleartext_secrets:
            policy.check_auth(req.context,
                              policy.GET_RENDEREDCONFIGDOCS_CLRTXT)

        resp.body = self.get_rendered_configdocs(
            helper=helper,
            version=version,
            cleartext_secrets=cleartext_secrets)
        resp.append_header('Content-Type', 'application/x-yaml')
        resp.status = falcon.HTTP_200
예제 #4
0
    def create_action(self, action, context, allow_intermediate_commits=False):
        # use uuid assigned for this request as the id of the action.
        action['id'] = ulid.ulid()
        # the invoking user
        action['user'] = context.user
        # add current timestamp (UTC) to the action.
        action['timestamp'] = str(datetime.utcnow())
        # add external marker that is the passed with request context
        action['context_marker'] = context.request_id
        # validate that action is supported.
        LOG.info("Attempting action: %s", action['name'])
        action_mappings = _action_mappings()
        if action['name'] not in action_mappings:
            raise ApiError(title='Unable to start action',
                           description='Unsupported Action: {}'.format(
                               action['name']))

        action_cfg = action_mappings.get(action['name'])

        # check access to specific actions - lack of access will exception out
        policy.check_auth(context, action_cfg['rbac_policy'])

        dag = action_cfg['dag']
        action['dag_id'] = dag

        # Set up configdocs_helper
        self.configdocs_helper = ConfigdocsHelper(context)

        # Retrieve last committed design revision
        action['committed_rev_id'] = self.get_committed_design_version()
        # Set if intermediate commits are ignored
        action['allow_intermediate_commits'] = allow_intermediate_commits

        # populate action parameters if they are not set
        if 'parameters' not in action:
            action['parameters'] = {}

        for validator in action_cfg['validators']:
            # validators will raise ApiError if they fail validation.
            # validators are expected to accept action as a parameter, but
            # handle all other kwargs (e.g. def vdtr(action, **kwargs): even if
            # they don't use that parameter.
            validator(action=action, configdocs_helper=self.configdocs_helper)

        # invoke airflow, get the dag's date
        dag_execution_date = self.invoke_airflow_dag(dag_id=dag,
                                                     action=action,
                                                     context=context)
        # set values on the action
        action['dag_execution_date'] = dag_execution_date
        action['dag_status'] = 'SCHEDULED'

        # insert the action into the shipyard db
        # TODO(b-str): When invoke_airflow_dag triggers a DAG but fails to
        #    respond properly, no record is inserted, so there is a running
        #    process with no tracking in the Shipyard database. This is not
        #    ideal.
        self.insert_action(action=action)
        notes_helper.make_action_note(action_id=action['id'],
                                      note_val="Configdoc revision {}".format(
                                          action['committed_rev_id']))
        self.audit_control_command_db({
            'id': ulid.ulid(),
            'action_id': action['id'],
            'command': 'invoke',
            'user': context.user
        })

        return action