Skip to content

Commit

Permalink
Adding add-app-password, revoke-app-password, and list-app-passwords …
Browse files Browse the repository at this point in the history
…commands
  • Loading branch information
sanko committed Jan 27, 2024
1 parent efe9456 commit e9e0ee2
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 22 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,42 @@ Show notifications.
--json boolean flag; content is printed as JSON objects if given
```

## add-app-password

```
bsky add-app-password "Your app name"
```

Create a new App password.

Note that you must be logged in with the account password to add a new app password.

## revoke-app-password

```
bsky revoke-app-password "Your app name"
```

Delete App password.

Note that you must be logged in with the account password to revoke an app password.

## list-app-passwords

```
bsky list-app-passwords
bsky list-app-passwords --json
```

Show App passwords.

### Options

```
--json boolean flag; content is printed as JSON objects if given
```

## login

```
Expand Down
26 changes: 20 additions & 6 deletions lib/App/bsky.pm
Original file line number Diff line number Diff line change
Expand Up @@ -476,16 +476,30 @@ package App::bsky 0.02 {
...;
}
method cmd_listapppasswords ($handle) {
...;
method cmd_listapppasswords (@args) {
GetOptionsFromArray( \@args, 'json' => \my $json );
my $passwords = $bsky->server_listAppPasswords;
my @passwords = @{ $passwords->{passwords} };
if ($json) {
$self->say( JSON::Tiny::to_json [ map { $_->_raw } @passwords ] );
}
else {
$self->say( '%s (%s)', $_->name, $_->createdAt->_raw ) for @passwords;
}
scalar @passwords;
}
method cmd_addapppassword ($handle) {
...;
method cmd_addapppassword ($name) {
my $res = $bsky->server_createAppPassword($name);
if ( builtin::blessed $res->{appPassword} ) {
$self->say( 'App name: %s', $res->{appPassword}->name );
$self->say( 'Password: %s', $res->{appPassword}->password );
}
1;
}
method cmd_revokeapppassword ($handle) {
...;
method cmd_revokeapppassword ($name) {
$bsky->server_revokeAppPassword($name) ? 1 : 0;
}
method cmd_config ( $field //= (), $value //= () ) {
Expand Down
28 changes: 28 additions & 0 deletions script/bsky
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,34 @@ Show notifications.
--all boolean flag, show all notifications
--json boolean flag; content is printed as JSON objects if given

=head2 add-app-password

bsky add-app-password "Your app name"

Create a new App password.

Note that you must be logged in with the account password to add a new app password.

=head2 revoke-app-password

bsky revoke-app-password "Your app name"

Delete App password.

Note that you must be logged in with the account password to revoke an app password.

=head2 list-app-passwords

bsky list-app-passwords

bsky list-app-passwords --json

Show App passwords.

=head3 Options

--json boolean flag; content is printed as JSON objects if given

=head2 login

bsky login [ident] [password] [--host http://bsky.social]
Expand Down
18 changes: 9 additions & 9 deletions t/00_compile.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ subtest 'commands' => sub {
cmd_timeline cmd_tl
cmd_stream
cmd_thread
cmd_post cmd_delete
cmd_vote cmd_votes
cmd_repost cmd_reposts
cmd_follow cmd_unfollow cmd_follows cmd_followers
cmd_block cmd_unblock cmd_blocks
cmd_post cmd_delete
cmd_vote cmd_votes
cmd_repost cmd_reposts
cmd_follow cmd_unfollow cmd_follows cmd_followers
cmd_block cmd_unblock cmd_blocks
cmd_login
cmd_notifications cmd_notif
cmd_invitecodes cmd_listapppasswords
cmd_addapppassword cmd_revokeapppassword
cmd_notifications cmd_notif
cmd_invitecodes
cmd_listapppasswords cmd_addapppassword cmd_revokeapppassword
cmd_config
cmd_help
cmd_VERSION cmd_version
cmd_VERSION cmd_version
];
};
subtest 'internals' => sub {
Expand Down
20 changes: 13 additions & 7 deletions t/01_client.t
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,19 @@ my $mock = mock 'App::bsky::CLI' => (
my $code = shift;
@err = ();
$code->();
wantarray ? @err : join "\n", @err;
my $msg = join "\n", @say;
note $msg;
wantarray ? @say : $msg if @say;
}

sub is_say(&) {
my $code = shift;
@say = ();
$code->();
return 0 if !$say[0];
wantarray ? @say : join "\n", @say if @say;
my $msg = join "\n", @say;
note $msg;
wantarray ? @say : $msg if @say;
}
}
#
Expand All @@ -82,7 +86,7 @@ is is_say { client->run(qw[config wrap]) }, 0, 'config wrap == 0';
#
subtest 'live' => sub {
my $todo = todo 'Rate limit or another login info error...';
eval {
todo 'using the web... things may go wrong that are not our fault' => sub {
subtest 'login ... ... (error)' => sub {
my $client;
like warning {
Expand Down Expand Up @@ -161,10 +165,12 @@ subtest 'live' => sub {
qr[did:plc:qvzn322kmcvd7xtnips5xaun], 'thread at://...';
like is_say { client->run(qw[thread at://did:plc:qdvyf5jhuxqx667ay7k7nagl/app.bsky.feed.post/3kju327qezs2n --json]) }, qr[^{],
'thread --json at://...';
like is_say { client->run(qw[notifications]) }, qr[did:plc:pwqewimhd3rxc4hg6ztwrcyj], 'notifications';
like is_say { client->run(qw[notifications --json]) }, qr[^{], 'notifications --json';
like is_say { client->run(qw[show-session]) }, qr[did:plc:pwqewimhd3rxc4hg6ztwrcyj], 'show-session';
like is_say { client->run(qw[show-session --json]) }, qr[^{], 'show-session --json';
like is_say { client->run(qw[list-app-passwords]) }, qr[Test Suite - bsky], 'list-app-passwords';
like is_say { client->run(qw[list-app-passwords --json]) }, qr[^\[\{], 'list-app-passwords --json';
like is_say { client->run(qw[notifications]) }, qr[did:plc:pwqewimhd3rxc4hg6ztwrcyj], 'notifications';
like is_say { client->run(qw[notifications --json]) }, qr[^{], 'notifications --json';
like is_say { client->run(qw[show-session]) }, qr[did:plc:pwqewimhd3rxc4hg6ztwrcyj], 'show-session';
like is_say { client->run(qw[show-session --json]) }, qr[^{], 'show-session --json';
}
};
done_testing;
Expand Down

0 comments on commit e9e0ee2

Please sign in to comment.