This is an automated email from the ASF dual-hosted git repository.
zrhoffman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 82901de3a1 Fixes additional profile endpoints V5 apis to respond with
RFC3339 date/time Format (#7759)
82901de3a1 is described below
commit 82901de3a15590d9b0212eb7a7e8b13d973027c9
Author: Jagan Parthiban <[email protected]>
AuthorDate: Wed Aug 30 21:17:59 2023 +0530
Fixes additional profile endpoints V5 apis to respond with RFC3339
date/time Format (#7759)
* V5 profiles/{{ID}}/parameters to respond with RFC3339 time format.
* V5 profiles/name/{{name}}/parameters to respond with RFC3339 time format.
* Documentation Update
* Update CHANGELOG.md
* Update CHANGELOG.md
* Update CHANGELOG.md
---
CHANGELOG.md | 3 +-
docs/source/api/v5/profiles_id_parameters.rst | 8 ++---
.../api/v5/profiles_name_name_parameters.rst | 8 ++---
lib/go-tc/parameters.go | 15 ++++++++
.../profileparameter/parameterprofilebyid.go | 42 ++++++++++++++++------
.../profileparameter/parameterprofilebyname.go | 42 ++++++++++++++++------
6 files changed, 89 insertions(+), 29 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a66862ca15..d91df04da0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -79,6 +79,7 @@ The format is based on [Keep a
Changelog](http://keepachangelog.com/en/1.0.0/).
### Fixed
- [RFC3339](https://github.com/apache/trafficcontrol/issues/5911)
+ - [#7759](https://github.com/apache/trafficcontrol/pull/7759) *Traffic
Ops* Fixed `/profiles/{{ID}}/parameters` and
`profiles/name/{{name}}/parameters` v5 APIs to respond with `RFC3339`
timestamps.
- [#7734](https://github.com/apache/trafficcontrol/pull/7734) *Traffic
Ops* Fixed `/profiles` v5 APIs to respond with `RFC3339` timestamps.
- [#7708](https://github.com/apache/trafficcontrol/pull/7708) *Traffic
Ops* Fixed `/parameters` v5 APIs to respond with `RFC3339` timestamps
- [#7740](https://github.com/apache/trafficcontrol/pull/7740) *Traffic
Ops* Fixed `/staticDNSEntries` v5 APIs to respond with `RFC3339` timestamps.
@@ -101,7 +102,7 @@ The format is based on [Keep a
Changelog](http://keepachangelog.com/en/1.0.0/).
- [#7691](https://github.com/apache/trafficcontrol/pull/7691) *Traffic
Ops* Fixed `/topologies` v5 APIs to respond with `RFC3339` timestamps.
- [#7413](https://github.com/apache/trafficcontrol/issues/7413) *Traffic
Ops* Fixed `/service_category` v5 APIs to respond with `RFC3339` timestamps.
- [#7413](https://github.com/apache/trafficcontrol/issues/7706) *Traffic
Ops* Fixed `/statuses` v5 APIs to respond with `RFC3339` timestamps.
-- [#7743](https://github.com/apache/trafficcontrol/issues/7743) *Traffic Ops*
Fixes /server_server_capabilities apis to respond with RFC3339 date/time format
+ - [#7743](https://github.com/apache/trafficcontrol/issues/7743) *Traffic
Ops* Fixed `/server_server_capabilities` v5 APIs to respond with `RFC3339`
timestamps.
- [#7730](https://github.com/apache/trafficcontrol/pull/7730) *Traffic
Monitor* Fixed the panic seen in TM when `plugin.system_stats.timestamp_ms`
appears as float and not string.
- [#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.
- [#7623](https://github.com/apache/trafficcontrol/pull/7623) *Traffic Ops*
Removed TryIfModifiedSinceQuery from servicecategories.go and reused from ims.go
diff --git a/docs/source/api/v5/profiles_id_parameters.rst
b/docs/source/api/v5/profiles_id_parameters.rst
index 3181404734..68af05fbbf 100644
--- a/docs/source/api/v5/profiles_id_parameters.rst
+++ b/docs/source/api/v5/profiles_id_parameters.rst
@@ -52,7 +52,7 @@ Response Structure
------------------
:configFile: The :term:`Parameter`'s :ref:`parameter-config-file`
:id: The :term:`Parameter`'s :ref:`parameter-id`
-:lastUpdated: The date and time at which this :term:`Parameter` was last
updated, in :ref:`non-rfc-datetime`
+:lastUpdated: The date and time at which this :term:`Parameter` was last
updated, in :rfc:`3339`
:name: :ref:`parameter-name` of the :term:`Parameter`
:profiles: An array of :term:`Profile` :ref:`Names <profile-name>` that use
this :term:`Parameter`
:secure: A boolean value that describes whether or not the
:term:`Parameter` is :ref:`parameter-secure`
@@ -77,7 +77,7 @@ Response Structure
{
"configFile": "global",
"id": 4,
- "lastUpdated": "2018-12-05 17:50:49+00",
+ "lastUpdated": "2018-12-05T23:52:59.696337+05:30",
"name": "tm.instance_name",
"secure": false,
"value": "Traffic Ops CDN"
@@ -85,7 +85,7 @@ Response Structure
{
"configFile": "global",
"id": 5,
- "lastUpdated": "2018-12-05 17:50:49+00",
+ "lastUpdated": "2018-12-05T23:52:59.696337+05:30",
"name": "tm.toolname",
"secure": false,
"value": "Traffic Ops"
@@ -93,7 +93,7 @@ Response Structure
{
"configFile": "regex_revalidate.config",
"id": 7,
- "lastUpdated": "2018-12-05 17:50:49+00",
+ "lastUpdated": "2018-12-05T23:52:59.696337+05:30",
"name": "maxRevalDurationDays",
"secure": false,
"value": "90"
diff --git a/docs/source/api/v5/profiles_name_name_parameters.rst
b/docs/source/api/v5/profiles_name_name_parameters.rst
index 0ad2ff7a52..eeed9cae31 100644
--- a/docs/source/api/v5/profiles_name_name_parameters.rst
+++ b/docs/source/api/v5/profiles_name_name_parameters.rst
@@ -51,7 +51,7 @@ Response Structure
------------------
:configFile: The :term:`Parameter`'s :ref:`parameter-config-file`
:id: The :term:`Parameter`'s :ref:`parameter-id`
-:lastUpdated: The date and time at which this :term:`Parameter` was last
updated, in :ref:`non-rfc-datetime`
+:lastUpdated: The date and time at which this :term:`Parameter` was last
updated, in :rfc:`3339`
:name: :ref:`parameter-name` of the :term:`Parameter`
:profiles: An array of :term:`Profile` :ref:`Names <profile-name>` that use
this :term:`Parameter`
:secure: A boolean value that describes whether or not the
:term:`Parameter` is :ref:`parameter-secure`
@@ -76,7 +76,7 @@ Response Structure
{
"configFile": "global",
"id": 4,
- "lastUpdated": "2018-12-05 17:50:49+00",
+ "lastUpdated": "2018-12-05T23:52:59.696337+05:30",
"name": "tm.instance_name",
"secure": false,
"value": "Traffic Ops CDN"
@@ -84,7 +84,7 @@ Response Structure
{
"configFile": "global",
"id": 5,
- "lastUpdated": "2018-12-05 17:50:49+00",
+ "lastUpdated": "2018-12-05T23:52:59.696337+05:30",
"name": "tm.toolname",
"secure": false,
"value": "Traffic Ops"
@@ -92,7 +92,7 @@ Response Structure
{
"configFile": "regex_revalidate.config",
"id": 7,
- "lastUpdated": "2018-12-05 17:50:49+00",
+ "lastUpdated": "2018-12-05T23:52:59.696337+05:30",
"name": "maxRevalDurationDays",
"secure": false,
"value": "90"
diff --git a/lib/go-tc/parameters.go b/lib/go-tc/parameters.go
index 570dd17374..fc2c60fa48 100644
--- a/lib/go-tc/parameters.go
+++ b/lib/go-tc/parameters.go
@@ -127,6 +127,21 @@ type ProfileParameterByName struct {
Value string `json:"value"`
}
+// ProfileParameterByNameV5 is the alias to the latest minor version of major
version 5
+type ProfileParameterByNameV5 ProfileParameterByNameV50
+
+// ProfileParameterByNameV50 is a structure that's used to represent a
Parameter
+// in a context where they are associated with some Profile specified by a
+// client of the Traffic Ops API by its Name.
+type ProfileParameterByNameV50 struct {
+ ConfigFile string `json:"configFile"`
+ ID int `json:"id"`
+ LastUpdated time.Time `json:"lastUpdated"`
+ Name string `json:"name"`
+ Secure bool `json:"secure"`
+ Value string `json:"value"`
+}
+
// ProfileParameterByNamePost is a structure that's only used internally to
// represent a Parameter that has been requested by a client of the Traffic Ops
// API to be associated with some Profile which was specified by Name.
diff --git
a/traffic_ops/traffic_ops_golang/profileparameter/parameterprofilebyid.go
b/traffic_ops/traffic_ops_golang/profileparameter/parameterprofilebyid.go
index 4492a85b5f..00455d7370 100644
--- a/traffic_ops/traffic_ops_golang/profileparameter/parameterprofilebyid.go
+++ b/traffic_ops/traffic_ops_golang/profileparameter/parameterprofilebyid.go
@@ -35,10 +35,17 @@ func GetProfileID(w http.ResponseWriter, r *http.Request) {
return
}
defer inf.Close()
- api.RespWriter(w, r,
inf.Tx.Tx)(getParametersByProfileID(inf.IntParams["id"], inf.Tx.Tx))
+ params, paramsV5, err := getParametersByProfileID(inf.IntParams["id"],
inf.Tx.Tx, inf.Version)
+
+ if inf.Version.Major >= 5 {
+ api.RespWriter(w, r, inf.Tx.Tx)(paramsV5, err)
+ } else {
+ api.RespWriter(w, r, inf.Tx.Tx)(params, err)
+ }
+
}
-func getParametersByProfileID(profileID int, tx *sql.Tx)
([]tc.ProfileParameterByName, error) {
+func getParametersByProfileID(profileID int, tx *sql.Tx, version *api.Version)
([]tc.ProfileParameterByName, []tc.ProfileParameterByNameV5, error) {
q := `
SELECT
parameter.id, parameter.name, parameter.value, parameter.config_file,
parameter.secure, parameter.last_updated
@@ -49,16 +56,31 @@ WHERE profile.id = $1
`
rows, err := tx.Query(q, profileID)
if err != nil {
- return nil, errors.New("querying profile name parameters: " +
err.Error())
+ return nil, nil, errors.New("querying profile name parameters:
" + err.Error())
}
defer rows.Close()
- params := []tc.ProfileParameterByName{}
- for rows.Next() {
- p := tc.ProfileParameterByName{}
- if err := rows.Scan(&p.ID, &p.Name, &p.Value, &p.ConfigFile,
&p.Secure, &p.LastUpdated); err != nil {
- return nil, errors.New("scanning profile id parameters:
" + err.Error())
+
+ if version.GreaterThanOrEqualTo(&api.Version{Major: 5, Minor: 0}) {
+ params := []tc.ProfileParameterByNameV5{}
+ for rows.Next() {
+ p := tc.ProfileParameterByNameV5{}
+ if err := rows.Scan(&p.ID, &p.Name, &p.Value,
&p.ConfigFile, &p.Secure, &p.LastUpdated); err != nil {
+ return nil, nil, errors.New("scanning profile
id parameters: " + err.Error())
+ }
+ params = append(params, p)
}
- params = append(params, p)
+ return nil, params, nil
+
+ } else {
+ params := []tc.ProfileParameterByName{}
+ for rows.Next() {
+ p := tc.ProfileParameterByName{}
+ if err := rows.Scan(&p.ID, &p.Name, &p.Value,
&p.ConfigFile, &p.Secure, &p.LastUpdated); err != nil {
+ return nil, nil, errors.New("scanning profile
id parameters: " + err.Error())
+ }
+ params = append(params, p)
+ }
+ return params, nil, nil
}
- return params, nil
+
}
diff --git
a/traffic_ops/traffic_ops_golang/profileparameter/parameterprofilebyname.go
b/traffic_ops/traffic_ops_golang/profileparameter/parameterprofilebyname.go
index 2fd0bdc946..08aa2dfff9 100644
--- a/traffic_ops/traffic_ops_golang/profileparameter/parameterprofilebyname.go
+++ b/traffic_ops/traffic_ops_golang/profileparameter/parameterprofilebyname.go
@@ -37,10 +37,17 @@ func GetProfileName(w http.ResponseWriter, r *http.Request)
{
defer inf.Close()
name := inf.Params["name"]
- api.RespWriter(w, r, inf.Tx.Tx)(getParametersByProfileName(inf.Tx.Tx,
name))
+
+ params, paramsV5, err := getParametersByProfileName(inf.Tx.Tx, name,
inf.Version)
+
+ if inf.Version.Major >= 5 {
+ api.RespWriter(w, r, inf.Tx.Tx)(paramsV5, err)
+ } else {
+ api.RespWriter(w, r, inf.Tx.Tx)(params, err)
+ }
}
-func getParametersByProfileName(tx *sql.Tx, profileName string)
([]tc.ProfileParameterByName, error) {
+func getParametersByProfileName(tx *sql.Tx, profileName string, version
*api.Version) ([]tc.ProfileParameterByName, []tc.ProfileParameterByNameV5,
error) {
q := `
SELECT
parameter.id, parameter.name, parameter.value, parameter.config_file,
parameter.secure, parameter.last_updated
@@ -51,16 +58,31 @@ WHERE profile.name = $1
`
rows, err := tx.Query(q, profileName)
if err != nil {
- return nil, errors.New("querying profile name parameters: " +
err.Error())
+ return nil, nil, errors.New("querying profile name parameters:
" + err.Error())
}
defer rows.Close()
- params := []tc.ProfileParameterByName{}
- for rows.Next() {
- p := tc.ProfileParameterByName{}
- if err := rows.Scan(&p.ID, &p.Name, &p.Value, &p.ConfigFile,
&p.Secure, &p.LastUpdated); err != nil {
- return nil, errors.New("scanning profile name
parameters: " + err.Error())
+
+ if version.GreaterThanOrEqualTo(&api.Version{Major: 5, Minor: 0}) {
+ params := []tc.ProfileParameterByNameV5{}
+ for rows.Next() {
+ p := tc.ProfileParameterByNameV5{}
+ if err := rows.Scan(&p.ID, &p.Name, &p.Value,
&p.ConfigFile, &p.Secure, &p.LastUpdated); err != nil {
+ return nil, nil, errors.New("scanning profile
name parameters: " + err.Error())
+ }
+ params = append(params, p)
}
- params = append(params, p)
+ return nil, params, nil
+
+ } else {
+ params := []tc.ProfileParameterByName{}
+ for rows.Next() {
+ p := tc.ProfileParameterByName{}
+ if err := rows.Scan(&p.ID, &p.Name, &p.Value,
&p.ConfigFile, &p.Secure, &p.LastUpdated); err != nil {
+ return nil, nil, errors.New("scanning profile
name parameters: " + err.Error())
+ }
+ params = append(params, p)
+ }
+ return params, nil, nil
}
- return params, nil
+
}