コード例 #1
0
def post_new_blueprint(revision_msg=None,
                       blueprint_name=None,
                       aadm_id=None,
                       username=None,
                       project_domain=None):  # noqa: E501
    """Add new blueprint.

    :param revision_msg: Optional comment on submission
    :type revision_msg: str
    :param blueprint_name: Optional human-readable blueprint name
    :type blueprint_name: str
    :param aadm_id: End-to-end debugging id
    :type aadm_id: str
    :param username: End-to-end debugging id
    :type username: str
    :param project_domain: Optional project domain this blueprint belongs to
    :type project_domain: str

    :rtype: Blueprint
    """
    # check roles
    if project_domain and not security_controller.check_roles(project_domain):
        return f"Unauthorized request for project: {project_domain}", 401

    file = connexion.request.files['CSAR']

    result, response = CSAR_db.add_revision(CSAR=file,
                                            revision_msg=revision_msg)

    if result is None:
        return f"Invalid CSAR: {response}", 406

    blueprint_meta = BlueprintVersion.from_dict(result)

    blueprint_meta.blueprint_name = blueprint_name
    blueprint_meta.project_domain = project_domain
    blueprint_meta.aadm_id = aadm_id
    blueprint_meta.username = username

    if not PostgreSQL.save_blueprint_meta(blueprint_meta):
        blueprint_id = blueprint_meta.blueprint_id
        return f"Failed to save project data for blueprint_id={blueprint_id}", 500

    PostgreSQL.save_git_transaction_data(
        blueprint_id=result['blueprint_id'],
        version_id=result['version_id'],
        revision_msg=f"Saved new blueprint: {revision_msg}",
        job='update',
        git_backend=str(CSAR_db.connection.git_connector),
        repo_url=result['url'],
        commit_sha=result['commit_sha'])

    return blueprint_meta, 201
コード例 #2
0
def post_blueprint(blueprint_id, revision_msg=None):
    """Add new version to existing blueprint.

    :param blueprint_id: Id of blueprint
    :type blueprint_id:
    :param revision_msg: Optional comment on submission
    :type revision_msg: str

    :rtype: Blueprint
    """
    file = connexion.request.files['CSAR']

    result, response = CSAR_db.add_revision(CSAR=file,
                                            revision_msg=revision_msg,
                                            blueprint_id=blueprint_id)

    if result is None:
        return f"Invalid CSAR: {response}", 406

    blueprint_meta = BlueprintVersion.from_dict(result)
    # copy blueprint params from first revision
    blueprint_meta_old = BlueprintVersion.from_dict(
        PostgreSQL.get_blueprint_meta(blueprint_id, 'v1.0'))
    blueprint_meta.blueprint_name = blueprint_meta_old.blueprint_name
    blueprint_meta.project_domain = blueprint_meta_old.project_domain
    blueprint_meta.aadm_id = blueprint_meta_old.aadm_id
    blueprint_meta.username = blueprint_meta_old.username

    if not PostgreSQL.save_blueprint_meta(blueprint_meta):
        return f"Failed to save project data for blueprint_id={blueprint_id}", 500

    PostgreSQL.save_git_transaction_data(
        blueprint_id=result['blueprint_id'],
        version_id=result['version_id'],
        revision_msg=f"Updated blueprint: {revision_msg}",
        job='update',
        git_backend=str(CSAR_db.connection.git_connector),
        repo_url=result['url'],
        commit_sha=result['commit_sha'])

    return blueprint_meta, 201