Skip to content

Commit

Permalink
Update timestamp for Delivery service Request Comment to match RFC333…
Browse files Browse the repository at this point in the history
…9 format (#7570)

* wip

* add remaining methods

* Add changelog, fix formatting

* code review comments

* add nano
  • Loading branch information
srijeet0406 authored Jun 23, 2023
1 parent c1e70b7 commit b2ca0f2
Show file tree
Hide file tree
Showing 8 changed files with 312 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,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.

### Fixed
- [#7570](https://github.com/apache/trafficcontrol/pull/7570) *Traffic Ops* Fixes `deliveryservice_request_comments` v5 apis to respond with `RFC3339` date/time Format.
- [#7312](https://github.com/apache/trafficcontrol/issues/7312) *Docs* Changing docs for CDN locks for DELETE response structure v4 and v5.
- [#7572](https://github.com/apache/trafficcontrol/pull/7572) *Traffic Ops* Fixes Delivery Service Requests V5 apis docs with RFC3339 date/time Format
- [#7539](https://github.com/apache/trafficcontrol/pull/7539) *Traffic Monitor* Use stats_over_http timestamp to calculate bandwidth for TM's health.
Expand Down
14 changes: 7 additions & 7 deletions docs/source/api/v5/deliveryservice_request_comments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Response Structure
:authorId: The integral, unique identifier of the user who created the comment.
:deliveryServiceRequestId: The integral, unique identifier of the :term:`Delivery Service Request` that the comment was posted on.
:id: The integral, unique identifier of the :term:`DSR` comment.
:lastUpdated: The date and time at which the user was last modified, in :ref:`non-rfc-datetime`
:lastUpdated: The date and time at which the user was last modified, in :rfc:`3339`
:value: The text of the comment that was posted.
:xmlId: This is the ``xmlId`` value that you provided in the request.

Expand All @@ -88,7 +88,7 @@ Response Structure
"author": "admin",
"deliveryServiceRequestId": 2,
"id": 3,
"lastUpdated": "2020-02-24 19:59:46+00",
"lastUpdated": "2020-02-24T19:59:46.682939-06:00",
"value": "Changing to a different origin for now.",
"xmlId": "demo1"
},
Expand All @@ -97,7 +97,7 @@ Response Structure
"author": "admin",
"deliveryServiceRequestId": 2,
"id": 4,
"lastUpdated": "2020-02-24 19:59:55+00",
"lastUpdated": "2020-02-24T19:59:55.782431-06:00",
"value": "Using HTTPS.",
"xmlId": "demo1"
}
Expand Down Expand Up @@ -141,7 +141,7 @@ Response Structure
:authorId: The integral, unique identifier of the user who created the comment.
:deliveryServiceRequestId: The integral, unique identifier of the :term:`Delivery Service Request` that the comment was posted on.
:id: The integral, unique identifier of the :term:`DSR` comment.
:lastUpdated: The date and time at which the user was last modified, in :ref:`non-rfc-datetime`
:lastUpdated: The date and time at which the user was last modified, in :rfc:`3339`
:value: The text of the comment that was posted.
:xmlId: This is the ``xmlId`` value that you provided in the request.

Expand Down Expand Up @@ -173,7 +173,7 @@ Response Structure
"author": null,
"deliveryServiceRequestId": 2,
"id": 6,
"lastUpdated": "2020-02-24 20:02:20+00",
"lastUpdated": "2020-02-24T20:02:20.583524-06:00",
"value": "Does anyone have time to review my delivery service request?",
"xmlId": null
}
Expand Down Expand Up @@ -226,7 +226,7 @@ Response Structure
:authorId: The integral, unique identifier of the user who created the comment.
:deliveryServiceRequestId: The integral, unique identifier of the :term:`Delivery Service Request` that the comment was posted on.
:id: The integral, unique identifier of the :term:`DSR` comment.
:lastUpdated: The date and time at which the user was last modified, in :ref:`non-rfc-datetime`
:lastUpdated: The date and time at which the user was last modified, in :rfc:`3339`
:value: The text of the comment that was posted.
:xmlId: This is the ``xmlId`` value that you provided in the request.

Expand Down Expand Up @@ -258,7 +258,7 @@ Response Structure
"author": null,
"deliveryServiceRequestId": 2,
"id": 6,
"lastUpdated": "2020-02-24 20:05:46+00",
"lastUpdated": "2020-02-24T20:05:46.124229-06:00",
"value": "Update: We no longer need this, feel free to reject.\n\nDoes anyone have time to review my delivery service request?",
"xmlId": null
}
Expand Down
31 changes: 31 additions & 0 deletions lib/go-tc/deliveryservice_request_comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,37 @@ package tc
* under the License.
*/

import (
"time"
)

// DeliveryServiceRequestCommentV5 is a Delivery Service Request Comment as it appears in version 5 of the
// Traffic Ops API - it always points to the highest minor version in APIv5.
type DeliveryServiceRequestCommentV5 DeliveryServiceRequestCommentV50

// DeliveryServiceRequestCommentV50 is a struct containing the fields for a delivery
// service request comment, for API version 5.0.
type DeliveryServiceRequestCommentV50 struct {
AuthorID IDNoMod `json:"authorId" db:"author_id"`
Author string `json:"author"`
DeliveryServiceRequestID int `json:"deliveryServiceRequestId" db:"deliveryservice_request_id"`
ID int `json:"id" db:"id"`
LastUpdated time.Time `json:"lastUpdated" db:"last_updated"`
Value string `json:"value" db:"value"`
XMLID string `json:"xmlId" db:"xml_id"`
}

// DeliveryServiceRequestCommentsResponseV5 is a Delivery Service Request Comment Response as it appears in version 5
// of the Traffic Ops API - it always points to the highest minor version in APIv5.
type DeliveryServiceRequestCommentsResponseV5 DeliveryServiceRequestCommentsResponseV50

// DeliveryServiceRequestCommentsResponseV50 is a list of
// DeliveryServiceRequestCommentsV5 as a response, for API version 5.0.
type DeliveryServiceRequestCommentsResponseV50 struct {
Response []DeliveryServiceRequestCommentV5 `json:"response"`
Alerts
}

// DeliveryServiceRequestCommentsResponse is a list of
// DeliveryServiceRequestComments as a response.
type DeliveryServiceRequestCommentsResponse struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestDeliveryServiceRequestComments(t *testing.T) {
currentTimeRFC := currentTime.Format(time.RFC1123)
tomorrow := currentTime.AddDate(0, 0, 1).Format(time.RFC1123)

methodTests := utils.TestCase[client.Session, client.RequestOptions, tc.DeliveryServiceRequestComment]{
methodTests := utils.TestCase[client.Session, client.RequestOptions, tc.DeliveryServiceRequestCommentV5]{
"GET": {
"NOT MODIFIED when NO CHANGES made": {
ClientSession: TOSession,
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestDeliveryServiceRequestComments(t *testing.T) {
"OK when VALID request": {
EndpointID: GetDSRequestCommentId(t, "admin"),
ClientSession: TOSession,
RequestBody: tc.DeliveryServiceRequestComment{
RequestBody: tc.DeliveryServiceRequestCommentV5{
DeliveryServiceRequestID: GetDSRequestId(t, "test-ds1")(),
Value: "updated comment",
},
Expand All @@ -78,13 +78,13 @@ func TestDeliveryServiceRequestComments(t *testing.T) {
EndpointID: GetDSRequestCommentId(t, "admin"),
ClientSession: TOSession,
RequestOpts: client.RequestOptions{Header: http.Header{rfc.IfUnmodifiedSince: {currentTimeRFC}}},
RequestBody: tc.DeliveryServiceRequestComment{},
RequestBody: tc.DeliveryServiceRequestCommentV5{},
Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusPreconditionFailed)),
},
"PRECONDITION FAILED when updating with IFMATCH ETAG Header": {
EndpointID: GetDSRequestCommentId(t, "admin"),
ClientSession: TOSession,
RequestBody: tc.DeliveryServiceRequestComment{},
RequestBody: tc.DeliveryServiceRequestCommentV5{},
RequestOpts: client.RequestOptions{Header: http.Header{rfc.IfMatch: {rfc.ETag(currentTime)}}},
Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusPreconditionFailed)),
},
Expand Down Expand Up @@ -147,7 +147,7 @@ func GetDSRequestId(t *testing.T, xmlId string) func() int {
func validateSortedDSRequestComments() utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, _ tc.Alerts, err error) {
var sortedList []string
dsReqComments := resp.([]tc.DeliveryServiceRequestComment)
dsReqComments := resp.([]tc.DeliveryServiceRequestCommentV5)

for _, comment := range dsReqComments {
sortedList = append(sortedList, comment.XMLID)
Expand Down
2 changes: 1 addition & 1 deletion traffic_ops/testing/api/v5/traffic_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type TrafficControl struct {
Coordinates []tc.CoordinateV5 `json:"coordinates"`
DeliveryServicesRegexes []tc.DeliveryServiceRegexesTest `json:"deliveryServicesRegexes"`
DeliveryServiceRequests []tc.DeliveryServiceRequestV5 `json:"deliveryServiceRequests"`
DeliveryServiceRequestComments []tc.DeliveryServiceRequestComment `json:"deliveryServiceRequestComments"`
DeliveryServiceRequestComments []tc.DeliveryServiceRequestCommentV5 `json:"deliveryServiceRequestComments"`
DeliveryServices []tc.DeliveryServiceV5 `json:"deliveryservices"`
DeliveryServicesRequiredCapabilities []tc.DeliveryServicesRequiredCapability `json:"deliveryservicesRequiredCapabilities"`
DeliveryServiceServerAssignments []tc.DeliveryServiceServers `json:"deliveryServiceServerAssignments"`
Expand Down
Loading

0 comments on commit b2ca0f2

Please sign in to comment.