-
Notifications
You must be signed in to change notification settings - Fork 344
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
Fixed lastUpdated timestamp format in api v5 federation resolvers #7596
Fixed lastUpdated timestamp format in api v5 federation resolvers #7596
Conversation
Codecov Report
@@ Coverage Diff @@
## master #7596 +/- ##
=========================================
Coverage 30.13% 30.13%
Complexity 98 98
=========================================
Files 794 794
Lines 84078 84054 -24
Branches 907 907
=========================================
Hits 25333 25333
+ Misses 56615 56591 -24
Partials 2130 2130
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
traffic_ops/traffic_ops_golang/federation_resolvers/federation_resolvers.go
Fixed
Show fixed
Hide fixed
CHANGELOG.md
Outdated
@@ -59,6 +59,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). | |||
- [#7469](https://github.com/apache/trafficcontrol/pull/7469) *Traffic Ops* Changed logic to not report empty or missing cookies into TO error.log. | |||
- [#7586](https://github.com/apache/trafficcontrol/pull/7586) *Traffic Ops* Add permission to Operations Role to read from dnsseckeys endpoint. | |||
- [#7600](https://github.com/apache/trafficcontrol/pull/7600) *t3c* changed default go-direct command line arg to be old to avoid unexpected config changes upon upgrade. | |||
- [#7596](https://github.com/apache/trafficcontrol/pull/7596) *Traffic Ops* Fixes `federation_resolvers` v5 apis to respond with `RFC3339` date/time Format. |
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.
This should be a part of the "fixed" section.
lib/go-tc/federation_resolver.go
Outdated
@@ -50,6 +51,36 @@ type FederationResolver struct { | |||
TypeID *uint `json:"typeId,omitempty" db:"type"` | |||
} | |||
|
|||
// [V5] FederationResolverV5 is an alias for the Federal Resolver struct response used for the latest minor version associated with api major version 5. |
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.
The GoDoc comment should be gin with the name of the function/ struct that it applies to.
lib/go-tc/federation_resolver.go
Outdated
// [V5] FederationResolverV5 is an alias for the Federal Resolver struct response used for the latest minor version associated with api major version 5. | ||
type FederationResolverV5 = FederationResolverV50 | ||
|
||
// [V50] FederationResolverV50 is used for RFC3339 format timestamp in FederationResolver which represents a resolver record for a CDN Federation. |
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.
Same comment here about godocs.
lib/go-tc/federation_resolver.go
Outdated
} | ||
|
||
// [V5] FederationResolversV5Response is an alias for the FederationResolvers struct response used for the latest minor version associated with api major version 5. | ||
type FederationResolversV5Response = FederationResolversV50Response |
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.
Same comment 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.
Doesn't look like this comment was addressed :)
lib/go-tc/federation_resolver.go
Outdated
// [V5] FederationResolversV5Response is an alias for the FederationResolvers struct response used for the latest minor version associated with api major version 5. | ||
type FederationResolversV5Response = FederationResolversV50Response | ||
|
||
// [V50] GET request to its /federation_resolvers endpoint for APIv5. |
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.
Same comment here
lib/go-tc/federation_resolver.go
Outdated
type FederationResolversV5Response = FederationResolversV50Response | ||
|
||
// [V50] GET request to its /federation_resolvers endpoint for APIv5. | ||
type FederationResolversV50Response struct { |
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.
V50 should be at the end of the name of the struct 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.
This one as well.
lib/go-tc/tovalidate/rules.go
Outdated
@@ -217,3 +217,14 @@ func StringIsValidFloat() *validation.StringRule { | |||
return err == nil && !math.IsNaN(validated) | |||
}, "must be a valid float") | |||
} | |||
|
|||
// IsValidIPorCIDR returns whether the input is a valid IP address or CIDR notation subnet | |||
func IsValidIPorCIDR(input string) bool { |
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.
nit: The name should be IsValidIPOrCIDR
, instead of IsValidIPorCIDR
Note that the O
needs to be capitalized
lib/go-tc/tovalidate/rules.go
Outdated
} | ||
|
||
_, _, err := net.ParseCIDR(input) | ||
return err == nil // Valid CIDR notation subnet |
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 return the error from 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.
now removed as i removed post method itself.
@@ -301,3 +306,153 @@ func deleteFederationResolver(inf *api.APIInfo) (tc.Alert, tc.FederationResolver | |||
|
|||
return alert, result, userErr, sysErr, statusCode | |||
} | |||
|
|||
// GetFederationResolvers [V5] - get list of federation resolver for APIv5 |
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.
Since federation_resolvers is not using the CRUDer interface, it will be much easier (and would involve lesser lines of code) if we could just check the api version in the Get
and Create
methods of federation_resolvers, and return the appropriate structs.
You can take a look at this PR for reference: #7547
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.
nice, i would do this srijeet
@@ -466,8 +466,8 @@ func Routes(d ServerData) ([]Route, http.Handler, error) { | |||
{Version: api.Version{Major: 5, Minor: 0}, Method: http.MethodDelete, Path: `federations/{id}/deliveryservices/{dsID}/?$`, Handler: api.DeleteHandler(&federations.TOFedDSes{}), RequiredPrivLevel: auth.PrivLevelAdmin, RequiredPermissions: []string{"FEDERATION:UPDATE", "DELIVERY-SERVICE:UPDATE", "FEDERATION:READ", "DELIVERY-SERVICE:READ"}, Authenticated: Authenticated, Middlewares: nil, ID: 441740257031}, | |||
|
|||
// Federation Resolvers | |||
{Version: api.Version{Major: 5, Minor: 0}, Method: http.MethodPost, Path: `federation_resolvers/?$`, Handler: federation_resolvers.Create, RequiredPrivLevel: auth.PrivLevelAdmin, RequiredPermissions: []string{"FEDERATION-RESOLVER:CREATE", "TYPE:READ"}, Authenticated: Authenticated, Middlewares: nil, ID: 413437366131}, | |||
{Version: api.Version{Major: 5, Minor: 0}, Method: http.MethodGet, Path: `federation_resolvers/?$`, Handler: federation_resolvers.Read, RequiredPrivLevel: auth.PrivLevelReadOnly, RequiredPermissions: []string{"FEDERATION-RESOLVER:READ", "TYPE:READ"}, Authenticated: Authenticated, Middlewares: nil, ID: 45660875931}, | |||
{Version: api.Version{Major: 5, Minor: 0}, Method: http.MethodPost, Path: `federation_resolvers/?$`, Handler: federation_resolvers.CreateFederationResolver, RequiredPrivLevel: auth.PrivLevelAdmin, RequiredPermissions: []string{"FEDERATION-RESOLVER:CREATE", "TYPE:READ"}, Authenticated: Authenticated, Middlewares: nil, ID: 413437366131}, |
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.
If you just used the same functions with the api version checks in there, you wouldn't need to change anything in this file.
Also, could you please change the title of the PR to be something like |
traffic_ops/traffic_ops_golang/federation_resolvers/federation_resolvers.go
Fixed
Show fixed
Hide fixed
lib/go-tc/federation_resolver.go
Outdated
@@ -50,6 +51,36 @@ type FederationResolver struct { | |||
TypeID *uint `json:"typeId,omitempty" db:"type"` | |||
} | |||
|
|||
// FederationResolverV5 [V5] - is an alias for the Federal Resolver struct response used for the latest minor version associated with APIv5. |
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.
nit: Do we need the text within the brackets?
lib/go-tc/federation_resolver.go
Outdated
// FederationResolverV5 [V5] - is an alias for the Federal Resolver struct response used for the latest minor version associated with APIv5. | ||
type FederationResolverV5 = FederationResolverV50 | ||
|
||
// FederationResolverV50 [V50]- is used for RFC3339 format timestamp in FederationResolver which represents a resolver record for a CDN Federation for APIv50. |
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.
Same comment here
lib/go-tc/federation_resolver.go
Outdated
} | ||
|
||
// [V5] FederationResolversV5Response is an alias for the FederationResolvers struct response used for the latest minor version associated with api major version 5. | ||
type FederationResolversV5Response = FederationResolversV50Response |
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.
Doesn't look like this comment was addressed :)
lib/go-tc/federation_resolver.go
Outdated
type FederationResolversV5Response = FederationResolversV50Response | ||
|
||
// [V50] GET request to its /federation_resolvers endpoint for APIv5. | ||
type FederationResolversV50Response struct { |
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.
This one as well.
lib/go-tc/federation_resolver.go
Outdated
} | ||
|
||
// [V5] FederationResolverV5Response represents struct response used for the latest minor version associated with api major version 5. | ||
type FederationResolverV5Response = FederationResolverV50Response |
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.
Same here
@@ -103,6 +101,7 @@ func Create(w http.ResponseWriter, r *http.Request) { | |||
} | |||
|
|||
// Read is the handler for GET requests to /federation_resolvers (and /federation_resolvers/{{ID}}). | |||
// here based on request V5 is identified to get list of federation resolver for APIv5 |
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.
I don't think you need this godoc comment here.
|
||
// Based on version we load types - for version 5 and above we use FederationResolverV5 | ||
var resolvers []interface{} | ||
if inf.Version != nil && inf.Version.Major >= 5 && inf.Version.Minor >= 0 { |
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.
This is fine, but there is a utility function that can be used in place of this if statement like this:
if inf.Version.GreaterThanOrEqualTo(&api.Version{Major: 5, Minor: 0})
for _, item := range frData { | ||
resolvers = append(resolvers, item) | ||
} | ||
} |
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.
This entire code block is not needed, because, on lines 142 and 147, you're declaring a new variable (array), and on the subsequent lines, you're traversing over that array. There are 0 entries in the array, so traversing through it is needless.
if sysErr != nil { | ||
sysErr = fmt.Errorf("federation_resolver scanning: %v", sysErr) | ||
// Based on version we load types - for version 5 and above we use FederationResolverV5 | ||
if inf.Version != nil && inf.Version.Major >= 5 && inf.Version.Minor >= 0 { |
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.
You could use the pre defined utility function here, but it's your call.
} | ||
api.HandleErr(w, r, tx, errCode, userErr, sysErr) | ||
return | ||
resolvers = append(resolvers, resolver) |
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 repeating this block twice, here's what I'd do:
Scan the struct into a v4 struct as it was being done earlier. Then, check for the version, and if it's >= 5.0, then convert the v4 struct into a v5 struct before appending it to the interface array resolvers
.
var v5Resolver tc.FederationResolverV5 | ||
|
||
// Convert FederationResolver fields to FederationResolverV5 fields | ||
v5Resolver.ID = resolver.ID |
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.
This looks good. Do you mind making it into a utility function please, so that future development can make use of it and not have to repeat these lines everywhere?
v5Resolver.LastUpdated = &lastUpdated | ||
v5Resolver.Type = resolver.Type | ||
|
||
resolvers = append(resolvers, &v5Resolver) |
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 this be appending the reference of v5Resolver?
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.
here we are trying to append value of v5Resolver to resolvers, is that done wrongly ?
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.
It needs to append the value of v5Resolver, not the reference (address), which is what the &
does.
So, it should just be
resolvers = append(resolvers, v5Resolver)
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 great! Manual testing also passes.
…ache#7596) * fr changes * fr changes * changelog added * type import correction * fr codefix * fr code changes * comment correction * fixes * comments addressed * changelog correction * fr changed to give rfc format res * removed unused function * version revert for deletion * space added * comments addressed * comments addressed * reference mistake correction
Related: #5911
Fixes
federation_resolver
v5 apis to respond withRFC3339
date/time Format.Which Traffic Control components are affected by this PR?
What is the best way to verify this PR?
Make Api calls to types 5.0
Ferderation Resolver to Use RFC3339 Format
If this is a bugfix, which Traffic Control versions contained the bug?
-7.0.1
PR submission checklist