Add functions for retrieving individual access rules
@@ -68,6 +68,13 @@ func (api *API) CreateUserAccessRule(accessRule AccessRule) (*AccessRuleResponse
return api.createAccessRule("/user", accessRule)
}
+// UserAccessRule returns the details of a user's account access rule.
+//
+// API reference: https://api.cloudflare.com/#user-level-firewall-access-rule-list-access-rules
+func (api *API) UserAccessRule(accessRuleID string) (*AccessRuleResponse, error) {
+ return api.retrieveAccessRule("/user", accessRuleID)
+}
+
// UpdateUserAccessRule updates a single access rule for the logged-in user &
// given access rule identifier.
//
@@ -102,6 +109,13 @@ func (api *API) CreateZoneAccessRule(zoneID string, accessRule AccessRule) (*Acc
return api.createAccessRule("/zones/"+zoneID, accessRule)
}
+// ZoneAccessRule returns the details of a zone's access rule.
+//
+// API reference: https://api.cloudflare.com/#firewall-access-rule-for-a-zone-list-access-rules
+func (api *API) ZoneAccessRule(zoneID string, accessRuleID string) (*AccessRuleResponse, error) {
+ return api.retrieveAccessRule("/zones/"+zoneID, accessRuleID)
+}
+
// UpdateZoneAccessRule updates a single access rule for the given zone &
// access rule identifiers.
//
@@ -136,6 +150,13 @@ func (api *API) CreateOrganizationAccessRule(organizationID string, accessRule A
return api.createAccessRule("/accounts/"+organizationID, accessRule)
}
+// OrganizationAccessRule returns the details of an organization's access rule.
+//
+// API reference: https://api.cloudflare.com/#account-level-firewall-access-rule-access-rule-details
+func (api *API) OrganizationAccessRule(organizationID string, accessRuleID string) (*AccessRuleResponse, error) {
+ return api.retrieveAccessRule("/accounts/"+organizationID, accessRuleID)
+}
+
// UpdateOrganizationAccessRule updates a single access rule for the given
// organization & access rule identifiers.
//
@@ -209,6 +230,24 @@ func (api *API) createAccessRule(prefix string, accessRule AccessRule) (*AccessR
return response, nil
}
+func (api *API) retrieveAccessRule(prefix, accessRuleID string) (*AccessRuleResponse, error) {
+ uri := prefix + "/firewall/access_rules/rules/" + accessRuleID
+
+ res, err := api.makeRequest("GET", uri, nil)
+
+ if err != nil {
+ return nil, errors.Wrap(err, errMakeRequestError)
+ }
+
+ response := &AccessRuleResponse{}
+ err = json.Unmarshal(res, &response)
+ if err != nil {
+ return nil, errors.Wrap(err, errUnmarshalError)
+ }
+
+ return response, nil
+}
+
func (api *API) updateAccessRule(prefix, accessRuleID string, accessRule AccessRule) (*AccessRuleResponse, error) {
uri := prefix + "/firewall/access_rules/rules/" + accessRuleID
res, err := api.makeRequest("PATCH", uri, accessRule)
