Skip to content

Conversation

@abrightwell
Copy link
Member

@abrightwell abrightwell commented Mar 23, 2022

This PR adds the cb role command to allow for managing cluster roles. As well, it updates the cb uri command to allow for a role name to be provided via the --role flag.

> ./bin/cb role --help
Usage: cb role <create|update|destroy>
    -h, --help                       Show this help
    create                           Create new role for a cluster
    update                           Update a cluster role
    destroy                          Destroy a cluster role

> ./bin/cb role create --help
Usage: cb role create <--cluster>
    -h, --help                       Show this help
    --cluster ID                     Choose cluster

> ./bin/cb role update --help
Usage: cb role update <--cluster> <--name> [--mode] [--rotate-password]
    -h, --help                       Show this help
    --cluster ID                     Choose cluster
    --name NAME                      Role name
    --read-only <true|false>         Read-only
    --rotate-password <true|false>   Rotate password
    
> ./bin/cb role destroy --help
Usage: cb role destroy <--cluster> <--name>
    -h, --help                       Show this help
    --cluster ID                     Choose cluster
    --name NAME                      Role name
> ./bin/cb uri --help
Usage: cb uri <cluster id> [--role]
    -h, --help                       Show this help
    --role NAME                      Role name (default: default)

Removes unused function from `scope.cr`.
Previously we refactored the use of `print_team_slash_cluster` to be a
method defined on `Action`. When refactoring uses of this method, we
missed one the `psql` action. These changes simply clean this up and
brings the action in line with the rest of the source.
Adds some convenience methods to the Client::Error class for `403
Forbidden` and `400 Bad Request`.
Adds cluster role methods to `CB::Client`. As well, updates calls to get
the default role to use new method that allows specifying the name of
the cluster role to retrieve. The URI on the `role` record was updated
to be nilable, as it is possible for the API to return a null value for
URI when a role is deleted.
@abrightwell abrightwell force-pushed the abrightwell/cluster-roles branch 3 times, most recently from bc82913 to c9bd3a6 Compare March 23, 2022 16:44
Comment on lines +49 to +52
c.p_get_role = -> : CB::Client::Role {
raise CB::Client::Error.new("", "",
HTTP::Client::Response.new(HTTP::Status::BAD_REQUEST))
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm sure this could be 'simpler' too...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah we could take a look at patterns in our usage of them in the test and make more helper methods. Idk if we have enough now to figure out what'd be useful, or if it'd make sense to wait for a few more to accumulate

Comment on lines +69 to +71
# Nilable boolean setter. This is useful for fields where nil can have a
# meaningful value beyond being falesy.
macro bool_setter?(property)
Copy link
Member Author

@abrightwell abrightwell Mar 23, 2022

Choose a reason for hiding this comment

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

I needed this so that we could definitively know when a particular flag was set and not simply omitted. For example, --read-only on cb role update. If we just defaulted to false then it would update the role every time, possibly setting the 'mode' or 'flavor' of the role to be be write when it wasn't intended. 😬

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we define one of these in terms of the other?, or have one that takes an option. But it's fiddly stuff and I can take a look after it's merged.

@abrightwell abrightwell requested review from brandur and will March 23, 2022 16:51
@abrightwell abrightwell force-pushed the abrightwell/cluster-roles branch from c9bd3a6 to 91ad8a8 Compare March 23, 2022 17:08
end

# https://crunchybridgeapi.docs.apiary.io/#reference/0/clustersclusteridrolesrolename/update-role
def update_role(cluster_id, role_name, ur)
Copy link
Contributor

Choose a reason for hiding this comment

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

OOC, what's "ur"? Might be better to call this a body or request body if that's what it is.

Copy link
Member Author

Choose a reason for hiding this comment

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

heh... yeah... ur -> updated role... I was just following other similar methods for consistency. But yeah, I definitely agree it could be more clear on what it is.

Copy link
Contributor

@brandur brandur left a comment

Choose a reason for hiding this comment

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

Seems good from my perspective!

One question. These usage docs that are generated:

> ./bin/cb uri --help
Usage: cb uri <cluster id> [--role]
    -h, --help                       Show this help
    --role NAME                      Role name (default: default)

Would it be possible to eventually have some sort of docstring on there describing what the command does? Some are reasonably obvious, but IMO some like this aren't — "uri" is a pretty generic term, and I'd have to guess that what "cb uri" does is give you a Postgres connection string.

@abrightwell
Copy link
Member Author

Seems good from my perspective!

One question. These usage docs that are generated:

> ./bin/cb uri --help
Usage: cb uri <cluster id> [--role]
    -h, --help                       Show this help
    --role NAME                      Role name (default: default)

Would it be possible to eventually have some sort of docstring on there describing what the command does? Some are reasonably obvious, but IMO some like this aren't — "uri" is a pretty generic term, and I'd have to guess that what "cb uri" does is give you a Postgres connection string.

Yeah, I think there can/should be some improvements around this. I was also looking into the potential behind having some man pages we could generate for it as well to bring more details to all of it as well.

Also, another improvement I want to make is around the flag descriptions themselves. Would be great to have more detail there in some way.

Copy link
Collaborator

@will will left a comment

Choose a reason for hiding this comment

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

Just the one small thing I think. I can take care of it tomorrow if you don’t get to it first.

Comment on lines +69 to +71
# Nilable boolean setter. This is useful for fields where nil can have a
# meaningful value beyond being falesy.
macro bool_setter?(property)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we define one of these in terms of the other?, or have one that takes an option. But it's fiddly stuff and I can take a look after it's merged.

Adds support to `create`, `update` and `destroy` a cluster role. Also,
the `cb uri` command is updated to allow for specifying the name of the
role to retrieve.
@abrightwell abrightwell force-pushed the abrightwell/cluster-roles branch from 91ad8a8 to 70a38ee Compare March 30, 2022 12:49
@abrightwell abrightwell merged commit 5863205 into main Mar 30, 2022
@abrightwell abrightwell deleted the abrightwell/cluster-roles branch March 30, 2022 13:06
will added a commit that referenced this pull request Oct 31, 2025
```
<<< /nix/store/6sk9jhxaqa01jm0wp0b4x9labcyi5a3c-cb-3.6.7.drv
>>> /nix/store/jwxavs1iq4zp0bshivkz508js1s8f6g2-cb-3.6.7.drv
Version changes:
[C.]  #1  binutils-with-gold               2.44.tar.bz2 x2 -> 2.44.tar.bz2
[C.]  #2  builder.pl                       <none> x3 -> <none> x2
[C.]  #3  cctools-binutils-darwin-wrapper  1010.6 x7 -> 1010.6 x5
[C.]  #4  clang                            20.1.8, 21.1.2 x2 -> 21.1.2 x2
[C.]  #5  clang-at-least                   16-LLVMgold-path.patch x4 -> 16-LLVMgold-path.patch x3
[C.]  #6  clang-src                        20.1.8, 21.1.2 x2 -> 21.1.2 x2
[C.]  #7  clang-wrapper                    20.1.8 x3, 21.1.2 x3 -> 21.1.2 x3
[C.]  #8  compiler-rt                      20.1.8, 21.1.2 -> 21.1.2
[C.]  #9  compiler-rt-libc                 20.1.8, 21.1.2 -> 21.1.2
[C.]  #10  compiler-rt-src                  20.1.8, 21.1.2 -> 21.1.2
[C.]  #11  cpio                             2.15 x3, 2.15.tar.bz2 x2 -> 2.15 x2, 2.15.tar.bz2
[C*]  #12  crystal                          1.10.1-1-darwin-universal.tar.gz, 1.16.3 -> 1.10.1-1-darwin-universal.tar.gz, 1.18.2
[C.]  #13  expand-response-params           <none> x5 -> <none> x4
[C.]  #14  gnu-install-dirs.patch           <none> x4 -> <none> x3
[C.]  #15  jq                               1.8.1 x2, 1.8.1.tar.gz x2 -> 1.8.1, 1.8.1.tar.gz
[C.]  #16  libbfd-plugin-api-header         <none> x3 -> <none> x2
[C.]  #17  libcxx                           19.1.2+apple-sdk-15.5 x5 -> 19.1.2+apple-sdk-15.5 x4
[C.]  #18  llvm                             18-compatibility.patch, 20.1.8, 21.1.2 x2 -> 18-compatibility.patch, 21.1.2 x2
[C.]  #19  llvm-src                         20.1.8, 21.1.2 x2 -> 21.1.2 x2
[C.]  #20  llvm-tblgen                      20.1.8, 21.1.2 x2 -> 21.1.2 x2
[C.]  #21  llvm-tblgen-src                  20.1.8, 21.1.2 x2 -> 21.1.2 x2
[C.]  #22  macOS-SDK                        11.3 x2, 14.4, 15.5 x3 -> 11.3 x2, 14.4, 15.5 x2
[C.]  #23  make-binary-wrapper-hook         <none> x4 -> <none> x3
[C.]  #24  onig                             6.9.10.tar.gz x2 -> 6.9.10.tar.gz
[C.]  #25  oniguruma                        6.9.10 x2 -> 6.9.10
[C.]  #26  pbzx                             1.0.2 x3 -> 1.0.2 x2
[C.]  #27  psutil                           7.1.0.tar.gz x2 -> 7.1.0.tar.gz
[C.]  #28  python3                          3.13.8 x2, 3.13.8-env x2 -> 3.13.8 x2, 3.13.8-env
[C.]  #29  python3.13-psutil                7.1.0 x2 -> 7.1.0
[C*]  #30  source                           <none> x85 -> <none> x83
[C*]  #31  stdenv-darwin                    <none> x5 -> <none> x3
Removed packages:
[R.]  #1  bd49bbaaafc98433a2cb4e95ce25b7a201baf5a5.patch  <none>
Closure size: 1239 -> 1201 (806 paths added, 844 paths removed, delta -38, disk usage -161.7KiB).
```
will added a commit that referenced this pull request Oct 31, 2025
* Allow temp location to change if necessary

To keep the specs completely isolated, we don't want to reuse the same
global tempdir.

* update crystal 1.16 -> 1.18


```
<<< /nix/store/6sk9jhxaqa01jm0wp0b4x9labcyi5a3c-cb-3.6.7.drv
>>> /nix/store/jwxavs1iq4zp0bshivkz508js1s8f6g2-cb-3.6.7.drv
Version changes:
[C.]  #1  binutils-with-gold               2.44.tar.bz2 x2 -> 2.44.tar.bz2
[C.]  #2  builder.pl                       <none> x3 -> <none> x2
[C.]  #3  cctools-binutils-darwin-wrapper  1010.6 x7 -> 1010.6 x5
[C.]  #4  clang                            20.1.8, 21.1.2 x2 -> 21.1.2 x2
[C.]  #5  clang-at-least                   16-LLVMgold-path.patch x4 -> 16-LLVMgold-path.patch x3
[C.]  #6  clang-src                        20.1.8, 21.1.2 x2 -> 21.1.2 x2
[C.]  #7  clang-wrapper                    20.1.8 x3, 21.1.2 x3 -> 21.1.2 x3
[C.]  #8  compiler-rt                      20.1.8, 21.1.2 -> 21.1.2
[C.]  #9  compiler-rt-libc                 20.1.8, 21.1.2 -> 21.1.2
[C.]  #10  compiler-rt-src                  20.1.8, 21.1.2 -> 21.1.2
[C.]  #11  cpio                             2.15 x3, 2.15.tar.bz2 x2 -> 2.15 x2, 2.15.tar.bz2
[C*]  #12  crystal                          1.10.1-1-darwin-universal.tar.gz, 1.16.3 -> 1.10.1-1-darwin-universal.tar.gz, 1.18.2
[C.]  #13  expand-response-params           <none> x5 -> <none> x4
[C.]  #14  gnu-install-dirs.patch           <none> x4 -> <none> x3
[C.]  #15  jq                               1.8.1 x2, 1.8.1.tar.gz x2 -> 1.8.1, 1.8.1.tar.gz
[C.]  #16  libbfd-plugin-api-header         <none> x3 -> <none> x2
[C.]  #17  libcxx                           19.1.2+apple-sdk-15.5 x5 -> 19.1.2+apple-sdk-15.5 x4
[C.]  #18  llvm                             18-compatibility.patch, 20.1.8, 21.1.2 x2 -> 18-compatibility.patch, 21.1.2 x2
[C.]  #19  llvm-src                         20.1.8, 21.1.2 x2 -> 21.1.2 x2
[C.]  #20  llvm-tblgen                      20.1.8, 21.1.2 x2 -> 21.1.2 x2
[C.]  #21  llvm-tblgen-src                  20.1.8, 21.1.2 x2 -> 21.1.2 x2
[C.]  #22  macOS-SDK                        11.3 x2, 14.4, 15.5 x3 -> 11.3 x2, 14.4, 15.5 x2
[C.]  #23  make-binary-wrapper-hook         <none> x4 -> <none> x3
[C.]  #24  onig                             6.9.10.tar.gz x2 -> 6.9.10.tar.gz
[C.]  #25  oniguruma                        6.9.10 x2 -> 6.9.10
[C.]  #26  pbzx                             1.0.2 x3 -> 1.0.2 x2
[C.]  #27  psutil                           7.1.0.tar.gz x2 -> 7.1.0.tar.gz
[C.]  #28  python3                          3.13.8 x2, 3.13.8-env x2 -> 3.13.8 x2, 3.13.8-env
[C.]  #29  python3.13-psutil                7.1.0 x2 -> 7.1.0
[C*]  #30  source                           <none> x85 -> <none> x83
[C*]  #31  stdenv-darwin                    <none> x5 -> <none> x3
Removed packages:
[R.]  #1  bd49bbaaafc98433a2cb4e95ce25b7a201baf5a5.patch  <none>
Closure size: 1239 -> 1201 (806 paths added, 844 paths removed, delta -38, disk usage -161.7KiB).
```

---------

Co-authored-by: Will Leinweber <will@bitfission.com>
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.

4 participants