Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Fixed `user apply` failing with `KeyError: 'Name'` by overriding `name_from_body` and `apply` to use `Username` and set the correct `State` for create vs update
- Updated broken links in batch documentation
- Fixed `batch_scheduling_policy update` returning 405 by PUTting to the collection endpoint instead of a named resource path
- Fixed `batch_scheduling_policy` resource decorator name colliding with `batch_job`
- Fixed `rds delete` showing internal AWS path (`aws/rds/instance/<name>`) instead of only the database name
- Fixed `user apply` failing with `KeyError: 'Name'` by overriding `name_from_body` to return `Username` and adding an `update` method; the inherited V2 `apply` now drives the find → update/create flow
- Fixed `apply` failing for resources whose API returns HTTP 400 (not 404) for not-found lookups (e.g. RDS) by promoting 400 responses containing "not found" to `DuploNotFound`
- Fixed `lambda apply` failing with "No lambda functions found" when creating the first lambda in a tenant
- Fixed `service apply` creating instead of updating when V3 find endpoint returns 200 with null body for non-existent services
Expand Down
39 changes: 33 additions & 6 deletions src/duplo_resource/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@ def __init__(self, duplo: DuploCtl):
super().__init__(duplo)
self.tenent_svc = duplo.load('tenant')

def name_from_body(self, body):
return body["Username"]
Comment thread
amaechiabuah marked this conversation as resolved.

Comment thread
qodo-code-review[bot] marked this conversation as resolved.
@Command("ls")
def list(self):
"""Retrieve a list of all users in the Duplo system."""
response = self.client.get("admin/GetAllUserRoles")
return response.json()

@Command("get")
def find(self,
def find(self,
name: args.NAME):
"""Find a User by their username."""
try:
return [u for u in self.list() if u["Username"] == name][0]
except IndexError:
raise DuploNotFound(name, "User")

@Command()
def create(self,
def create(self,
body: args.BODY) -> dict:
"""Create a new user.

Expand All @@ -38,9 +41,9 @@ def create(self,
```yaml
--8<-- "src/tests/data/user.yaml"
```

Args:
body: The user body.
body: The user body.

Returns:
message: A success message.
Expand All @@ -49,6 +52,30 @@ def create(self,
body['State'] = 'added'
response = self.client.post("admin/UpdateUserRole", body)
return response.json()

@Command()
def update(self,
name: args.NAME = None,
body: args.BODY = None) -> dict:
"""Update an existing user.

Usage: CLI Usage
```sh
duploctl user update -f 'user.yaml'
```

Args:
name: The username (unused; kept for signature parity with the
base ``apply`` which calls ``update(name, body)`` positionally).
body: The user body.

Returns:
message: A success message.
"""
if 'State' not in body:
body['State'] = 'updated'
response = self.client.post("admin/UpdateUserRole", body)
return response.json()

@Command()
def delete(self,
Expand Down
Loading