Skip to content

Commit

Permalink
Fix cb uri hostname for replicas using user role.
Browse files Browse the repository at this point in the history
It was reported that using `cb uri` to retrieve credentials for a `user`
role on a replica was returning the hostname of the `primary` instead of
the target replica.

This was because it's possible that the` user` role does not exist yet
and therefore would need to first be created on the primary. So, to
ensure that it is, we always attempt to create it on the primary and
then retrieve it for the replica. Previously, we were only creating it
and that was resulting in the returned credentials to be associated with
the primary. So, we've now eliminated that branch in the code so that it
will always retrieve this information from the correct target.
  • Loading branch information
abrightwell committed May 9, 2024
1 parent 07817e3 commit 704e6b2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- `cb config-param set` issue truncating values with multiple `=` characters.
- `cb uri` retrieving correct `user` role credentials for a replica.

## [3.5.0] - 2024-01-31
### Added
Expand Down
2 changes: 2 additions & 0 deletions spec/cb/cluster_uri_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Spectator.describe CB::ClusterURI do
action.role = "user"

expect(client).to receive(:create_role).and_return(role)
expect(client).to receive(:get_role).and_return(role)

action.call

Expand All @@ -48,6 +49,7 @@ Spectator.describe CB::ClusterURI do
action.role = "user"

expect(client).to receive(:create_role).and_return(role)
expect(client).to receive(:get_role).and_return(role)

action.call

Expand Down
7 changes: 2 additions & 5 deletions src/cb/cluster_uri.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ class CB::ClusterURI < CB::APIAction
def run
validate

role = if @role == "user"
client.create_role(@cluster_id[:cluster])
else
client.get_role(@cluster_id[:cluster], @role.to_s)
end
client.create_role(@cluster_id[:cluster]) if @role == "user"
role = client.get_role(@cluster_id[:cluster], @role.to_s)

uri = role.uri
raise Error.new "There is no URI available for this cluster." unless uri
Expand Down

0 comments on commit 704e6b2

Please sign in to comment.