This is an automated email from the ASF dual-hosted git repository.

mattjackson 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 c0bb2b6  Rework deliveryservices/xmlId/:XMLID/sslkeys/delete (#4519)
c0bb2b6 is described below

commit c0bb2b66db869954780402c16d28735bc646b53d
Author: Michael Hoppal <54542891+mho...@users.noreply.github.com>
AuthorDate: Wed Mar 25 08:00:09 2020 -0600

    Rework deliveryservices/xmlId/:XMLID/sslkeys/delete (#4519)
    
    * Rework deliveryservices/xmlId/:XMLID/sslkeys/delete
    
    * Use common function
---
 CHANGELOG.md                                       |  2 +
 ...deliveryservices_xmlid_xmlid_sslkeys_delete.rst | 27 +++++++++++-
 .../v2/deliveryservices_xmlid_xmlid_sslkeys.rst    | 46 +++++++++++++++++++
 ...deliveryservices_xmlid_xmlid_sslkeys_delete.rst | 51 ----------------------
 .../clients/python/trafficops/tosession.py         |  4 +-
 .../traffic_ops_golang/deliveryservice/keys.go     | 27 +++++++++---
 traffic_ops/traffic_ops_golang/routing/routes.go   |  4 +-
 7 files changed, 98 insertions(+), 63 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index ee75a96..ef77fbf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,7 @@ The format is based on [Keep a 
Changelog](http://keepachangelog.com/en/1.0.0/).
   - /api/2.0/isos
   - /api/1.5/deliveryservice/:id/routing
   - /api/1.5/deliveryservices/sslkeys/generate/letsencrypt `POST`
+  - /api/2.0/deliveryservices/xmlId/:XMLID/sslkeys `DELETE`
   - /deliveryserviceserver/:dsid/:serverid
   - /api/1.5/letsencrypt/autorenew `POST`
   - /api/1.5/letsencrypt/dnsrecords `GET`
@@ -72,6 +73,7 @@ The format is based on [Keep a 
Changelog](http://keepachangelog.com/en/1.0.0/).
   - /deliveryservices/{dsid}/regexes/{regexid} (GET)
   - /deliveryservices/:id (GET)
   - /deliveryservices/:id/state
+  - /deliveryservices/xmlId/:XMLID/sslkeys/delete
   - /divisions/:division_name/regions
   - /divisions/:id
   - /divisions/name/:name
diff --git a/docs/source/api/v1/deliveryservices_xmlid_xmlid_sslkeys_delete.rst 
b/docs/source/api/v1/deliveryservices_xmlid_xmlid_sslkeys_delete.rst
index e10a618..09d2f73 100644
--- a/docs/source/api/v1/deliveryservices_xmlid_xmlid_sslkeys_delete.rst
+++ b/docs/source/api/v1/deliveryservices_xmlid_xmlid_sslkeys_delete.rst
@@ -18,6 +18,8 @@
 ***************************************************
 ``deliveryservices/xmlId/{{xmlid}}/sslkeys/delete``
 ***************************************************
+.. deprecated:: ATCv4
+       Use the ``DELETE`` method of 
:ref:`to-api-deliveryservices-xmlid-xmlid-sslkeys` instead.
 
 ``GET``
 =======
@@ -45,7 +47,28 @@ Request Structure
 
 Response Structure
 ------------------
-.. code-block:: json
+.. code-block:: http
        :caption: Response Example
 
-       { "response": "Successfully deleted ssl keys for <xml_id>" }
+       HTTP/1.1 200 OK
+       Access-Control-Allow-Credentials: true
+       Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, 
Accept, Set-Cookie, Cookie
+       Access-Control-Allow-Methods: POST,GET,OPTIONS,PUT,DELETE
+       Access-Control-Allow-Origin: *
+       Content-Encoding: gzip
+       Content-Type: application/json
+       Set-Cookie: mojolicious=...; Path=/; Expires=Wed, 18 Mar 2020 17:36:10 
GMT; Max-Age=3600; HttpOnly
+       Whole-Content-Sha512: 
Pj+zCoOXg19nGNxcSkjib2iDjG062Y3RcEEV+OYnwbGIsLcpa0BKZleY/qJOKT5DkSoX2qQkckUxUqdDxjVorQ==
+       X-Server-Name: traffic_ops_golang/
+       Date: Wed, 18 Mar 2020 16:36:10 GMT
+       Content-Length: 173
+
+       {
+               "alerts": [
+                       {
+                               "text": "This endpoint is deprecated, please 
use DELETE /deliveryservices/xmlId/:xmlid/sslkeys instead",
+                               "level": "warning"
+                       }
+               ],
+               "response": "Successfully deleted ssl keys for demo1"
+       }
\ No newline at end of file
diff --git a/docs/source/api/v2/deliveryservices_xmlid_xmlid_sslkeys.rst 
b/docs/source/api/v2/deliveryservices_xmlid_xmlid_sslkeys.rst
index f65e64b..020e323 100644
--- a/docs/source/api/v2/deliveryservices_xmlid_xmlid_sslkeys.rst
+++ b/docs/source/api/v2/deliveryservices_xmlid_xmlid_sslkeys.rst
@@ -95,4 +95,50 @@ Response Structure
                "expiration": "2020-08-18T13:53:06Z"
        }}
 
+``DELETE``
+==========
+:Auth. Required: Yes
+:Roles Required: "admin" or "operations"
+:Response Type:  Object (string)
+
+Request Structure
+-----------------
+.. table:: Request Path Parameters
+
+       
+-------+----------+-------------------------------------------------------------+
+       | Name  | Required | Description                                        
         |
+       
+=======+==========+=============================================================+
+       | xmlId | yes      | The :ref:`ds-xmlid` of the desired :term:`Delivery 
Service` |
+       
+-------+----------+-------------------------------------------------------------+
+
+.. table:: Request Query Parameters
+
+       
+---------+----------+------------------------------------------------------------+
+       |   Name  | Required |          Description                             
          |
+       
+=========+==========+============================================================+
+       | version | no       | The version number of the SSL keys that shall be 
retrieved |
+       
+---------+----------+------------------------------------------------------------+
+
+Response Structure
+------------------
+.. code-block:: http
+       :caption: Response Example
+
+       HTTP/1.1 200 OK
+       Access-Control-Allow-Credentials: true
+       Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, 
Accept, Set-Cookie, Cookie
+       Access-Control-Allow-Methods: POST,GET,OPTIONS,PUT,DELETE
+       Access-Control-Allow-Origin: *
+       Content-Encoding: gzip
+       Content-Type: application/json
+       Set-Cookie: mojolicious=...; Path=/; Expires=Wed, 18 Mar 2020 17:36:10 
GMT; Max-Age=3600; HttpOnly
+       Whole-Content-Sha512: 
Pj+zCoOXg19nGNxcSkjib2iDjG062Y3RcEEV+OYnwbGIsLcpa0BKZleY/qJOKT5DkSoX2qQkckUxUqdDxjVorQ==
+       X-Server-Name: traffic_ops_golang/
+       Date: Wed, 18 Mar 2020 16:36:10 GMT
+       Content-Length: 79
+
+       {
+               "response": "Successfully deleted ssl keys for demo1"
+       }
+
 .. [1] These optional fields will be present in the response if and only if 
they were specified during key generation; they are optional during key 
generation and thus cannot be guaranteed to exist or not exist.
diff --git a/docs/source/api/v2/deliveryservices_xmlid_xmlid_sslkeys_delete.rst 
b/docs/source/api/v2/deliveryservices_xmlid_xmlid_sslkeys_delete.rst
deleted file mode 100644
index 8b03332..0000000
--- a/docs/source/api/v2/deliveryservices_xmlid_xmlid_sslkeys_delete.rst
+++ /dev/null
@@ -1,51 +0,0 @@
-..
-..
-.. Licensed under the Apache License, Version 2.0 (the "License");
-.. you may not use this file except in compliance with the License.
-.. You may obtain a copy of the License at
-..
-..     http://www.apache.org/licenses/LICENSE-2.0
-..
-.. Unless required by applicable law or agreed to in writing, software
-.. distributed under the License is distributed on an "AS IS" BASIS,
-.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-.. See the License for the specific language governing permissions and
-.. limitations under the License.
-..
-
-.. _to-api-deliveryservices-xmlid-xmlid-sslkeys-delete:
-
-***************************************************
-``deliveryservices/xmlId/{{xmlid}}/sslkeys/delete``
-***************************************************
-
-``GET``
-=======
-:Auth. Required: Yes
-:Roles Required: "admin" or "operations"
-:Response Type:  Object (string)
-
-Request Structure
------------------
-.. table:: Request Path Parameters
-
-       
+-------+----------+-------------------------------------------------------------+
-       | Name  | Required | Description                                        
         |
-       
+=======+==========+=============================================================+
-       | xmlId | yes      | The :ref:`ds-xmlid` of the desired :term:`Delivery 
Service` |
-       
+-------+----------+-------------------------------------------------------------+
-
-.. table:: Request Query Parameters
-
-       
+---------+----------+------------------------------------------------------------+
-       |   Name  | Required |          Description                             
          |
-       
+=========+==========+============================================================+
-       | version | no       | The version number of the SSL keys that shall be 
retrieved |
-       
+---------+----------+------------------------------------------------------------+
-
-Response Structure
-------------------
-.. code-block:: json
-       :caption: Response Example
-
-       { "response": "Successfully deleted ssl keys for <xml_id>" }
diff --git a/traffic_control/clients/python/trafficops/tosession.py 
b/traffic_control/clients/python/trafficops/tosession.py
index 5468124..f38f0b7 100644
--- a/traffic_control/clients/python/trafficops/tosession.py
+++ b/traffic_control/clients/python/trafficops/tosession.py
@@ -819,11 +819,11 @@ class TOSession(RestApiSession):
                :raises: Union[LoginError, OperationError]
                """
 
-       @api_request('get', 'deliveryservices/xmlId/{xml_id}/sslkeys/delete', 
('2.0',))
+       @api_request('delete', 'deliveryservices/xmlId/{xml_id}/sslkeys', 
('2.0',))
        def delete_deliveryservice_ssl_keys_by_xml_id(self, xml_id=None, 
query_params=None):
                """
                Delete SSL keys for a Delivery Service by xmlId.
-               :ref:`to-api-deliveryservices-xmlid-xmlid-sslkeys-delete`
+               :ref:`to-api-deliveryservices-xmlid-xmlid-sslkeys`
                :param xml_id: The Delivery Service xmlId
                :type xml_id: str
                :param query_params: The url query parameters for the call
diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/keys.go 
b/traffic_ops/traffic_ops_golang/deliveryservice/keys.go
index 3104e60..22c6a8f 100644
--- a/traffic_ops/traffic_ops_golang/deliveryservice/keys.go
+++ b/traffic_ops/traffic_ops_golang/deliveryservice/keys.go
@@ -371,35 +371,50 @@ func base64EncodeCertificate(cert 
*tc.DeliveryServiceSSLKeysCertificate) {
        cert.Key = base64.StdEncoding.EncodeToString([]byte(cert.Key))
 }
 
+// DeleteSSLKeys deletes a Delivery Service's sslkeys via a DELETE method
 func DeleteSSLKeys(w http.ResponseWriter, r *http.Request) {
+       deleteSSLKeys(w, r, false)
+}
+
+// DeleteSSLKeysDeprecated deletes a Delivery Service's sslkeys via a 
deprecated GET method
+func DeleteSSLKeysDeprecated(w http.ResponseWriter, r *http.Request) {
+       deleteSSLKeys(w, r, true)
+}
+
+func deleteSSLKeys(w http.ResponseWriter, r *http.Request, deprecated bool) {
+       alt := "DELETE /deliveryservices/xmlId/:xmlid/sslkeys"
        inf, userErr, sysErr, errCode := api.NewInfo(r, []string{"xmlid"}, nil)
        if userErr != nil || sysErr != nil {
-               api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+               api.HandleErrOptionalDeprecation(w, r, inf.Tx.Tx, errCode, 
userErr, sysErr, deprecated, &alt)
                return
        }
        defer inf.Close()
        if inf.Config.RiakEnabled == false {
-               api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, 
userErr, errors.New("deliveryservice.DeleteSSLKeys: Riak is not configured"))
+               api.HandleErrOptionalDeprecation(w, r, inf.Tx.Tx, 
http.StatusInternalServerError, userErr, 
errors.New("deliveryservice.DeleteSSLKeys: Riak is not configured"), 
deprecated, &alt)
                return
        }
        xmlID := inf.Params["xmlid"]
        dsID, ok, err := getDSIDFromName(inf.Tx.Tx, xmlID)
        if err != nil {
-               api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, 
nil, errors.New("deliveryservice.DeleteSSLKeys: getting DS ID from name 
"+err.Error()))
+               api.HandleErrOptionalDeprecation(w, r, inf.Tx.Tx, 
http.StatusInternalServerError, nil, errors.New("deliveryservice.DeleteSSLKeys: 
getting DS ID from name "+err.Error()), deprecated, &alt)
                return
        } else if !ok {
-               api.HandleErr(w, r, inf.Tx.Tx, http.StatusNotFound, 
errors.New("no DS with name "+xmlID), nil)
+               api.HandleErrOptionalDeprecation(w, r, inf.Tx.Tx, 
http.StatusNotFound, errors.New("no DS with name "+xmlID), nil, deprecated, 
&alt)
                return
        }
        if userErr, sysErr, errCode := tenant.Check(inf.User, xmlID, 
inf.Tx.Tx); userErr != nil || sysErr != nil {
-               api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+               api.HandleErrOptionalDeprecation(w, r, inf.Tx.Tx, errCode, 
userErr, sysErr, deprecated, &alt)
                return
        }
        if err := riaksvc.DeleteDSSSLKeys(inf.Tx.Tx, 
inf.Config.RiakAuthOptions, inf.Config.RiakPort, xmlID, inf.Params["version"]); 
err != nil {
-               api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, 
userErr, errors.New("deliveryservice.DeleteSSLKeys: deleting SSL keys: 
"+err.Error()))
+               api.HandleErrOptionalDeprecation(w, r, inf.Tx.Tx, 
http.StatusInternalServerError, userErr, 
errors.New("deliveryservice.DeleteSSLKeys: deleting SSL keys: "+err.Error()), 
deprecated, &alt)
                return
        }
        api.CreateChangeLogRawTx(api.ApiChange, "DS: "+xmlID+", ID: 
"+strconv.Itoa(dsID)+", ACTION: Deleted SSL keys", inf.User, inf.Tx.Tx)
+       if deprecated {
+               api.WriteAlertsObj(w, r, http.StatusOK, 
api.CreateDeprecationAlerts(&alt), "Successfully deleted ssl keys for "+xmlID)
+               return
+       }
        api.WriteResp(w, r, "Successfully deleted ssl keys for "+xmlID)
 }
 
diff --git a/traffic_ops/traffic_ops_golang/routing/routes.go 
b/traffic_ops/traffic_ops_golang/routing/routes.go
index 146f469..9a8df83 100644
--- a/traffic_ops/traffic_ops_golang/routing/routes.go
+++ b/traffic_ops/traffic_ops_golang/routing/routes.go
@@ -466,7 +466,7 @@ func Routes(d ServerData) ([]Route, []RawRoute, 
http.Handler, error) {
 
                {api.Version{2, 0}, http.MethodGet, 
`deliveryservices/xmlId/{xmlid}/sslkeys$`, 
deliveryservice.GetSSLKeysByXMLIDV15, auth.PrivLevelAdmin, Authenticated, nil, 
2135772907, noPerlBypass},
                {api.Version{2, 0}, http.MethodPost, 
`deliveryservices/sslkeys/add$`, deliveryservice.AddSSLKeys, 
auth.PrivLevelAdmin, Authenticated, nil, 2872878583, noPerlBypass},
-               {api.Version{2, 0}, http.MethodGet, 
`deliveryservices/xmlId/{xmlid}/sslkeys/delete$`, 
deliveryservice.DeleteSSLKeys, auth.PrivLevelOperations, Authenticated, nil, 
2926734, noPerlBypass},
+               {api.Version{2, 0}, http.MethodDelete, 
`deliveryservices/xmlId/{xmlid}/sslkeys$`, deliveryservice.DeleteSSLKeys, 
auth.PrivLevelOperations, Authenticated, nil, 2926734, noPerlBypass},
                {api.Version{2, 0}, http.MethodPost, 
`deliveryservices/sslkeys/generate/?$`, deliveryservice.GenerateSSLKeys, 
auth.PrivLevelOperations, Authenticated, nil, 253439051, noPerlBypass},
                {api.Version{2, 0}, http.MethodPost, 
`deliveryservices/xmlId/{name}/urlkeys/copyFromXmlId/{copy-name}/?$`, 
deliveryservice.CopyURLKeys, auth.PrivLevelOperations, Authenticated, nil, 
2262501076, noPerlBypass},
                {api.Version{2, 0}, http.MethodPost, 
`deliveryservices/xmlId/{name}/urlkeys/generate/?$`, 
deliveryservice.GenerateURLKeys, auth.PrivLevelOperations, Authenticated, nil, 
2530482824, noPerlBypass},
@@ -939,7 +939,7 @@ func Routes(d ServerData) ([]Route, []RawRoute, 
http.Handler, error) {
                {api.Version{1, 5}, http.MethodGet, 
`deliveryservices/hostname/{hostname}/sslkeys$`, 
deliveryservice.GetSSLKeysByHostNameV15, auth.PrivLevelAdmin, Authenticated, 
nil, 2105792224, noPerlBypass},
                {api.Version{1, 1}, http.MethodGet, 
`deliveryservices/hostname/{hostname}/sslkeys$`, 
deliveryservice.GetSSLKeysByHostName, auth.PrivLevelAdmin, Authenticated, nil, 
2105792225, noPerlBypass},
                {api.Version{1, 1}, http.MethodPost, 
`deliveryservices/sslkeys/add$`, deliveryservice.AddSSLKeys, 
auth.PrivLevelAdmin, Authenticated, nil, 1872878583, noPerlBypass},
-               {api.Version{1, 1}, http.MethodGet, 
`deliveryservices/xmlId/{xmlid}/sslkeys/delete$`, 
deliveryservice.DeleteSSLKeys, auth.PrivLevelOperations, Authenticated, nil, 
1926734, noPerlBypass},
+               {api.Version{1, 1}, http.MethodGet, 
`deliveryservices/xmlId/{xmlid}/sslkeys/delete$`, 
deliveryservice.DeleteSSLKeysDeprecated, auth.PrivLevelOperations, 
Authenticated, nil, 1926734, noPerlBypass},
                {api.Version{1, 1}, http.MethodPost, 
`deliveryservices/sslkeys/generate/?(\.json)?$`, 
deliveryservice.GenerateSSLKeys, auth.PrivLevelOperations, Authenticated, nil, 
753439051, noPerlBypass},
                {api.Version{1, 1}, http.MethodPost, 
`deliveryservices/xmlId/{name}/urlkeys/copyFromXmlId/{copy-name}/?(\.json)?$`, 
deliveryservice.CopyURLKeys, auth.PrivLevelOperations, Authenticated, nil, 
1262501076, noPerlBypass},
                {api.Version{1, 1}, http.MethodPost, 
`deliveryservices/xmlId/{name}/urlkeys/generate/?(\.json)?$`, 
deliveryservice.GenerateURLKeys, auth.PrivLevelOperations, Authenticated, nil, 
1530482824, noPerlBypass},

Reply via email to