Skip to content

Commit

Permalink
To types rfc format (apache#7575)
Browse files Browse the repository at this point in the history
* types rfc time changes

* types rfc time changes fixes

* type get api scan order fix

* types golang rfc changes

types golang rfc changes

* DOC UPDATED FOR TYPE

* removed unwanted code

* test case fix

error in test case fixed

* revert code

* revert old change

* align correction

* Delete admin

* comments addresed

* typo changes

* comment addressing

* comment changes

* comments addressed

* removed unused TypeNullableV5

* comments corrected as per fnc name

* test case fail fix

* correct method used

* type reference correction

* changelog fixed
  • Loading branch information
gbkannan89 authored Jul 6, 2023
1 parent 79219bf commit 8a08e3b
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- [#7471](https://github.com/apache/trafficcontrol/pull/7471) *Traffic Control Cache Config (t3c)* Fixed issue with MSO non topo origins from multiple cache groups.
- [#4393](https://github.com/apache/trafficcontrol/issues/4393) *Traffic Ops* Fixed the error code and alert structure when TO is queried for a delivery service with no ssl keys.
- [#7590](https://github.com/apache/trafficcontrol/issues/7590) *Traffic Control Cache Config (t3c)* Fixed issue with git detected dubious ownership in repository.
- [#7575](https://github.com/apache/trafficcontrol/pull/7575) *Traffic Ops* Fixes `types` v5 apis to respond with `RFC3339` date/time Format.

### Removed
- [#7271](https://github.com/apache/trafficcontrol/pull/7271) Remove components in `infrastructre/docker/`, not in use as cdn-in-a-box performs the same functionality.
Expand Down
8 changes: 4 additions & 4 deletions docs/source/api/v5/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Response Structure
------------------
:description: A short description of this type
:id: An integral, unique identifier for this type
:lastUpdated: The date and time at which this type was last updated, in :ref:`non-rfc-datetime`
:lastUpdated: The date and time at which this type was last updated, in :rfc:`3339`
:name: The name of this type
:useInTable: The name of the Traffic Ops database table that contains objects which are grouped, identified, or described by this type

Expand All @@ -77,7 +77,7 @@ Response Structure
{ "response": [
{
"id": 48,
"lastUpdated": "2018-12-12 16:26:41+00",
"lastUpdated": "2018-12-12T10:59:07.962423+05:30",
"name": "TC_LOC",
"description": "Location for Traffic Control Component Servers",
"useInTable": "cachegroup"
Expand Down Expand Up @@ -124,7 +124,7 @@ Response Structure

:description: A short description of this type
:id: An integral, unique identifier for this type
:lastUpdated: The date and time at which this type was last updated, in :ref:`non-rfc-datetime`
:lastUpdated: The date and time at which this type was last updated, in :rfc:`3339`
:name: The name of this type
:useInTable: The name of the Traffic Ops database table that contains objects which are grouped, identified, or described by this type

Expand Down Expand Up @@ -152,7 +152,7 @@ Response Structure
"response": [
{
"id": 3004,
"lastUpdated": "2020-02-26 18:58:41+00",
"lastUpdated": "2020-02-26T10:59:07.962423+05:30",
"name": "Example01",
"description": "Example"
"useInTable": "server"
Expand Down
2 changes: 1 addition & 1 deletion docs/source/api/v5/types_id.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Response Structure
"response": [
{
"id": 3004,
"lastUpdated": "2020-02-26 18:58:41+00",
"lastUpdated": "2020-02-26T10:59:07.962423+05:30",
"name": "Example02",
"description": "Example"
"useInTable": "server"
Expand Down
23 changes: 23 additions & 0 deletions lib/go-tc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package tc
import (
"database/sql"
"errors"
"time"
)

// TypesResponse is the type of a response from Traffic Ops to a GET request
Expand Down Expand Up @@ -49,6 +50,28 @@ type TypeNullable struct {
UseInTable *string `json:"useInTable" db:"use_in_table"`
}

// TypesResponseV5 is type struct response used for the latest minor version associated with api major version 5.
type TypesResponseV5 = TypesResponseV50

// TypesResponseV50 is the type of response (for RFC3339) from Traffic Ops to a GET Request
// made to its /types API endpoint.
type TypesResponseV50 struct {
Response []TypeV50 `json:"response"`
Alerts
}

// TypeV5 contains information about a given Type in Traffic Ops used for the latest minor version associated with api major version 5.
type TypeV5 = TypeV50

// TypeV50 contains information about a given Type in Traffic Ops.
type TypeV50 struct {
ID int `json:"id"`
LastUpdated time.Time `json:"lastUpdated"`
Name string `json:"name"`
Description string `json:"description"`
UseInTable string `json:"useInTable"`
}

// GetTypeData returns the type's name and use_in_table, true/false if the
// query returned data, and any error.
//
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 @@ -55,7 +55,7 @@ type TrafficControl struct {
Tenants []tc.Tenant `json:"tenants"`
ServerCheckExtensions []tc.ServerCheckExtensionNullable `json:"servercheck_extensions"`
Topologies []tc.Topology `json:"topologies"`
Types []tc.Type `json:"types"`
Types []tc.TypeV5 `json:"types"`
SteeringTargets []tc.SteeringTargetNullable `json:"steeringTargets"`
Serverchecks []tc.ServercheckRequestNullable `json:"serverchecks"`
Users []tc.UserV4 `json:"users"`
Expand Down
16 changes: 8 additions & 8 deletions traffic_ops/testing/api/v5/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestTypes(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.Type]{
methodTests := utils.TestCase[client.Session, client.RequestOptions, tc.TypeV5]{
"GET": {
"NOT MODIFIED when NO CHANGES made": {
ClientSession: TOSession,
Expand All @@ -65,7 +65,7 @@ func TestTypes(t *testing.T) {
"POST": {
"BAD REQUEST when INVALID useInTable NOT server": {
ClientSession: TOSession,
RequestBody: tc.Type{
RequestBody: tc.TypeV5{
Description: "Host header regular expression-Test",
Name: "TEST_1",
UseInTable: "regex",
Expand All @@ -74,20 +74,20 @@ func TestTypes(t *testing.T) {
},
"OK when VALID request when useInTable=server": {
ClientSession: TOSession,
RequestBody: tc.Type{
RequestBody: tc.TypeV5{
Description: "Host header regular expression-Test",
Name: "TEST_4",
UseInTable: "server",
},
Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK),
Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusCreated),
validateTypeUpdateCreateFields("TEST_4", map[string]interface{}{"Name": "TEST_4"})),
},
},
"PUT": {
"BAD REQUEST when useInTable NOT server": {
EndpointID: GetTypeID(t, "ACTIVE_DIRECTORY"),
ClientSession: TOSession,
RequestBody: tc.Type{
RequestBody: tc.TypeV5{
Description: "Active Directory User",
Name: "TEST_3",
UseInTable: "cachegroup",
Expand All @@ -97,7 +97,7 @@ func TestTypes(t *testing.T) {
"OK when VALID request when useInTable=server": {
EndpointID: GetTypeID(t, "RIAK"),
ClientSession: TOSession,
RequestBody: tc.Type{
RequestBody: tc.TypeV5{
Description: "riak type",
Name: "TEST_5",
UseInTable: "server",
Expand Down Expand Up @@ -158,7 +158,7 @@ func validateTypeSort() utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, alerts tc.Alerts, _ error) {
assert.RequireNotNil(t, resp, "Expected Type response to not be nil.")
var typeNames []string
typeResp := resp.([]tc.Type)
typeResp := resp.([]tc.TypeV5)
for _, typ := range typeResp {
typeNames = append(typeNames, typ.Name)
}
Expand All @@ -169,7 +169,7 @@ func validateTypeSort() utils.CkReqFunc {
func validateTypeFields(expectedResp map[string]interface{}) utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, _ tc.Alerts, _ error) {
assert.RequireNotNil(t, resp, "Expected Type response to not be nil.")
typeResp := resp.([]tc.Type)
typeResp := resp.([]tc.TypeV5)
for field, expected := range expectedResp {
for _, typ := range typeResp {
switch field {
Expand Down
8 changes: 4 additions & 4 deletions traffic_ops/traffic_ops_golang/routing/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ func Routes(d ServerData) ([]Route, http.Handler, error) {
{Version: api.Version{Major: 5, Minor: 0}, Method: http.MethodGet, Path: `system/info/?$`, Handler: systeminfo.Get, RequiredPrivLevel: auth.PrivLevelReadOnly, RequiredPermissions: nil, Authenticated: Authenticated, Middlewares: nil, ID: 42104747531},

//Type: CRUD
{Version: api.Version{Major: 5, Minor: 0}, Method: http.MethodGet, Path: `types/?$`, Handler: api.ReadHandler(&types.TOType{}), RequiredPrivLevel: auth.PrivLevelReadOnly, RequiredPermissions: []string{"TYPE:READ"}, Authenticated: Authenticated, Middlewares: nil, ID: 422670182331},
{Version: api.Version{Major: 5, Minor: 0}, Method: http.MethodPut, Path: `types/{id}$`, Handler: api.UpdateHandler(&types.TOType{}), RequiredPrivLevel: auth.PrivLevelOperations, RequiredPermissions: []string{"TYPE:UPDATE", "TYPE:READ"}, Authenticated: Authenticated, Middlewares: nil, ID: 4886011531},
{Version: api.Version{Major: 5, Minor: 0}, Method: http.MethodPost, Path: `types/?$`, Handler: api.CreateHandler(&types.TOType{}), RequiredPrivLevel: auth.PrivLevelOperations, RequiredPermissions: []string{"TYPE:CREATE", "TYPE:READ"}, Authenticated: Authenticated, Middlewares: nil, ID: 451330819531},
{Version: api.Version{Major: 5, Minor: 0}, Method: http.MethodDelete, Path: `types/{id}$`, Handler: api.DeleteHandler(&types.TOType{}), RequiredPrivLevel: auth.PrivLevelOperations, RequiredPermissions: []string{"TYPE:DELETE", "TYPE:READ"}, Authenticated: Authenticated, Middlewares: nil, ID: 4317577331},
{Version: api.Version{Major: 5, Minor: 0}, Method: http.MethodGet, Path: `types/?$`, Handler: types.Read, RequiredPrivLevel: auth.PrivLevelReadOnly, RequiredPermissions: []string{"TYPE:READ"}, Authenticated: Authenticated, Middlewares: nil, ID: 422670182331},
{Version: api.Version{Major: 5, Minor: 0}, Method: http.MethodPut, Path: `types/{id}$`, Handler: types.Update, RequiredPrivLevel: auth.PrivLevelOperations, RequiredPermissions: []string{"TYPE:UPDATE", "TYPE:READ"}, Authenticated: Authenticated, Middlewares: nil, ID: 4886011531},
{Version: api.Version{Major: 5, Minor: 0}, Method: http.MethodPost, Path: `types/?$`, Handler: types.Create, RequiredPrivLevel: auth.PrivLevelOperations, RequiredPermissions: []string{"TYPE:CREATE", "TYPE:READ"}, Authenticated: Authenticated, Middlewares: nil, ID: 451330819531},
{Version: api.Version{Major: 5, Minor: 0}, Method: http.MethodDelete, Path: `types/{id}$`, Handler: types.Delete, RequiredPrivLevel: auth.PrivLevelOperations, RequiredPermissions: []string{"TYPE:DELETE", "TYPE:READ"}, Authenticated: Authenticated, Middlewares: nil, ID: 4317577331},

//About
{Version: api.Version{Major: 5, Minor: 0}, Method: http.MethodGet, Path: `about/?$`, Handler: about.Handler(), RequiredPrivLevel: auth.PrivLevelReadOnly, RequiredPermissions: nil, Authenticated: Authenticated, Middlewares: nil, ID: 431750116631},
Expand Down
Loading

0 comments on commit 8a08e3b

Please sign in to comment.