Skip to content

Commit

Permalink
Update CDN v5 endpoints to use RFC3339 timestamps (#7549)
Browse files Browse the repository at this point in the history
* Update CDN v5 endpoint to use RFC3339 timestamps

* Get rid of CRUD

* Fix bad merge

* Fix tests and handle locks

* Set ID when updating a CDN

---------

Co-authored-by: Steve Hamrick <shamrick@apache.org>
  • Loading branch information
shamrickus and shamrickus authored Jul 31, 2023
1 parent 814a979 commit 07cdf46
Show file tree
Hide file tree
Showing 10 changed files with 366 additions and 68 deletions.
8 changes: 4 additions & 4 deletions docs/source/api/v5/cdns.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Response Structure
:dnssecEnabled: ``true`` if DNSSEC is enabled on this CDN, otherwise ``false``
:domainName: Top Level Domain name within which this CDN operates
:id: The integral, unique identifier for the CDN
:lastUpdated: Date and time when the CDN was last modified in :ref:`non-rfc-datetime`
:lastUpdated: Date and time when the CDN was last modified in :rfc:`3339`
:name: The name of the CDN
:ttlOverride: A :abbr:`TTL (Time To Live)` value, in seconds, that, if set, overrides all set TTL values on :term:`Delivery Services` in this :abbr:`CDN (Content Delivery Network)`

Expand All @@ -89,15 +89,15 @@ Response Structure
"dnssecEnabled": false,
"domainName": "-",
"id": 1,
"lastUpdated": "2018-11-14 18:21:06+00",
"lastUpdated": "2018-11-14T18:21.32.516553Z",
"name": "ALL",
"ttlOverride": 60
},
{
"dnssecEnabled": false,
"domainName": "mycdn.ciab.test",
"id": 2,
"lastUpdated": "2018-11-14 18:21:14+00",
"lastUpdated": "2018-11-14 18:21.32:516553Z",
"name": "CDN-in-a-Box"
}
]}
Expand Down Expand Up @@ -166,6 +166,6 @@ Response Structure
"dnssecEnabled": false,
"domainName": "quest",
"id": 3,
"lastUpdated": "2018-11-14 20:49:28+00",
"lastUpdated": "2018-11-14T20:49:28.111111Z",
"name": "test",
}}
45 changes: 45 additions & 0 deletions lib/go-tc/cdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,18 @@ package tc

import (
"database/sql"
"time"
)

// CDNsV5Response is a list of CDNs as a response.
// swagger:response CDNsResponse
// in: body
type CDNsV5Response struct {
// in: body
Response []CDNV5 `json:"response"`
Alerts
}

// CDNsResponse is a list of CDNs as a response.
// swagger:response CDNsResponse
// in: body
Expand All @@ -42,6 +52,41 @@ type CDNResponse struct {
Alerts
}

// A CDNV5 represents a set of configuration and hardware that can be used to
// serve content within a specific top-level domain.
type CDNV5 struct {

// The CDN to retrieve
//
// enables Domain Name Security Extensions on the specified CDN
//
// required: true
DNSSECEnabled bool `json:"dnssecEnabled" db:"dnssec_enabled"`

// DomainName of the CDN
//
// required: true
DomainName string `json:"domainName" db:"domain_name"`

// ID of the CDN
//
// required: true
ID int `json:"id" db:"id"`

// LastUpdated
//
LastUpdated time.Time `json:"lastUpdated" db:"last_updated"`

// Name of the CDN
//
// required: true
Name string `json:"name" db:"name"`

// TTLOverride
//
TTLOverride *int `json:"ttlOverride,omitempty" db:"ttl_override"`
}

// A CDN represents a set of configuration and hardware that can be used to
// serve content within a specific top-level domain.
type CDN struct {
Expand Down
2 changes: 1 addition & 1 deletion traffic_ops/testing/api/v5/cdn_locks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ func TestCDNLocks(t *testing.T) {
}
},
"CDN UPDATE": func(t *testing.T) {
cdn := tc.CDN{}
cdn := tc.CDNV5{}
err = json.Unmarshal(dat, &cdn)
assert.NoError(t, err, "Error occurred when unmarshalling request body: %v", err)
alerts, reqInf, err := testCase.ClientSession.UpdateCDN(testCase.EndpointID(), cdn, testCase.RequestOpts)
Expand Down
24 changes: 12 additions & 12 deletions traffic_ops/testing/api/v5/cdns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestCDNs(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.CDN]{
methodTests := utils.TestCase[client.Session, client.RequestOptions, tc.CDNV5]{
"GET": {
"NOT MODIFIED when NO CHANGES made": {
ClientSession: TOSession,
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestCDNs(t *testing.T) {
"POST": {
"BAD REQUEST when CDN ALREADY EXISTS": {
ClientSession: TOSession,
RequestBody: tc.CDN{
RequestBody: tc.CDNV5{
Name: "cdn3",
DNSSECEnabled: false,
DomainName: "test.cdn3.net",
Expand All @@ -122,7 +122,7 @@ func TestCDNs(t *testing.T) {
},
"BAD REQUEST when EMPTY NAME": {
ClientSession: TOSession,
RequestBody: tc.CDN{
RequestBody: tc.CDNV5{
Name: "",
DNSSECEnabled: false,
DomainName: "test.noname.net",
Expand All @@ -131,7 +131,7 @@ func TestCDNs(t *testing.T) {
},
"BAD REQUEST when EMPTY DOMAIN NAME": {
ClientSession: TOSession,
RequestBody: tc.CDN{
RequestBody: tc.CDNV5{
Name: "nodomain",
DNSSECEnabled: false,
DomainName: "",
Expand All @@ -140,7 +140,7 @@ func TestCDNs(t *testing.T) {
},
"FORBIDDEN when READ ONLY USER": {
ClientSession: readOnlyUserSession,
RequestBody: tc.CDN{
RequestBody: tc.CDNV5{
Name: "readOnlyTest",
DNSSECEnabled: false,
DomainName: "test.ro",
Expand All @@ -152,7 +152,7 @@ func TestCDNs(t *testing.T) {
"OK when VALID request": {
EndpointID: GetCDNID(t, "cdn1"),
ClientSession: TOSession,
RequestBody: tc.CDN{
RequestBody: tc.CDNV5{
DNSSECEnabled: false,
DomainName: "domain2",
Name: "cdn1",
Expand All @@ -164,7 +164,7 @@ func TestCDNs(t *testing.T) {
EndpointID: GetCDNID(t, "cdn1"),
ClientSession: TOSession,
RequestOpts: client.RequestOptions{Header: http.Header{rfc.IfUnmodifiedSince: {currentTimeRFC}}},
RequestBody: tc.CDN{
RequestBody: tc.CDNV5{
DNSSECEnabled: false,
DomainName: "newDomain",
Name: "cdn1",
Expand All @@ -175,7 +175,7 @@ func TestCDNs(t *testing.T) {
EndpointID: GetCDNID(t, "cdn1"),
ClientSession: TOSession,
RequestOpts: client.RequestOptions{Header: http.Header{rfc.IfMatch: {rfc.ETag(currentTime)}}},
RequestBody: tc.CDN{
RequestBody: tc.CDNV5{
DNSSECEnabled: false,
DomainName: "newDomain",
Name: "cdn1",
Expand Down Expand Up @@ -233,7 +233,7 @@ func TestCDNs(t *testing.T) {
func validateCDNFields(expectedResp map[string]interface{}) utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, _ tc.Alerts, _ error) {
assert.RequireNotNil(t, resp, "Expected CDN response to not be nil.")
cdnResp := resp.([]tc.CDN)
cdnResp := resp.([]tc.CDNV5)
for field, expected := range expectedResp {
for _, cdn := range cdnResp {
switch field {
Expand Down Expand Up @@ -265,7 +265,7 @@ func validateCDNUpdateFields(name string, expectedResp map[string]interface{}) u
func validateCDNPagination(paginationParam string) utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, _ tc.Alerts, _ error) {
assert.RequireNotNil(t, resp, "Expected CDN response to not be nil.")
paginationResp := resp.([]tc.CDN)
paginationResp := resp.([]tc.CDNV5)

opts := client.NewRequestOptions()
opts.QueryParameters.Set("orderby", "id")
Expand All @@ -289,7 +289,7 @@ func validateCDNSort() utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, alerts tc.Alerts, _ error) {
assert.RequireNotNil(t, resp, "Expected CDN response to not be nil.")
var cdnNames []string
cdnResp := resp.([]tc.CDN)
cdnResp := resp.([]tc.CDNV5)
for _, cdn := range cdnResp {
cdnNames = append(cdnNames, cdn.Name)
}
Expand All @@ -300,7 +300,7 @@ func validateCDNSort() utils.CkReqFunc {
func validateCDNDescSort() utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, alerts tc.Alerts, _ error) {
assert.RequireNotNil(t, resp, "Expected CDN response to not be nil.")
cdnDescResp := resp.([]tc.CDN)
cdnDescResp := resp.([]tc.CDNV5)
var descSortedList []string
var ascSortedList []string
assert.RequireGreaterOrEqual(t, len(cdnDescResp), 2, "Need at least 2 CDNs in Traffic Ops to test desc sort, found: %d", len(cdnDescResp))
Expand Down
4 changes: 2 additions & 2 deletions traffic_ops/testing/api/v5/deliveryservices_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func TestDeliveryServicesKeys(t *testing.T) {
})
}

func createBlankCDN(cdnName string, t *testing.T) tc.CDN {
_, _, err := TOSession.CreateCDN(tc.CDN{
func createBlankCDN(cdnName string, t *testing.T) tc.CDNV5 {
_, _, err := TOSession.CreateCDN(tc.CDNV5{
DNSSECEnabled: false,
DomainName: cdnName + ".ai",
Name: cdnName,
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 @@ -22,7 +22,7 @@ import (
// TrafficControl - maps to the tc-fixtures.json file
type TrafficControl struct {
ASNs []tc.ASNV5 `json:"asns"`
CDNs []tc.CDN `json:"cdns"`
CDNs []tc.CDNV5 `json:"cdns"`
CDNLocks []tc.CDNLock `json:"cdnlocks"`
CacheGroups []tc.CacheGroupNullable `json:"cachegroups"`
Capabilities []tc.Capability `json:"capability"`
Expand Down
Loading

0 comments on commit 07cdf46

Please sign in to comment.