Skip to content

Commit

Permalink
RFC3339 Changes for ProfileParameters. Fixes apache#7737
Browse files Browse the repository at this point in the history
  • Loading branch information
jagan-parthiban committed Aug 22, 2023
1 parent 13184de commit 6329dfb
Show file tree
Hide file tree
Showing 10 changed files with 419 additions and 17 deletions.
16 changes: 8 additions & 8 deletions docs/source/api/v5/profileparameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Request Structure

Response Structure
------------------
:lastUpdated: The date and time at which this :term:`Profile`/:term:`Parameter` association was last modified, in :ref:`non-rfc-datetime`
:lastUpdated: The date and time at which this :term:`Profile`/:term:`Parameter` association was last modified, in :rfc:`3339`
:parameter: The :ref:`parameter-id` of a :term:`Parameter` assigned to ``profile``
:profile: The :ref:`profile-name` of the :term:`Profile` to which the :term:`Parameter` identified by ``parameter`` is assigned

Expand All @@ -73,12 +73,12 @@ Response Structure
{ "response": [
{
"lastUpdated": "2018-12-05 17:50:49+00",
"lastUpdated": "2018-12-05T21:44:14.410503+05:30",
"profile": "GLOBAL",
"parameter": 4
},
{
"lastUpdated": "2018-12-05 17:50:49+00",
"lastUpdated": "2018-12-05T21:44:14.410503+05:30",
"profile": "GLOBAL",
"parameter": 5
}
Expand Down Expand Up @@ -152,7 +152,7 @@ Array Format
Response Structure
------------------
:lastUpdated: The date and time at which the :term:`Profile`/:term:`Parameter` assignment was last modified, in :ref:`non-rfc-datetime`
:lastUpdated: The date and time at which the :term:`Profile`/:term:`Parameter` assignment was last modified, in :rfc:`3339`
:parameter: :ref:`parameter-name` of the :term:`Parameter` which is assigned to ``profile``
:parameterId: The :ref:`parameter-id` of the assigned :term:`Parameter`
:profile: :ref:`profile-name` of the :term:`Profile` to which the :term:`Parameter` is assigned
Expand All @@ -175,14 +175,14 @@ Response Structure
{ "alerts": [
{
"text": "profileParameter was created.",
"text": "All Requested ProfileParameters were created.",
"level": "success"
}
],
"response": {
"lastUpdated": null,
"profile": null,
"lastUpdated": "2018-12-05T21:44:14.410503+05:30",
"profile": "testProfile1",
"profileId": 18,
"parameter": null,
"parameter": "testParam1",
"parameterId": 1
}}
33 changes: 33 additions & 0 deletions lib/go-tc/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"fmt"
"strconv"
"strings"
"time"

"github.com/apache/trafficcontrol/lib/go-util"

Expand Down Expand Up @@ -295,6 +296,16 @@ type ProfileParametersNullable struct {
Parameter *int `json:"parameter" db:"parameter_id"`
}

// ProfileParametersNullableV5 is the latest minor version of the major version 5
type ProfileParametersNullableV5 ProfileParametersNullableV50

// ProfileParametersNullableV50 is an object of the form returned by the Traffic Ops /profileparameters endpoint.
type ProfileParametersNullableV50 struct {
LastUpdated *time.Time `json:"lastUpdated" db:"last_updated"`
Profile *string `json:"profile" db:"profile"`
Parameter *int `json:"parameter" db:"parameter_id"`
}

// ProfileParametersNullableResponse is the structure of a response from
// Traffic Ops to GET requests made to its /profileparameters API endpoint.
//
Expand All @@ -315,6 +326,18 @@ type ProfileParam struct {
LastUpdated *TimeNoMod `json:"lastUpdated"`
}

// ProfileParamV5 is the latest minor version of the major version 5
type ProfileParamV5 ProfileParamV50

// ProfileParamV50 is a relationship between a Profile and some Parameter
// assigned to it as it appears in the Traffic Ops API's responses to the
// /profileparameters endpoint.
type ProfileParamV50 struct {
Parameter int `json:"parameter"`
Profile string `json:"profile"`
LastUpdated *time.Time `json:"lastUpdated"`
}

// ProfileParameterCreationRequest is the type of data accepted by Traffic
// Ops as payloads in POST requests to its /profileparameters endpoint.
type ProfileParameterCreationRequest struct {
Expand All @@ -329,6 +352,16 @@ type ProfileParametersAPIResponse struct {
Alerts
}

// ProfileParametersAPIResponseV5 is the latest minor version of the major version 5
type ProfileParametersAPIResponseV5 ProfileParametersAPIResponseV50

// ProfileParametersAPIResponseV50 is the type of a response from Traffic Ops to
// requests made to its /profileparameters endpoint.
type ProfileParametersAPIResponseV50 struct {
Response []ProfileParamV5 `json:"response"`
Alerts
}

// ProfileExportImportParameterNullable is an object of the form used by Traffic Ops
// to represent parameters for exported and imported profiles.
type ProfileExportImportParameterNullable struct {
Expand Down
49 changes: 49 additions & 0 deletions lib/go-tc/profile_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package tc
* under the License.
*/

import "time"

// ProfileParametersResponse is the type of the response from Traffic Ops to
// GET requests made to its /profileparameters API endpoint.
type ProfileParametersResponse struct {
Expand Down Expand Up @@ -59,3 +61,50 @@ type ProfileParameterNullable struct {
Parameter *string `json:"parameter" db:"parameter"`
ParameterID *int `json:"parameterId" db:"parameter_id"`
}

// ProfileParametersResponseV5 is the type of the response from Traffic Ops to
// GET requests made to its /profileparameters API endpoint.
type ProfileParametersResponseV5 struct {
Response []ProfileParameterV5 `json:"response"`
Alerts
}

// ProfileParameterResponseV5 is a single ProfileParameter response for Create to
// depict what changed.
// swagger:response ProfileParameterResponse
// in: body
type ProfileParameterResponseV5 struct {
// in: body
Response ProfileParameterV5 `json:"response"`
Alerts
}

// ProfileParameterV5 is the latest minor version of the major version 5
type ProfileParameterV5 ProfileParameterV50

// ProfileParameterV50 is a representation of a relationship between a Parameter
// and a Profile to which it is assigned.
//
// Note that not all unique identifiers for each represented object in this
// relationship structure are guaranteed to be populated by the Traffic Ops
// API.
type ProfileParameterV50 struct {
LastUpdated time.Time `json:"lastUpdated"`
Profile string `json:"profile"`
ProfileID int `json:"profileId"`
Parameter string `json:"parameter"`
ParameterID int `json:"parameterId"`
}

// ProfileParameterNullableV5 is the latest minor version of the major version 5
type ProfileParameterNullableV5 ProfileParameterNullableV50

// ProfileParameterNullableV50 is identical to ProfileParameter, except that its
// fields are reference values, which allows them to be nil.
type ProfileParameterNullableV50 struct {
LastUpdated *time.Time `json:"lastUpdated" db:"last_updated"`
Profile *string `json:"profile" db:"profile"`
ProfileID *int `json:"profileId" db:"profile_id"`
Parameter *string `json:"parameter" db:"parameter"`
ParameterID *int `json:"parameterId" db:"parameter_id"`
}
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 @@ -326,7 +326,7 @@ func TestCDNLocks(t *testing.T) {
"profileId": GetProfileID(t, "EDGEInCDN2")(),
"parameterId": GetParameterID(t, "CONFIG proxy.config.admin.user_id", "records.config", "STRING ats")(),
},
Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusCreated)),
},
"FORBIDDEN when ADMIN USER DOESNT OWN LOCK": {
ClientSession: TOSession,
Expand Down
2 changes: 1 addition & 1 deletion traffic_ops/testing/api/v5/profile_parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestProfileParameters(t *testing.T) {
},
},
},
Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK)),
Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusCreated)),
},
"BAD REQUEST when INVALID PROFILEID and PARAMETERID": {
ClientSession: TOSession,
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 @@ -41,7 +41,7 @@ type TrafficControl struct {
Origins []tc.Origin `json:"origins"`
Profiles []tc.Profile `json:"profiles"`
Parameters []tc.Parameter `json:"parameters"`
ProfileParameters []tc.ProfileParameter `json:"profileParameters"`
ProfileParameters []tc.ProfileParameterV5 `json:"profileParameters"`
PhysLocations []tc.PhysLocationV5 `json:"physLocations"`
Regions []tc.RegionV5 `json:"regions"`
Roles []tc.RoleV4 `json:"roles"`
Expand Down
15 changes: 15 additions & 0 deletions traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2304,3 +2304,18 @@ func DeleteCoordinate(tx *sql.Tx, cacheGroupID int, coordinateID int) error {
}
return nil
}

// ProfileParameterExists confirms whether the ProfileParameter exists, and an error (if one occurs).
func ProfileParameterExists(tx *sql.Tx, profileID string, parameterID string) (bool, error) {
var count int
if err := tx.QueryRow("SELECT count(*) FROM profile_parameter WHERE profile=$1 and parameter=$2", profileID, parameterID).Scan(&count); err != nil {
return false, fmt.Errorf("error getting profile_parameter info: %w", err)
}
if count == 0 {
return false, nil
}
if count != 1 {
return false, fmt.Errorf("getting profile_parameter info - expected row count: 1, actual: %d", count)
}
return true, nil
}
Loading

0 comments on commit 6329dfb

Please sign in to comment.