Skip to content

fix: make login() username and password optional - #257

Open
Shubham-Padkonde wants to merge 1 commit into
oras-project:mainfrom
Shubham-Padkonde:fix/login-optional-credentials
Open

Shubham-Padkonde wants to merge 1 commit into
oras-project:mainfrom
Shubham-Padkonde:fix/login-optional-credentials

Conversation

@Shubham-Padkonde

Copy link
Copy Markdown
Contributor

Registry.login() prompts for the username and password when they are not given, but both were required positional parameters, so calling client.login() raised "TypeError: missing 2 required positional arguments" and the prompts were unreachable without passing None explicitly.

Closes #235

Registry.login() prompts for the username and password when they are
not given, but both were required positional parameters, so calling
client.login() raised "TypeError: missing 2 required positional
arguments" and the prompts were unreachable without passing None
explicitly.

Closes oras-project#235

Signed-off-by: Shubham Padkonde <shubhampadkonde12@gmail.com>

@vsoch vsoch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's work on this one next.

This is not in the lines that you changed, but I realize that this will show the password in the terminal:

password = input("Password: ")

Could we please use getpass.getpass("Password: ").

Can you please test password_stdin=True without a username? E.g.,

client.login(password_stdin=True, hostname="x")

Can you test providing the password but not the username? I want to make sure it does not return login not successful, which is misleading.

Finally, let's put all these changes under this same version update, so we can do one at a time and rebase accordingly.

Comment thread oras/provider.py
:type username: str
:param password: the user account password
:param password: the user account password, prompted for if not provided
:type password: str

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like the types here need to be updated. I also see that there is "insecure" which is not supported here anymore I don't think?

answers = iter(["alice", "secret"])
monkeypatch.setattr("builtins.input", lambda prompt="": next(answers))
set_basic_auth = Mock()
monkeypatch.setattr(client.auth, "set_basic_auth", set_basic_auth)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your docker client stub ignores its arguments, so the test won't catch the prompted credentials not reaching client.login(...).

@vsoch

vsoch commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

@Shubham-Padkonde you've opened a lot of PRs, and we need to do one by one. This is the one we can work on next. Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

oras.provider.Registry.login doesn't prompt for username and password

2 participants