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
Add support for Get/Patch API Shield API Discovery Operations #1413
Conversation
changelog detected ✅ |
…ions This change adds support for the following API Shield related endpoints related to API Discovery: - Retrieve discovered operations on a zone - Patch discovered operations - Patch discovered operation
b5d15ba
to
01e4f42
Compare
PR now ready for review after documentation updated: https://developers.cloudflare.com/api/operations/api-shield-api-discovery-retrieve-discovered-operations-on-a-zone |
api_shield_api_discovery.go
Outdated
// PatchAPIShieldDiscoveryOperation updates certain fields on a discovered operation | ||
// | ||
// API Documentation: https://developers.cloudflare.com/api/operations/api-shield-api-patch-discovered-operation | ||
func (api *API) PatchAPIShieldDiscoveryOperation(ctx context.Context, rc *ResourceContainer, params PatchAPIShieldDiscoveryOperationParams) (*PatchAPIShieldDiscoveryOperation, error) { |
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.
instead of Patch
, we prefer to use Update
unless the HTTP method is important context to have for the caller. more details in https://github.com/cloudflare/cloudflare-go/blob/master/docs/experimental.md#consistent-crud-method-signatures
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.
makes sense to me - thanks!
i went ahead and updated this to match the library conventions from the code review. feel free to take a look and let me know if anything doesn't make sense. otherwise, i'll merge this one in. |
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.
Looks good to me. I'd provide consts for enum like filter conditions that are modeled here as strings
api_shield_api_discovery.go
Outdated
// Origin represents the API discovery engine(s) that discovered this operation | ||
Origin []string `json:"origin"` | ||
// State represents the state of operation in API Discovery | ||
State string `json:"state"` |
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.
Should we provide the set of valid state strings as consts that one can pass here?
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.
entirely up to you folks. we do half and half in other places but once we do SDK generation, we will have allowed enums.
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.
Have opted to add typed field + consts for these fields 80d9650
api_shield_api_discovery.go
Outdated
// API documentation: https://developers.cloudflare.com/api/operations/api-shield-api-patch-discovered-operation | ||
type UpdateAPIShieldDiscoveryOperationParams struct { | ||
// OperationID is the operation to be patched | ||
OperationID string `json:"-" url:"-"` |
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.
Why is this not a uuid?
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.
we pass string for the ID field in normal operations too https://github.com/cloudflare/cloudflare-go/blob/master/api_shield_operations.go#L13-L18
I'm not sure if it's a good idea to enforce the type here or not (we'd need cloudflare-go to depend on a uuid library like github.com/google/uuid
)
@jacobbednarz what do you think? I'm inclined to just stick with string. If a non uuid is provided then the API will respond with an invalid input error
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.
string seems fine to me here.
|
||
uri := fmt.Sprintf("/zones/%s/api_gateway/discovery/operations/%s", rc.Identifier, params.OperationID) | ||
|
||
res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, params) |
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.
Just to check: Does the .makeRequestContext
function add the respective request body and corresponding headers?
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.
Does it know that it should only add the state field and not the operation ID to the request body?
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.
Or should we rather pass the UpdateAPIShieldDiscoveryOperation type here?
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.
yes, the params
(of type UpdateAPIShieldDiscoveryOperationParams
) is what gets put in the body.
The params
struct is serialized to JSON here
Lines 222 to 227 in 217beeb
var jsonBody []byte | |
jsonBody, err = json.Marshal(params) | |
if err != nil { | |
return nil, fmt.Errorf("error marshalling params to JSON: %w", err) | |
} | |
reqBody = bytes.NewReader(jsonBody) |
and the content-type
header is set to application/json
if none is set here
Lines 382 to 384 in 217beeb
if req.Header.Get("Content-Type") == "" { | |
req.Header.Set("Content-Type", "application/json") | |
} |
The operation ID does not get serialized as we set the json tag to -
https://github.com/cloudflare/cloudflare-go/pull/1413/files#diff-a8b0a1c475237e4f8ba6786369d22fa9008203858112922a8a8c1426ce423e6dR60
83d0588
to
80d9650
Compare
@jacobbednarz We're happy for this to be merged |
This functionality has been released in v0.79.0. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
This change adds support for the following API Shield related endpoints related to API Discovery:
Description
This change adds support for API Shield endpoints related to API Shield API Discovery. This is so they can be used from the library and will enable this feature to be added to terraform in the future.
Has your change been tested?
Types of changes
What sort of change does your code introduce/modify?
Checklist:
and relies on stable APIs. (see API Shield API Discovery)