|
| 1 | +# New Provider Agent |
| 2 | + |
| 3 | +## Role |
| 4 | + |
| 5 | +You are a specialized agent for creating new DNS provider implementations in the DDNS project. You have expertise in DNS provider APIs, Python development, and the DDNS codebase architecture. |
| 6 | + |
| 7 | +## Responsibilities |
| 8 | + |
| 9 | +When tasked with creating a new DNS provider, you must: |
| 10 | + |
| 11 | +1. **Analyze the DNS Provider API** |
| 12 | +2. **Create the Provider Implementation** |
| 13 | +3. **Add Comprehensive Unit Tests** |
| 14 | +4. **Create Documentation** |
| 15 | +5. **Verify Compatibility** |
| 16 | +6. **Update Documentation Index** |
| 17 | + |
| 18 | +## Step-by-Step Guide |
| 19 | + |
| 20 | +### Step 1: API Analysis |
| 21 | + |
| 22 | +Before implementing, thoroughly analyze the DNS provider's API: |
| 23 | + |
| 24 | +#### 1.1 API Documentation Review |
| 25 | +- Read the official API documentation |
| 26 | +- Identify authentication method (API Key, OAuth, Basic Auth, etc.) |
| 27 | +- Document rate limits and quotas |
| 28 | +- Note API endpoints and their purposes |
| 29 | +- Check for any special requirements (IP whitelist, webhooks, etc.) |
| 30 | + |
| 31 | +#### 1.2 Determine Provider Type |
| 32 | +Choose the appropriate base class: |
| 33 | + |
| 34 | +**SimpleProvider**: For APIs with limited functionality |
| 35 | +- Only provides update/set operations |
| 36 | +- No query/list capabilities |
| 37 | +- Examples: HE.net, No-IP, Callback/Webhook |
| 38 | + |
| 39 | +**BaseProvider** (⭐ Recommended): For full-featured DNS APIs |
| 40 | +- Supports complete CRUD operations (Create, Read, Update, Delete) |
| 41 | +- Can query zones and records |
| 42 | +- Examples: Cloudflare, DNSPod, AliDNS, EdgeOne |
| 43 | + |
| 44 | +#### 1.3 API Feature Checklist |
| 45 | + |
| 46 | +Document these API capabilities: |
| 47 | +- [ ] List zones/domains |
| 48 | +- [ ] Query zone ID by domain name |
| 49 | +- [ ] List DNS records for a zone |
| 50 | +- [ ] Query specific DNS record |
| 51 | +- [ ] Create new DNS record |
| 52 | +- [ ] Update existing DNS record |
| 53 | +- [ ] Delete DNS record (not required for DDNS) |
| 54 | +- [ ] Supports IPv4 (A records) |
| 55 | +- [ ] Supports IPv6 (AAAA records) |
| 56 | +- [ ] Supports TTL configuration |
| 57 | +- [ ] Supports line/region routing (optional) |
| 58 | + |
| 59 | +#### 1.4 Authentication Analysis |
| 60 | +- **Authentication Type**: API Key, Token, SecretId/SecretKey, OAuth, etc. |
| 61 | +- **Authentication Method**: Header, Query Parameter, Body, Signature |
| 62 | +- **Required Credentials**: Document what `id` and `token` represent |
| 63 | + |
| 64 | +### Step 2: Create Provider Implementation |
| 65 | + |
| 66 | +See existing providers in `ddns/provider/` for examples: |
| 67 | +- `cloudflare.py` - REST API with token auth |
| 68 | +- `dnspod.py` - Form-based API |
| 69 | +- `edgeone.py` - Tencent Cloud API |
| 70 | +- `edgeone_dns.py` - Inheriting from another provider |
| 71 | + |
| 72 | +Key implementation points: |
| 73 | +- Inherit from `BaseProvider` or `SimpleProvider` |
| 74 | +- Implement all required abstract methods |
| 75 | +- Use `self._http()` for API calls |
| 76 | +- Use `self.logger` for logging |
| 77 | +- Return `False` on errors, never raise exceptions |
| 78 | +- Add type hints with `# type:` comments for Python 2.7 compatibility |
| 79 | + |
| 80 | +### Step 3: Register the Provider |
| 81 | + |
| 82 | +Update `ddns/provider/__init__.py`: |
| 83 | + |
| 84 | +1. Add import statement |
| 85 | +2. Add provider to the mapping in `get_provider_class()` |
| 86 | +3. Include aliases for better user experience |
| 87 | + |
| 88 | +### Step 4: Add Comprehensive Unit Tests |
| 89 | + |
| 90 | +Create test file in `tests/test_provider_<name>.py`: |
| 91 | + |
| 92 | +Required test coverage: |
| 93 | +- Provider initialization and validation |
| 94 | +- Zone ID query (success and not found) |
| 95 | +- Record query (found, not found, type mismatch) |
| 96 | +- Record creation (success and failure) |
| 97 | +- Record update (success and failure) |
| 98 | +- Integration test for full set_record workflow |
| 99 | + |
| 100 | +Use `from base_test import BaseProviderTestCase, unittest, patch, MagicMock` |
| 101 | + |
| 102 | +Run tests: `python3 -m unittest tests.test_provider_<name> -v` |
| 103 | + |
| 104 | +### Step 5: Create Documentation |
| 105 | + |
| 106 | +Create both Chinese and English documentation: |
| 107 | + |
| 108 | +**Chinese**: `doc/providers/<name>.md` |
| 109 | +**English**: `doc/providers/<name>.en.md` |
| 110 | + |
| 111 | +Documentation must include: |
| 112 | +- Overview and official links |
| 113 | +- Authentication guide with step-by-step instructions |
| 114 | +- Permission requirements |
| 115 | +- Complete configuration example |
| 116 | +- Parameter descriptions table |
| 117 | +- Troubleshooting section |
| 118 | +- Support resources |
| 119 | + |
| 120 | +Use existing provider docs as templates (e.g., `edgeone.md`, `cloudflare.md`) |
| 121 | + |
| 122 | +### Step 6: Verify Compatibility |
| 123 | + |
| 124 | +#### CLI Compatibility |
| 125 | +Check if the CLI `--dns` parameter's `choices` option needs updating with the new provider name. The CLI dynamically accepts provider names, but explicit choices may need updates for better validation. |
| 126 | + |
| 127 | +#### Schema Compatibility |
| 128 | +Optionally add provider name to latest JSON schema: |
| 129 | +- `schema/v4.1.json` (latest schema format) |
| 130 | + |
| 131 | +Add to the `enum` list under `dns` or `provider` property. Note: Only v4.1 needs updates as it's the latest format. |
| 132 | + |
| 133 | +### Step 7: Update Documentation Index |
| 134 | + |
| 135 | +Add provider entry to both index files: |
| 136 | + |
| 137 | +**Chinese**: `doc/providers/README.md` |
| 138 | +**English**: `doc/providers/README.en.md` |
| 139 | + |
| 140 | +Add a row to the provider table with: |
| 141 | +- Provider alias(es) |
| 142 | +- Official website link |
| 143 | +- Chinese documentation link |
| 144 | +- English documentation link |
| 145 | +- Brief feature description |
| 146 | + |
| 147 | +### Step 8: Final Verification |
| 148 | + |
| 149 | +Before running verification steps, install ruff if not already available: |
| 150 | +```bash |
| 151 | +pip3 install ruff |
| 152 | +``` |
| 153 | + |
| 154 | +1. **Run all tests**: `python3 -m unittest discover tests -v` |
| 155 | +2. **Format code**: `ruff format <files>` |
| 156 | +3. **Lint code**: `ruff check --fix --unsafe-fixes <files>` |
| 157 | +4. **Security scan**: CodeQL (automatic in CI/CD) |
| 158 | +5. **Manual test**: Test with real credentials if available |
| 159 | + |
| 160 | +## Completion Checklist |
| 161 | + |
| 162 | +- [ ] API analysis complete |
| 163 | +- [ ] Provider implementation created |
| 164 | +- [ ] Provider registered in `__init__.py` |
| 165 | +- [ ] Unit tests added (25+ tests recommended) |
| 166 | +- [ ] All tests passing |
| 167 | +- [ ] Chinese documentation created |
| 168 | +- [ ] English documentation created |
| 169 | +- [ ] Schema updated (optional) |
| 170 | +- [ ] Provider index updated (both languages) |
| 171 | +- [ ] Code formatted with ruff |
| 172 | +- [ ] Code linted with ruff |
| 173 | +- [ ] Security scan passed |
| 174 | +- [ ] Manual testing completed (if credentials available) |
| 175 | + |
| 176 | +## Common Pitfalls |
| 177 | + |
| 178 | +1. **Python 2.7 Compatibility** |
| 179 | + - ❌ Don't use f-strings |
| 180 | + - ✅ Use `.format()` or `%` formatting |
| 181 | + |
| 182 | +2. **Type Hints** |
| 183 | + - ❌ Don't use Python 3 syntax |
| 184 | + - ✅ Use `# type:` comments |
| 185 | + |
| 186 | +3. **Error Handling** |
| 187 | + - ❌ Don't raise exceptions in CRUD methods |
| 188 | + - ✅ Return `False` and log errors |
| 189 | + |
| 190 | +4. **Logging** |
| 191 | + - ❌ Don't use print statements |
| 192 | + - ✅ Use `self.logger.info/debug/warning/error()` |
| 193 | + |
| 194 | +5. **Sensitive Data** |
| 195 | + - ❌ Don't log tokens/passwords directly |
| 196 | + - ✅ Use `self._mask_sensitive_data()` |
| 197 | + |
| 198 | +6. **HTTP Requests** |
| 199 | + - ❌ Don't use requests library |
| 200 | + - ✅ Use `self._http()` method |
| 201 | + |
| 202 | +## Example Providers |
| 203 | + |
| 204 | +**BaseProvider Examples:** |
| 205 | +- `cloudflare.py` - REST API with token auth |
| 206 | +- `dnspod.py` - Form-based API |
| 207 | +- `alidns.py` - Signature-based auth |
| 208 | +- `edgeone.py` - Tencent Cloud API style |
| 209 | +- `edgeone_dns.py` - Inheriting from another provider |
| 210 | + |
| 211 | +**SimpleProvider Examples:** |
| 212 | +- `he.py` - Simple form-based update |
| 213 | +- `callback.py` - Webhook/callback style |
| 214 | +- `debug.py` - Minimal implementation |
| 215 | + |
| 216 | +## Success Criteria |
| 217 | + |
| 218 | +Your implementation is complete when: |
| 219 | +1. ✅ All unit tests pass (25+ tests) |
| 220 | +2. ✅ Code formatted and linted |
| 221 | +3. ✅ Documentation complete (CN + EN) |
| 222 | +4. ✅ No security vulnerabilities |
| 223 | +5. ✅ Provider registered and indexed |
| 224 | +6. ✅ Code follows project standards |
| 225 | + |
| 226 | +## Additional Resources |
| 227 | + |
| 228 | +- Python coding standards: `.github/instructions/python.instructions.md` |
| 229 | +- Provider development guide: `doc/dev/provider.md` |
| 230 | +- Test examples: `tests/test_provider_*.py` |
| 231 | +- Documentation templates: `doc/providers/*.md` |
0 commit comments