Skip to content

Commit 3fccec8

Browse files
omerdemirokactions-user
authored andcommitted
Eng 1563 create cursor instructions for gcp manual adapters (#2794)
## PR Description # Create Comprehensive Documentation and Cursor Rules for GCP Adapter Development ## Overview This PR establishes comprehensive documentation and development guidelines for both manual and dynamic GCP adapter development, including detailed cursor rules for AI-assisted development workflows. ## Changes Made ### 📚 Enhanced Generic Source Adapter Documentation (`sources/README.md`) - **Fixed outdated file paths** and updated code examples to reflect current codebase structure - **Expanded Terraform Mappings section** with guidance on when to use GET vs SEARCH methods - **Enhanced Get Lookups documentation** with examples for single key, multiple keys, and composite lookups - **Improved Search Lookups section** using real examples from existing adapters - **Updated Testing patterns** to reflect actual GCP manual adapter test structures - **Simplified verbose explanations** while maintaining comprehensive coverage - **Added real-world examples** from `compute-instance.go`, `big-query-table.go`, and other adapters ### 🎯 GCP Manual Adapter Documentation (`sources/gcp/manual/README.md`) - **Created comprehensive README** for human authors developing GCP manual adapters - **Documented when to use manual vs dynamic adapters** with clear preference for dynamic - **Provided real examples** from codebase (BigQuery, Logging Sink) for non-standard cases - **Included comprehensive PR review checklist** covering unit tests, Terraform mappings, naming conventions, and linked item queries - **Referenced cursor rules** for detailed implementation guidance - **Updated naming conventions** to follow `{api}-{resource}.go` pattern (e.g., `compute-subnetwork.go`) ### 🤖 GCP Manual Adapter Cursor Rules (`sources/gcp/manual/.cursor/rules/gcp-manual-adapter-creation.mdc`) - **Created detailed cursor rules** with 20 comprehensive sections covering all aspects of manual adapter development - **Included real code examples** from existing adapters for every pattern and concept - **Documented wrapper type selection** (Wrapper, ListableWrapper, SearchableWrapper, SearchableListableWrapper) - **Covered base struct selection** (ProjectBase, RegionBase, ZoneBase) with scoping examples - **Detailed implementation patterns** for Get, List, Search, and ListStream methods - **Comprehensive testing guidance** with proper test run names and helper functions - **Code review checklist** with specific validation points for PR reviews - **Error handling patterns** and iterator usage examples ### 🚀 GCP Dynamic Adapter Framework Documentation (`sources/gcp/dynamic/README.md`) - **Created comprehensive README** explaining the dynamic adapter framework concept - **Documented benefits over SDK-based approach** including automatic link detection and centralized logic - **Explained resource requirements** with BigQuery as example of non-standard cases requiring manual adapters - **Detailed linker functionality** and how it standardizes linking across the entire source - **Provided high-level flow** from GET request to SDP adapter creation (referencing cursor rules for details) - **Documented AI tools integration** with Linear and Cursor for streamlined development - **Emphasized code quality** and thorough inspection of AI-generated code - **Comprehensive post-implementation checklist** including IAM permissions and API enablement - **Explained four adapter types** and automatic type determination ### 🔧 Minor Updates (`sources/gcp/README.md`) - **Updated references** to point to new comprehensive documentation ## Key Benefits ### For Manual Adapter Development - **Clear guidance** on when manual adapters are necessary vs when to use dynamic framework - **Comprehensive patterns** with real examples from existing codebase - **Standardized review process** with detailed checklist for PR validation - **Consistent naming conventions** following GCP API structure ### For Dynamic Adapter Development - **Complete framework understanding** from concept to implementation - **AI-assisted workflow** with emphasis on quality control and code review - **Automated tooling integration** with Linear and Cursor for ticket generation - **Post-implementation guidance** for documentation and infrastructure updates ### For Code Review - **Standardized checklists** ensure consistent quality across all adapter PRs - **Real examples** provide concrete reference points for validation - **Clear patterns** reduce review time and improve accuracy ## Files Changed - `sources/README.md` - Enhanced generic adapter documentation (+583 lines) - `sources/gcp/README.md` - Updated references (+4 lines) - `sources/gcp/dynamic/README.md` - New comprehensive framework documentation (+171 lines) - `sources/gcp/manual/.cursor/rules/gcp-manual-adapter-creation.mdc` - New detailed cursor rules (+719 lines) - `sources/gcp/manual/README.md` - New human author guide (+179 lines) ## Testing - All documentation follows existing patterns from the codebase - Examples are extracted from real, working adapters - Cursor rules include comprehensive validation checklists - Documentation is cross-referenced and consistent ## Impact This PR establishes a solid foundation for scalable GCP adapter development by providing: - Clear guidance for choosing between manual and dynamic approaches - Comprehensive development patterns and examples - Standardized review processes - AI-assisted development workflows with quality controls - Complete documentation ecosystem for both new and experienced developers The documentation serves as the definitive guide for GCP adapter development, ensuring consistency, quality, and maintainability across the entire adapter ecosystem. GitOrigin-RevId: 5c8d41ed40c8954013277d08ae4f0e77e0be4400
1 parent 8614ed8 commit 3fccec8

File tree

4 files changed

+1049
-2
lines changed

4 files changed

+1049
-2
lines changed

sources/gcp/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Further Information for GCG Adapter Creation
1+
# Further Information for GCP Adapter Creation
22

33
Please refer to the [generic adapter creation documentation](../README.md) to learn about the generic adapter framework.
44

@@ -71,7 +71,7 @@ When defining a relation between two adapters, we need to answer the following q
7171
In the following example, we define a relation between the `ComputeInstance` and `ComputeSubnetwork` adapters.
7272
- We identify the `ComputeSubnetwork` adapter as the related item.
7373
- We use the `sdp.QueryMethod_GET` method to get the related item. Because the attribute `subnetwork_name` can be used to get the `ComputeSubnetwork` resource. If it was an attribute that can be used for searching, we would use the `sdp.QueryMethod_SEARCH` method. By the time we are developing the adapter, the linked adapter may not be present. In that case, we have to research the linked adapter and make the correct judgement.
74-
- We use the `subnetworkName` as the query string to pass to the `GET` method. Because its [SDK documentation](https://cloud.google.com/compute/docs/reference/rest/v1/subnetworks/get) states that we need to pass its `name` to get the resource.
74+
- We use the `subnetworkName` as the query string to pass to the `GET` method. Because its [SDK documentation](https://cloud.google.com/compute/docs/reference/rest/v1/subnetworks/get) states that we need to pass its `name` to get the resource.
7575
- We define the scope as `region` via the `gcpshared.RegionalScope(c.ProjectID(), region)` helper function. Because the `ComputeSubnetwork` resource is a regional resource. It requires the `project_id` and `region` along with its `name` to get the resource.
7676
- We define the relation as `BlastPropagation` with `In: true` and `Out: false`. Because the adapter we define is the `ComputeInstance` adapter, we want to propagate the blast radius from the `ComputeInstance` to the `ComputeSubnetwork`. This means that if the `ComputeSubnetwork` is deleted, the `ComputeInstance` will be affected by that (`in:true`). But if the `ComputeInstance` is deleted, the `ComputeSubnetwork` will not be affected (`out:false`). The relation might not be that clear all the time. In this case we should err on to `true` side.
7777
```go

sources/gcp/dynamic/README.md

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# GCP Dynamic Adapter Framework
2+
3+
The GCP Dynamic Adapter Framework is a powerful system for automatically generating GCP resource adapters by making simple HTTP requests to GCP APIs instead of using versioned SDKs. This framework eliminates the need to manually implement GET/SEARCH/LIST methods and handles all the complex wiring, validation, and error handling automatically.
4+
5+
## What is a Dynamic Adapter?
6+
7+
Instead of using versioned SDKs for GCP, we make simple HTTP requests and generate resource adapters dynamically. The framework provides several key advantages:
8+
9+
- **No Manual Method Implementation**: Instead of creating GET/SEARCH/LIST methods manually, we define only the endpoints in the adapter type definition
10+
- **Automatic Link Detection**: We identify the linked items, but the framework handles all the wiring depending on the adapter metadata
11+
- **Centralized Framework Logic**: All adapter metadata, query validations, error handling, iterations, and caching are handled by the framework
12+
- **AI-Assisted Development**: With Cursor instructions, all we need to do is provide links for the resource type definition and GET endpoint. Cursor does a good job generating the code, but the output should be thoroughly inspected. The author should not allow good-looking verbose unnecessary code since every line of code is a liability. Focus on concise, essential implementations and comprehensive test coverage
13+
14+
## Why Dynamic?
15+
16+
We don't use fixed SDKs. We always use the dynamic API response. With comprehensive logging in place, we can identify potential links even after creating adapters, which was not possible before. We do this by checking the structure of an attribute - if it looks like a resource name but we don't have a link for it, then we log it as a potential adapter.
17+
18+
This approach provides several benefits:
19+
20+
- **Future-Proof**: No dependency on SDK versions that may change
21+
- **Consistent**: All adapters follow the same patterns and behaviors
22+
- **Discoverable**: Automatic detection of new potential links from API responses
23+
- **Maintainable**: Centralized logic means updates apply to all adapters
24+
25+
## Resource Requirements
26+
27+
For a resource to be compatible with the dynamic adapter framework, it should follow standard naming conventions and API response types. See BigQuery as an example of a non-standard adapter that required a manual implementation due to its unique API response format and naming conventions.
28+
29+
**Standard Requirements:**
30+
- Consistent resource naming in API responses
31+
- Standard REST API patterns (GET, LIST endpoints)
32+
- Predictable response structures
33+
- Standard GCP resource URL patterns
34+
35+
**Non-Standard Examples (Require Manual Adapters):**
36+
- BigQuery resources with composite IDs (`projectID:datasetID.tableID`)
37+
- Resources with attributes referencing multiple resource types
38+
- APIs with non-standard response formats
39+
40+
## Linker: How It Works
41+
42+
The linker is a critical component that finds the adapter metadata for linked items and creates linked item queries by their definition. This standardizes how a certain adapter is linked across the entire source and prevents code duplication.
43+
44+
**Key Benefits:**
45+
- **Standardization**: Ensures consistent linking patterns across all adapters
46+
- **Centralized Updates**: If a linked item adapter changes, the update applies to all existing adapters automatically
47+
- **No Find/Replace**: Eliminates the need to manually update multiple files when linked item logic changes
48+
- **Manual Adapter Compatibility**: It's possible to link manual adapters to dynamic adapters seamlessly
49+
50+
## Flow: GET Request to SDP Adapter
51+
52+
The complete flow from making a GET request to creating an SDP adapter follows these steps:
53+
54+
1. **Adapter Definition**: Define the adapter metadata in the adapter file (see [dynamic-adapter-creation.mdc](adapters/.cursor/rules/dynamic-adapter-creation.mdc))
55+
2. **Adapter Creation**: Framework creates the appropriate adapter type based on metadata configuration
56+
3. **GET Request Processing**: Validate scope, check cache, construct URL, make HTTP request, convert to SDP item
57+
4. **External Response to SDP Conversion**: Extract attributes, apply blast propagation rules, generate linked item queries
58+
5. **Unit Test Coverage**: Test GET functionality and static tests for blast propagation
59+
60+
For detailed implementation patterns and code examples, refer to the [dynamic adapter creation rules](adapters/.cursor/rules/dynamic-adapter-creation.mdc).
61+
62+
## AI Tools Available
63+
64+
We have helper scripts that benefit from Linear and Cursor integration to streamline adapter development:
65+
66+
### Generate Adapter Ticket
67+
```bash
68+
# Generate implementation ticket for new adapter
69+
go run ai-tools/generate-adapter-ticket-cmd/main.go -name compute-subnetwork -api-ref "https://cloud.google.com/compute/docs/reference/rest/v1/subnetworks/get"
70+
```
71+
72+
### Generate Test Ticket
73+
```bash
74+
# Generate test ticket for existing adapter
75+
go run ai-tools/generate-test-ticket-cmd/main.go compute-global-address
76+
```
77+
78+
**Benefits:**
79+
- **Automated Ticket Creation**: Generates Linear tickets with proper context and requirements
80+
- **Cursor Integration**: Works seamlessly with Cursor rules for consistent implementation
81+
- **Comprehensive Context**: Includes API references, implementation checklists, and testing requirements
82+
83+
For detailed usage instructions, see the [AI Tools README](ai-tools/README.md).
84+
85+
## Cursor Integration
86+
87+
It is highly recommended to use Cursor for creating adapters. There are comprehensive rules available that guide the implementation process. After creating an adapter, the author MUST perform the following checks:
88+
89+
### Adapter Validation
90+
91+
1. **Terraform Mappings GET/Search**: Check from Terraform registry that the mappings are correct
92+
2. **Blast Propagations**: Verify they are comprehensive and attribute values follow standards
93+
3. **Item Selector**: If the item identifier in the API response is something other than `name`, define it properly
94+
4. **Unique Attribute Keys**: Investigate the GET endpoint format and ensure it's correct
95+
96+
### Test Completeness
97+
98+
1. **Blast Propagation/Linked Item Queries**: Verify they work as expected
99+
2. **Unique Attribute**: Ensure it matches the GET call response
100+
3. **Terraform Mapping for Search**: Confirm it exists if search is supported
101+
102+
## Post-Implementation Steps
103+
104+
After adding a new adapter, follow the comprehensive post-implementation checklist in the [main adapter documentation](../README.md#post-implementation-steps). This includes updating documentation, IAM permissions, and enabling required APIs.
105+
106+
## Adapter Types
107+
108+
The framework supports four types of adapters based on their capabilities:
109+
110+
- **Standard**: GET only
111+
- **Listable**: GET + LIST
112+
- **Searchable**: GET + SEARCH
113+
- **SearchableListable**: GET + LIST + SEARCH
114+
115+
The adapter type is automatically determined based on the metadata configuration:
116+
117+
```go
118+
func adapterType(meta gcpshared.AdapterMeta) typeOfAdapter {
119+
if meta.ListEndpointFunc != nil && meta.SearchEndpointFunc == nil {
120+
return Listable
121+
}
122+
if meta.SearchEndpointFunc != nil && meta.ListEndpointFunc == nil {
123+
return Searchable
124+
}
125+
if meta.ListEndpointFunc != nil && meta.SearchEndpointFunc != nil {
126+
return SearchableListable
127+
}
128+
return Standard
129+
}
130+
```
131+
132+
## Benefits of Dynamic Adapters
133+
134+
1. **Consistency**: All adapters follow the same patterns and behaviors
135+
2. **Efficiency**: Reduces boilerplate code and speeds up development
136+
3. **Maintainability**: Centralized logic makes updates and bug fixes easier
137+
4. **Scalability**: Simplifies the process of adding new resources
138+
5. **Quality**: Automatic validation and error handling ensure reliability
139+
6. **Discoverability**: Automatic detection of potential new links from API responses
140+
141+
## Getting Started
142+
143+
1. **Use AI Tools**: Generate tickets using the helper scripts
144+
2. **Follow Cursor Rules**: Apply the comprehensive rules for consistent implementation
145+
3. **Review Thoroughly**: Check all validation points before considering complete
146+
4. **Update Documentation**: Ensure all related documentation is updated
147+
5. **Test Extensively**: Verify all functionality works as expected
148+
149+
The dynamic adapter framework represents a significant advancement in how we handle GCP resource discovery, providing a robust, scalable, and maintainable solution for infrastructure mapping.

0 commit comments

Comments
 (0)