Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b1cbbcb
Add --show-all flag to repo/package list
BartoszBlizniak Sep 25, 2024
f846fb2
Revert code changes
BartoszBlizniak Oct 9, 2024
14c7778
Merge branch 'master' into ceng-355-httpsgithubcomcloudsmith-ioclouds…
BartoszBlizniak Oct 9, 2024
cb080c4
Revert code changes
BartoszBlizniak Oct 9, 2024
2872493
Merge branch 'ceng-355-httpsgithubcomcloudsmith-iocloudsmith-clipull1…
BartoszBlizniak Oct 9, 2024
2eb9c38
Fix the code
BartoszBlizniak Oct 9, 2024
f36ae0a
Fix the code
BartoszBlizniak Oct 9, 2024
dd75831
Support upstreams with showall
BartoszBlizniak Oct 10, 2024
b596d7e
Clean up pagination to be re-useable
BartoszBlizniak Oct 11, 2024
9d8b666
ceng-225-add-slug-to-doc
BartoszBlizniak Oct 11, 2024
ed7b665
ceng-330-add-format-flag-for-whoami
BartoszBlizniak Oct 11, 2024
c79c929
Add tests for --show-all flag
BartoszBlizniak Oct 16, 2024
73a53c8
Add tests for --show-all flag
BartoszBlizniak Oct 16, 2024
ce41ea2
feedback from Chris
BartoszBlizniak Oct 17, 2024
981a8f7
feedback from Chris
BartoszBlizniak Oct 30, 2024
526162d
feedback from Chris
BartoszBlizniak Oct 30, 2024
46278f0
policy changes
BartoszBlizniak Oct 31, 2024
aef30f5
Merge branch 'master' into ceng-355-httpsgithubcomcloudsmith-ioclouds…
BartoszBlizniak Nov 4, 2024
544a1ef
Merge branch 'master' into ceng-355-httpsgithubcomcloudsmith-ioclouds…
BartoszBlizniak Nov 6, 2024
df673ac
Fix error message when using page/page-size with showall and added tests
BartoszBlizniak Nov 8, 2024
fbb1130
Merge branch 'ceng-355-httpsgithubcomcloudsmith-iocloudsmith-clipull1…
BartoszBlizniak Nov 8, 2024
de5ab4d
Fix error message when using page/page-size with showall and added tests
BartoszBlizniak Nov 8, 2024
ab63085
Fix error message when using page/page-size with showall and added tests
BartoszBlizniak Nov 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ jobs:
asset_path: ./cloudsmith-${{ env.VERSION }}.pyz
asset_name: cloudsmith-${{ env.VERSION }}.pyz
asset_content_type: application/zip
- name: Rename asset to cloudsmith.pyz
run: mv ./cloudsmith-${{ env.VERSION }}.pyz cloudsmith.pyz
- name: Upload to Cloudsmith
run: ./cloudsmith.pyz push raw ${{ vars.CLOUDSMITH_NAMESPACE }}/${{ vars.CLOUDSMITH_REPO }} cloudsmith.pyz --name "cloudsmith-cli" --version ${{ env.VERSION }}
env:
CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }}
VERSION: ${{ env.VERSION }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ reports/
.env

# Zipapp
*.pyz
*.pyz
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ For most purposes, you probably just want `pip install -r requirements.txt`.

Our [direnv config](./.envrc) file codifies the development environment setup which we use internally.

Run `pre-commit run -a black` to format the code.

## Coding Conventions

Expand Down
2 changes: 1 addition & 1 deletion cloudsmith_cli/cli/commands/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def list_dependencies(ctx, opts, owner_repo_package):
no dependencies then it is possible that dependency extraction isn't support
for the package format yet.

- OWNER/REPO/PACKAGE: Specify the OWNER namespace (i.e. user or org), the
- OWNER/REPO/PACKAGE(Slug): Specify the OWNER namespace (i.e. user or org), the
REPO name where the package is stored, and the PACKAGE name (identifier) of the
package itself. All separated by a slash.

Expand Down
31 changes: 22 additions & 9 deletions cloudsmith_cli/cli/commands/list_.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ...core.api.packages import get_package_format_names_with_distros, list_packages
from .. import command, decorators, utils, validators
from ..exceptions import handle_api_exceptions
from ..utils import maybe_spinner
from ..utils import maybe_spinner, paginate_results
from . import dependencies, entitlements
from .main import main
from .repos import get as get_repos
Expand Down Expand Up @@ -128,7 +128,7 @@ def entitlements_(*args, **kwargs): # pylint: disable=missing-docstring
help=("A boolean-like search term for querying package attributes."),
)
@click.pass_context
def packages(ctx, opts, owner_repo, page, page_size, query):
def packages(ctx, opts, owner_repo, page, page_size, query, show_all):
"""
List packages for a repository.

Expand Down Expand Up @@ -176,8 +176,14 @@ def packages(ctx, opts, owner_repo, page, page_size, query):
context_msg = "Failed to get list of packages!"
with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg):
with maybe_spinner(opts):
packages_, page_info = list_packages(
owner=owner, repo=repo, page=page, page_size=page_size, query=query
packages_, page_info = paginate_results(
list_packages,
show_all,
page,
page_size,
owner=owner,
repo=repo,
query=query,
)

click.secho("OK", fg="green", err=use_stderr)
Expand Down Expand Up @@ -209,10 +215,17 @@ def packages(ctx, opts, owner_repo, page, page_size, query):
click.echo()

num_results = len(packages_)
list_suffix = "package%s visible" % ("s" if num_results != 1 else "")
utils.pretty_print_list_info(
num_results=num_results, page_info=page_info, suffix=list_suffix
)
list_suffix = "package%s" % ("s" if num_results != 1 else "")
if show_all:
utils.pretty_print_list_info(
num_results=num_results, suffix=f"{list_suffix} retrieved", show_all=True
)
else:
utils.pretty_print_list_info(
num_results=num_results,
page_info=page_info,
suffix=f"{list_suffix} visible",
)


@list_.command()
Expand All @@ -229,7 +242,7 @@ def packages(ctx, opts, owner_repo, page, page_size, query):
required=False,
)
@click.pass_context
def repos(ctx, opts, owner_repo, page, page_size):
def repos(ctx, opts, owner_repo, page, page_size, show_all):
"""
List repositories for a namespace (owner).

Expand Down
30 changes: 21 additions & 9 deletions cloudsmith_cli/cli/commands/policy/license.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
maybe_spinner,
maybe_truncate_list,
maybe_truncate_string,
paginate_results,
)
from .command import policy


def print_license_policies(policies):
"""Print license policies as a table or output in another format."""

headers = [
"Name",
"Description",
Expand Down Expand Up @@ -57,10 +56,6 @@ def print_license_policies(policies):
utils.pretty_print_table(headers, rows)
click.echo()

num_results = len(rows)
list_suffix = "license polic%s" % ("y" if num_results == 1 else "ies")
utils.pretty_print_list_info(num_results=num_results, suffix=list_suffix)


@policy.group(cls=command.AliasGroup, name="license", aliases=[])
@decorators.common_cli_config_options
Expand All @@ -85,8 +80,14 @@ def licence(*args, **kwargs):
@click.argument(
"owner", metavar="OWNER", callback=validators.validate_owner, required=True
)
@click.option(
"--show-all",
"-a",
is_flag=True,
help="Show all results, not just the current page",
)
@click.pass_context
def ls(ctx, opts, owner, page, page_size):
def ls(ctx, opts, owner, page, page_size, show_all):
"""
List license policies.

Expand All @@ -111,8 +112,8 @@ def ls(ctx, opts, owner, page, page_size):
context_msg = "Failed to get license policies!"
with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg):
with maybe_spinner(opts):
policies, page_info = api.list_license_policies(
owner=owner, page=page, page_size=page_size
policies, page_info = paginate_results(
api.list_license_policies, show_all, page, page_size, owner=owner
)

click.secho("OK", fg="green", err=use_stderr)
Expand All @@ -122,6 +123,17 @@ def ls(ctx, opts, owner, page, page_size):

print_license_policies(policies)

click.echo()

num_results = len(policies)
list_suffix = "license polic%s" % ("y" if num_results == 1 else "ies")
utils.pretty_print_list_info(
num_results=num_results,
page_info=None if show_all else page_info,
suffix=list_suffix,
show_all=show_all,
)


@licence.command(aliases=["new"])
@decorators.common_cli_config_options
Expand Down
29 changes: 21 additions & 8 deletions cloudsmith_cli/cli/commands/policy/vulnerability.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
from ....core.api import orgs as api
from ... import command, decorators, utils, validators
from ...exceptions import handle_api_exceptions
from ...utils import fmt_bool, fmt_datetime, maybe_spinner, maybe_truncate_string
from ...utils import (
fmt_bool,
fmt_datetime,
maybe_spinner,
maybe_truncate_string,
paginate_results,
)
from .command import policy


Expand Down Expand Up @@ -45,10 +51,6 @@ def print_vulnerability_policies(policies):
utils.pretty_print_table(headers, rows, title="Vulnerability Policies")
click.echo()

num_results = len(rows)
list_suffix = "vulnerability polic%s" % ("y" if num_results == 1 else "ies")
utils.pretty_print_list_info(num_results=num_results, suffix=list_suffix)


@policy.group(cls=command.AliasGroup, name="vulnerability", aliases=[])
@decorators.common_cli_config_options
Expand All @@ -74,7 +76,7 @@ def vulnerability(*args, **kwargs):
"owner", metavar="OWNER", callback=validators.validate_owner, required=True
)
@click.pass_context
def ls(ctx, opts, owner, page, page_size):
def ls(ctx, opts, owner, page, page_size, show_all):
"""
List vulnerability policies.

Expand All @@ -99,8 +101,8 @@ def ls(ctx, opts, owner, page, page_size):
context_msg = "Failed to get package vulnerability policies!"
with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg):
with maybe_spinner(opts):
policies, page_info = api.list_vulnerability_policies(
owner=owner, page=page, page_size=page_size
policies, page_info = paginate_results(
api.list_vulnerability_policies, show_all, page, page_size, owner=owner
)

click.secho("OK", fg="green", err=use_stderr)
Expand All @@ -110,6 +112,17 @@ def ls(ctx, opts, owner, page, page_size):

print_vulnerability_policies(policies)

click.echo()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the newline break JSON parsing if you use JSON output?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unresolved this one.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ Still need an answer here


num_results = len(policies)
list_suffix = "vulnerability polic%s" % ("y" if num_results == 1 else "ies")
utils.pretty_print_list_info(
num_results=num_results,
page_info=None if show_all else page_info,
suffix=list_suffix,
show_all=show_all,
)


@vulnerability.command(aliases=["new"])
@decorators.common_cli_config_options
Expand Down
44 changes: 32 additions & 12 deletions cloudsmith_cli/cli/commands/repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
from ...core.api import repos as api
from .. import command, decorators, utils, validators
from ..exceptions import handle_api_exceptions
from ..utils import maybe_spinner
from ..utils import maybe_spinner, paginate_results
from .main import main


def print_repositories(opts, data, page_info=None, show_list_info=True):
def print_repositories(opts, data, page_info=None, show_list_info=True, show_all=False):
"""Print repositories as a table or output in another format."""
headers = [
"Name",
Expand Down Expand Up @@ -46,13 +46,23 @@ def print_repositories(opts, data, page_info=None, show_list_info=True):
click.echo()
utils.pretty_print_table(headers, rows)

if not show_list_info:
return

click.echo()

num_results = len(data)
list_suffix = "repositor%s visible" % ("ies" if num_results != 1 else "y")
utils.pretty_print_list_info(
num_results=num_results, page_info=page_info, suffix=list_suffix
)
list_suffix = "repositor%s" % ("ies" if num_results != 1 else "y")
if show_all:
utils.pretty_print_list_info(
num_results=num_results, suffix=f"{list_suffix} retrieved", show_all=True
)
else:
utils.pretty_print_list_info(
num_results=num_results,
page_info=page_info,
suffix=f"{list_suffix} visible",
)


@main.group(cls=command.AliasGroup, name="repositories", aliases=["repos"])
Expand Down Expand Up @@ -83,7 +93,7 @@ def repositories(ctx, opts): # pylink: disable=unused-argument
required=False,
)
@click.pass_context
def get(ctx, opts, owner_repo, page, page_size):
def get(ctx, opts, owner_repo, page, page_size, show_all):
"""
List repositories for a namespace (owner).

Expand Down Expand Up @@ -118,8 +128,8 @@ def get(ctx, opts, owner_repo, page, page_size):
context_msg = "Failed to get list of repositories!"
with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg):
with maybe_spinner(opts):
repos_, page_info = api.list_repos(
owner=owner, repo=repo, page=page, page_size=page_size
repos_, page_info = paginate_results(
api.list_repos, show_all, page, page_size, owner=owner, repo=repo
)

click.secho("OK", fg="green", err=use_stderr)
Expand All @@ -128,7 +138,11 @@ def get(ctx, opts, owner_repo, page, page_size):
return

print_repositories(
opts=opts, data=repos_, show_list_info=False, page_info=page_info
opts=opts,
data=repos_,
show_list_info=True,
page_info=page_info,
show_all=show_all,
)


Expand Down Expand Up @@ -192,7 +206,10 @@ def create(ctx, opts, owner, repo_config_file):

click.secho("OK", fg="green", err=use_stderr)

print_repositories(opts=opts, data=[repository], show_list_info=False)
if utils.maybe_print_as_json(opts, [repository]):
return

print_repositories(opts=opts, data=[repository], show_list_info=True)


@repositories.command()
Expand Down Expand Up @@ -252,7 +269,10 @@ def update(ctx, opts, owner_repo, repo_config_file):

click.secho("OK", fg="green", err=use_stderr)

print_repositories(opts=opts, data=[repository], show_list_info=False)
if utils.maybe_print_as_json(opts, [repository]):
return

print_repositories(opts=opts, data=[repository], show_list_info=True)


@repositories.command(aliases=["rm"])
Expand Down
Loading