def recipe(path, owner, tag, create_repo):
    """push a queenbee recipe to the pollination registry

    This subcommand pushes a packaged queenbee recipe to a registry on
    pollination cloud
    """
    ctx = click.get_current_context()
    client = ctx.obj.get_client()

    if owner is None:
        account = client.get_account()
        owner = account.username

    try:
        manifest = Recipe.from_folder(path)
    except ValidationError as error:
        raise click.ClickException(error)
    except FileNotFoundError as error:
        raise click.ClickException(error)
    except Exception as error:
        raise error

    handle_repository(client=client,
                      repo_type='recipe',
                      owner=owner,
                      name=manifest.metadata.name,
                      create_repo=create_repo)

    if tag is not None:
        manifest.metadata.tag = tag

    readme_string = RecipeVersion.read_readme(path)
    license_string = RecipeVersion.read_license(path)

    if readme_string is None:
        readme_string = ''

    if license_string is None:
        license_string = ''

    new_package = {
        'manifest': manifest.to_dict(),
        'readme': readme_string,
        'license': license_string
    }

    try:
        client.recipes.create_recipe_package(
            owner=owner,
            name=manifest.metadata.name,
            new_recipe_package=new_package,
        )
    except ApiException as error:
        raise click.ClickException(error)

    click.echo(
        f'Successfully created new recipe package {owner}/{manifest.metadata.name}:{manifest.metadata.tag}'
    )
Exemple #2
0
def recipe(name, owner, tag, path, force):
    """download a recipe from a pollination registry"""
    ctx = click.get_current_context()
    client = ctx.obj.get_client()

    path = os.path.abspath(path)
    path = os.path.join(path, name)

    if owner is None:
        account = client.get_account()
        owner = account.username

    if tag is None:
        try:
            res = client.recipes.get_recipe(
                owner=owner,
                name=name,
            )
        except ApiException as error:
            if error.status == 404:
                raise click.ClickException(f'Recipe not found: {owner}/{name}')
            raise click.ClickException(error)

        tag = res['latest_tag']

    try:
        res = client.recipes.get_recipe_tag(
            owner=owner,
            name=name,
            tag=tag
        )
    except ApiException as error:
        if error.status == 404:
            raise click.ClickException(f'Recipe not found: {owner}/{name}:{tag}')
        raise click.ClickException(error)

    manifest = Recipe.parse_obj(res['manifest'])

    try:
        manifest.to_folder(
            folder_path=path,
            readme_string=res['readme'],
            license_string=res['license'],
        )
    except FileExistsError as error:
        if not force:
            raise click.ClickException(f'Folder already exists at path {path}. Use "--force" to overwrite it.')

        shutil.rmtree(path)

        manifest.to_folder(
            folder_path=path,
            readme_string=res['readme'],
            license_string=res['license'],
        )

    click.echo(f'Recipe {owner}/{name}:{tag} saved to {path}')
 def test_raise_value_error(self, invalid_recipe):
     invalid_recipe = Recipe.from_file(invalid_recipe)
     with pytest.raises(ValueError):
         BakedRecipe.from_recipe(invalid_recipe)
 def test_value_error_message(self, invalid_recipe, error_message):
     invalid_recipe = Recipe.from_file(invalid_recipe)
     with pytest.raises(ValueError, match=error_message):
         BakedRecipe.from_recipe(invalid_recipe)
Exemple #5
0
with open(os.path.join(folder, 'workflow-openapi.json'), 'w') as out_file:
    json.dump(
        get_openapi(schema_class=Workflow, title='Queenbee Workflow Schema', description='Schema documentation for Queenbee Workflows'),
        out_file,
        indent=2
    )

with open(os.path.join(folder, 'operator-openapi.json'), 'w') as out_file:
    json.dump(
        get_openapi(schema_class=Operator, title='Queenbee Operator Schema', description='Schema documentation for Queenbee Operators'),
        out_file,
        indent=2
    )

with open(os.path.join(folder, 'recipe-openapi.json'), 'w') as out_file:
    json.dump(
        get_openapi(schema_class=Recipe, title='Queenbee Recipe Schema', description='Schema documentation for Queenbee Recipes'),
        out_file,
        indent=2
    )

with open(os.path.join(folder, 'workflow-schema.json'), 'w') as out_file:
    out_file.write(Workflow.schema_json())

with open(os.path.join(folder, 'operator-schema.json'), 'w') as out_file:
    out_file.write(Operator.schema_json())

with open(os.path.join(folder, 'recipe-schema.json'), 'w') as out_file:
    out_file.write(Recipe.schema_json())