No description
  • Python 98%
  • HTML 1.5%
  • Shell 0.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Doston Toirov c70965eed6
[AAP-82119] Add bulk-update endpoint for resource registry (#1054)
## Description

- **What:** Add `POST /service-index/resources/bulk-update/` endpoint to
the resource registry that accepts a list of resource updates and
processes them in a single database transaction.
- **Why:** During `migrate_service_data`, each resource item triggers an
individual HTTP PATCH to set its `service_id`. For 3,962 users, this
means 3,962 sequential round-trips taking 203s. The bulk endpoint
eliminates this per-item overhead.
- **How:** A new `@action` on `ResourceViewSet` that validates a list
payload, fetches all resources in a single query, and applies updates
atomically. Also adds `bulk_update_resources()` to `ResourceAPIClient`
for callers.

## Type of Change

- [x] New feature (non-breaking change which adds functionality)

## Self-Review Checklist

- [x] I have performed a self-review of my code
- [x] I have added relevant comments to complex code sections
- [x] I have updated documentation where needed
- [x] I have considered the security impact of these changes
- [x] I have considered performance implications
- [x] I have thought about error handling and edge cases
- [x] I have tested the changes in my local environment

## Testing Instructions

### Prerequisites

- SQLite test environment (or PostgreSQL with docker)

### Steps to Test

1. Run: `DJANGO_SETTINGS_MODULE=test_app.sqlite3settings python -m
pytest test_app/tests/resource_registry/test_bulk_update.py -v`
2. All 11 tests should pass covering: service_id updates, ansible_id
renames, partially_migrated flag, mixed fields, not-found errors,
empty/invalid/oversized payloads, permission checks, and resource_data
updates.

### Expected Results

- `POST /service-index/resources/bulk-update/` accepts a JSON list (max
1000 items)
- Each item requires `ansible_id`, optional: `service_id`,
`new_ansible_id`, `is_partially_migrated`, `resource_data`
- Returns `{"updated": N, "errors": [...]}`
- All operations are atomic (single transaction)
- Permission check: requires `HasResourceRegistryPermissions` (superuser
or resource_api_actions)

## Additional Context

### Required Actions

- [x] Requires downstream repository changes
- aap-gateway: `AAP-82119/batch-resource-migration` branch uses this
endpoint

### Performance Impact

At Kyndryl scale (3,962 users, 2,288 teams, 130 orgs), this endpoint
reduces resource migration HTTP calls from ~6,400 to ~130 (one per API
page instead of one per resource item).

---
**Note:** This PR was developed with assistance from Claude AI
assistant.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added a bulk-update API (`bulk-update`) to update multiple resources
in one request (up to 1,000 items).
* Supports changing service links, identifiers (including
`new_ansible_id`), migration status, and optionally resource content.
* Returns an `updated` count plus per-item errors, allowing partial
success.
* **Bug Fixes**
* Improved REST client behavior to always send valid request bodies,
even when the payload is empty.
* **Validation**
* Rejects malformed payloads, missing/invalid `items`, oversized
batches, items with no update fields, and duplicate identifiers within a
request.
* **Tests**
* Added comprehensive end-to-end coverage for success, partial failure,
authorization, and content rules.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-07-22 14:06:45 -04:00
.githooks AAP-35592: Move git hooks to own folder, add pre-push hook (#674) 2024-12-17 09:01:01 -05:00
.github [AAP-80579] Fix dynaconf 3.3.0 compat, rename in-files CI to canary (#1034) 2026-06-26 14:54:47 -06:00
ansible_base [AAP-82119] Add bulk-update endpoint for resource registry (#1054) 2026-07-22 14:06:45 -04:00
compose [AAP-41963] Fix SonarCloud security hotspots (#707) 2025-04-01 19:11:32 +02:00
docs Revert 1042 1038 (#1046) 2026-07-06 13:16:16 -04:00
requirements [AAP-65921] Add auto-sync cache invalidation to DABRedisCache (#1017) 2026-06-04 12:46:42 -04:00
test_app [AAP-82119] Add bulk-update endpoint for resource registry (#1054) 2026-07-22 14:06:45 -04:00
tools AAP-53946 [devel-only] Forever ensure that ansible_base.lib.* is importable (#844) 2025-10-01 19:13:44 +00:00
.dockerignore AAP-45875 Runtime Feature Flags (#875) 2025-11-24 20:36:39 +00:00
.git_archival.txt AAP-58240: Add git archive support for setuptools-scm (#901) 2025-12-10 15:09:36 +00:00
.gitattributes AAP-58240: Add git archive support for setuptools-scm (#901) 2025-12-10 15:09:36 +00:00
.gitignore Fix the docker-compose serving (#694) 2025-04-01 09:20:18 -04:00
.help_text_check.ignore Adding missing help_text and check 2024-11-26 16:10:05 -05:00
codecov.yml [AAP-74899] Add Codecov integration for coverage tracking (#1016) 2026-06-02 16:42:55 +02:00
docker-compose.yml [AAP-41963] Fix SonarCloud security hotspots (#707) 2025-04-01 19:11:32 +02:00
Dockerfile Make python 3.12 default (#892) 2025-12-11 19:36:46 +00:00
LICENSE Use LICENSE file according to the official guidelines 2024-04-03 22:29:52 +02:00
Makefile Make python 3.12 default (#892) 2025-12-11 19:36:46 +00:00
manage.py Split DAB into multiple applications (#76) 2024-01-19 17:10:35 +00:00
MANIFEST.in AAP-45875 Include feature flags definitions in package manifest 2025-11-26 10:21:51 -05:00
pyproject.toml [AAP-73865] Add observability app (#982) 2026-05-20 11:31:35 -06:00
README.md [AAP-52663] Add SonarCloud badges to README.md (#856) 2025-10-06 16:05:48 -04:00
SECURITY.md Initial commit, not properly building yet 2023-10-25 14:22:32 -04:00
sonar-project.properties Make python 3.12 default (#892) 2025-12-11 19:36:46 +00:00

Quality Gate Status Coverage Vulnerabilities Security Rating Bugs Code Smells Maintainability Rating

django-ansible-base

What is it?

Django-ansible-base is exactly what it says it is. A base for any Ansible application which will leverage Django.

Documentation

Docs for django-ansible-base features can be found in the docs directory.

Information about the test_app and how to start/use it can be found in test_app/README.md