-
Notifications
You must be signed in to change notification settings - Fork 485
CLOUDFLAREAPI: Add support for record comments and tags #4025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
CLOUDFLAREAPI: Add support for record comments and tags #4025
Conversation
Introducing the following Cloudflare-specific modifiers: - CF_MANAGE_COMMENTS - Domain modifier to opt into comment syncing - CF_MANAGE_TAGS - Domain modifier to opt into tag syncing - CF_COMMENT(comment) - Set a comment on a record (works on all plans) - CF_TAGS(tag1, tag2, ...) - Set tags on a record (requires paid plan) Features: - Comments and tags are read from API and displayed in get-zones output - Validation ensures CF_COMMENT/CF_TAGS require management flags enabled - Tags with reserved 'cf-' prefix are rejected - get-zones --format=js/djs auto-adds management flags when needed - Integration tests for comments (always run) and tags (-cftags flag)
|
@tlimoncelli should tags and CNAME flattening tests have a single gate ( |
Excellent question! Keep them separate, please. Even with a fully paid enterprise account, you can create API keys that are restricted to only support particular features. |
|
OK, ready for review then. I tested it manually quite a bit on a paid zone. I haven't tested comments alone on a free zone, I just realized. I'll do that now. |
| testgroup("CF_COMMENT create", | ||
| only("CLOUDFLAREAPI"), | ||
| domainMeta(map[string]string{"cloudflare_manage_comments": "true"}), | ||
| CfCommentCreate(), tcEmptyZone(), | ||
| ), | ||
|
|
||
| testgroup("CF_COMMENT change", | ||
| only("CLOUDFLAREAPI"), | ||
| domainMeta(map[string]string{"cloudflare_manage_comments": "true"}), | ||
| CfCommentCreate(), CfCommentChange(), | ||
| ), | ||
|
|
||
| testgroup("CF_COMMENT remove", | ||
| only("CLOUDFLAREAPI"), | ||
| domainMeta(map[string]string{"cloudflare_manage_comments": "true"}), | ||
| CfCommentCreate(), CfCommentRemove(), | ||
| ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These can be combined. No need to clear the zone between tests. (for example, testgroup("MX" does it all in one group)
| testgroup("CF_COMMENT create", | |
| only("CLOUDFLAREAPI"), | |
| domainMeta(map[string]string{"cloudflare_manage_comments": "true"}), | |
| CfCommentCreate(), tcEmptyZone(), | |
| ), | |
| testgroup("CF_COMMENT change", | |
| only("CLOUDFLAREAPI"), | |
| domainMeta(map[string]string{"cloudflare_manage_comments": "true"}), | |
| CfCommentCreate(), CfCommentChange(), | |
| ), | |
| testgroup("CF_COMMENT remove", | |
| only("CLOUDFLAREAPI"), | |
| domainMeta(map[string]string{"cloudflare_manage_comments": "true"}), | |
| CfCommentCreate(), CfCommentRemove(), | |
| ), | |
| testgroup("CF_COMMENT create", | |
| only("CLOUDFLAREAPI"), | |
| domainMeta(map[string]string{"cloudflare_manage_comments": "true"}), | |
| CfCommentCreate(), | |
| CfCommentChange(), | |
| CfCommentRemove(), | |
| ), |
| testgroup("CF_TAGS create", | ||
| only("CLOUDFLAREAPI"), | ||
| alltrue(*enableCFTags), | ||
| domainMeta(map[string]string{"cloudflare_manage_tags": "true"}), | ||
| CfTagsCreate(), tcEmptyZone(), | ||
| ), | ||
|
|
||
| testgroup("CF_TAGS change", | ||
| only("CLOUDFLAREAPI"), | ||
| alltrue(*enableCFTags), | ||
| domainMeta(map[string]string{"cloudflare_manage_tags": "true"}), | ||
| CfTagsCreate(), CfTagsChange(), | ||
| ), | ||
|
|
||
| testgroup("CF_TAGS remove", | ||
| only("CLOUDFLAREAPI"), | ||
| alltrue(*enableCFTags), | ||
| domainMeta(map[string]string{"cloudflare_manage_tags": "true"}), | ||
| CfTagsCreate(), CfTagsRemove(), | ||
| ), | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consolidate these:
| testgroup("CF_TAGS create", | |
| only("CLOUDFLAREAPI"), | |
| alltrue(*enableCFTags), | |
| domainMeta(map[string]string{"cloudflare_manage_tags": "true"}), | |
| CfTagsCreate(), tcEmptyZone(), | |
| ), | |
| testgroup("CF_TAGS change", | |
| only("CLOUDFLAREAPI"), | |
| alltrue(*enableCFTags), | |
| domainMeta(map[string]string{"cloudflare_manage_tags": "true"}), | |
| CfTagsCreate(), CfTagsChange(), | |
| ), | |
| testgroup("CF_TAGS remove", | |
| only("CLOUDFLAREAPI"), | |
| alltrue(*enableCFTags), | |
| domainMeta(map[string]string{"cloudflare_manage_tags": "true"}), | |
| CfTagsCreate(), CfTagsRemove(), | |
| ), | |
| testgroup("CF_TAGS create", | |
| only("CLOUDFLAREAPI"), | |
| alltrue(*enableCFTags), | |
| domainMeta(map[string]string{"cloudflare_manage_tags": "true"}), | |
| CfTagsCreate(), | |
| CfTagsChange(), | |
| CfTagsRemove(), | |
| ), | |
| // Helper constants/funcs for the CLOUDFLARE comments testing: | ||
|
|
||
| // A-record with comment | ||
| func CfCommentCreate() *TestCase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that CfCommentCreate() and friends are only used once, please inline them. That has the benefit of making the test data more visible.
| if comment, ok := rec.Metadata["cloudflare_comment"]; ok && comment != "" { | ||
| hasComments = true | ||
| } | ||
| if tags, ok := rec.Metadata["cloudflare_tags"]; ok && tags != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rec.Metadata["cloudflare_tags"] returns "" if there is no "cloudflare_tags" key. It seems like the "ok" checking is overkill.
This would make CF_TAGS("") and not having any tags be equivalent. (which is a good thing. I think?)
Introduced the following Cloudflare-specific modifiers:
Features:
Fixes #1862