You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2020/10/21 15:08:05 UTC

[GitHub] [trafficcontrol] mitchell852 opened a new pull request #5179: Adds the ability to apply a cdn lock aka a "do not make changes right now" notice via TP/TO API

mitchell852 opened a new pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179


   In Traffic Control, 2 actions are global to a CDN:
   
   1. Snapshotting a CDN
   2. Queuing servers updates for a CDN
   
   Because of this, incomplete changes can accidentally be pushed to the TM/TR via a cdn "snapshot" or to caches via a cdn "queue updates".
   
   This PR provides users w/ operations+ role the ability to "lock" a cdn which does 2 things:
   
   1. adds lockedBy and lockedReason to a cdn
   2. displays a persistent message in TP as such:
   
   ![image](https://user-images.githubusercontent.com/251272/96739017-91ec7f80-137c-11eb-8fc6-f4c371872dae.png)
   
   What this PR does NOT do:
   
   - it does not lock the database in any way (yet)
   - it does not prevent any api usage in any way (yet)
   
   <!--
   ************ STOP!! ************
   If this Pull Request is intended to fix a security vulnerability, DO NOT submit it! Instead, contact
   the Apache Software Foundation Security Team at security@trafficcontrol.apache.org and follow the
   guidelines at https://www.apache.org/security/ regarding vulnerability disclosure.
   -->
   ## What does this PR (Pull Request) do?
   <!-- Explain the changes you made here. If this fixes an Issue, identify it by
   replacing the text in the checkbox item with the Issue number e.g.
   
   - [x] This PR fixes #9001 OR is not related to any Issue
   
   ^ This will automatically close Issue number 9001 when the Pull Request is
   merged (The '#' is important).
   
   Be sure you check the box properly, see the "The following criteria are ALL
   met by this PR" section for details.
   -->
   
   - [ ] This PR fixes #REPLACE_ME OR is not related to any Issue <!-- You can check for an issue here: https://github.com/apache/trafficcontrol/issues -->
   
   
   ## Which Traffic Control components are affected by this PR?
   <!-- Please delete all components from this list that are NOT affected by this
   Pull Request. Also, feel free to add the name of a tool or script that is
   affected but not on the list.
   
   Additionally, if this Pull Request does NOT affect documentation, please
   explain why documentation is not required. -->
   
   - CDN in a Box
   - Documentation
   - Grove
   - Traffic Control Client <!-- Please specify which; e.g. 'Python', 'Go', 'Java' -->
   - Traffic Monitor
   - Traffic Ops
   - Traffic Ops ORT
   - Traffic Portal
   - Traffic Router
   - Traffic Stats
   - Traffic Vault
   - CI tests
   
   ## What is the best way to verify this PR?
   <!-- Please include here ALL the steps necessary to test your Pull Request. If
   it includes tests (and most should), outline here the steps needed to run the
   tests. If not, lay out the manual testing procedure and please explain why
   tests are unnecessary for this Pull Request. -->
   
   ## If this is a bug fix, what versions of Traffic Control are affected?
   <!-- If this PR fixes a bug, please list here all of the affected versions - to
   the best of your knowledge. It's also pretty helpful to include a commit hash
   of where 'master' is at the time this PR is opened (if it affects master),
   because what 'master' means will change over time. For example, if this PR
   fixes a bug that's present in master (at commit hash '1df853c8'), in v4.0.0,
   and in the current 4.0.1 Release candidate (e.g. RC1), then this list would
   look like:
   
   - master (1df853c8)
   - 4.0.0
   - 4.0.1 (RC1)
   
   If you don't know what other versions might have this bug, AND don't know how
   to find the commit hash of 'master', then feel free to leave this section
   blank (or, preferably, delete it entirely).
    -->
   
   
   ## The following criteria are ALL met by this PR
   <!-- Check the boxes to signify that the associated statement is true. To
   "check a box", replace the space inside of the square brackets with an 'x'.
   e.g.
   
   - [ x] <- Wrong
   - [x ] <- Wrong
   - [] <- Wrong
   - [*] <- Wrong
   - [x] <- Correct!
   
   -->
   
   - [ ] This PR includes tests OR I have explained why tests are unnecessary
   - [ ] This PR includes documentation OR I have explained why documentation is unnecessary
   - [ ] This PR includes an update to CHANGELOG.md OR such an update is not necessary
   - [ ] This PR includes any and all required license headers
   - [ ] This PR ensures that database migration sequence is correct OR this PR does not include a database migration
   - [ ] This PR **DOES NOT FIX A SERIOUS SECURITY VULNERABILITY** (see [the Apache Software Foundation's security guidelines](https://www.apache.org/security/) for details)
   
   
   ## Additional Information
   <!-- If you would like to include any additional information on the PR for
   potential reviewers please put it here.
   
   Some examples of this would be:
   
   - Before and after screenshots/gifs of the Traffic Portal if it is affected
   - Links to other dependent Pull Requests
   - References to relevant context (e.g. new/updates to dependent libraries,
   mailing list records, blueprints)
   
   Feel free to leave this section blank (or, preferably, delete it entirely).
   -->
   
   <!--
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you 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.
   -->
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#issuecomment-781714419


   it's alright. i'm going to rethink this and probably just create a GET/POST/PUT/DELETE 4.0/cdn_notifications endpoint


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r583798220



##########
File path: traffic_ops/traffic_ops_golang/routing/routes.go
##########
@@ -355,6 +356,11 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
 		{api.Version{4, 0}, http.MethodPost, `coordinates/?$`, api.CreateHandler(&coordinate.TOCoordinate{}), auth.PrivLevelOperations, Authenticated, nil, 44281121573},
 		{api.Version{4, 0}, http.MethodDelete, `coordinates/?$`, api.DeleteHandler(&coordinate.TOCoordinate{}), auth.PrivLevelOperations, Authenticated, nil, 43038498893},
 
+		//CDN notification
+		{api.Version{4, 0}, http.MethodGet, `cdn_notifications/?$`, cdnnotification.Read, auth.PrivLevelReadOnly, Authenticated, nil, 2221224514},
+		{api.Version{4, 0}, http.MethodPost, `cdn_notifications`, cdnnotification.Create, auth.PrivLevelOperations, Authenticated, nil, 2765223513},

Review comment:
       fixed. will push shortly.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 merged pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
ocket8888 merged pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r583875533



##########
File path: traffic_ops/testing/api/v4/cdnnotifications_test.go
##########
@@ -0,0 +1,61 @@
+package v4
+
+/*
+
+   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.
+*/
+
+import (
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"testing"
+)
+
+func TestCDNNotifications(t *testing.T) {
+	WithObjs(t, []TCObj{CDNs, CDNNotifications}, func() {
+		GetTestCDNotifications(t)
+	})
+}
+
+func GetTestCDNotifications(t *testing.T) {
+	for _, cdn := range testData.CDNs {
+		resp, _, err := TOSession.GetCDNNotifications(cdn.Name, nil)
+		if err != nil {
+			t.Errorf("cannot GET cdn notification for cdn: %v - %v", err, resp)
+		}
+		if len(resp) > 0 {
+			respNotification := resp[0]
+			expectedNotification := "test notification: " + cdn.Name
+			if *respNotification.Notification != expectedNotification {

Review comment:
       This will segfault if the CDN has no notification, should check `respNotification.Notification != nil` first

##########
File path: traffic_ops/v4-client/cdn_notifications.go
##########
@@ -0,0 +1,55 @@
+/*
+
+   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.
+*/
+
+package client
+
+import (
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/traffic_ops/toclientlib"
+	"net/http"
+	"net/url"

Review comment:
       standard library imports should be grouped before project-local imports

##########
File path: traffic_ops/testing/api/v4/cdnnotifications_test.go
##########
@@ -0,0 +1,61 @@
+package v4
+
+/*
+
+   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.
+*/
+
+import (
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"testing"

Review comment:
       standard library imports should be grouped before project-local imports




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r583055015



##########
File path: traffic_portal/app/src/common/modules/header/header.tpl.html
##########
@@ -40,7 +40,7 @@
             <li role="presentation" class="dropdown" ng-if="hasCapability('change-logs-read')">
                 <div class="btn-group" title="Change Logs" uib-dropdown is-open="alerts.isopen">
                     <button id="alertsButton" type="button" class="btn btn-link" ng-click="getChangeLogs()" uib-dropdown-toggle>
-                        <i class="fa fa-comment-o"></i>
+                        <i class="fa" ng-class="{ 'fa-comment': newLogCount() > 0, 'fa-comment-o': newLogCount() == 0 }"></i>

Review comment:
       Oh, that's because it doesn't need the curly braces. It's not an object anymore. My bad.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#issuecomment-781689123


   > Doesn't that technically require a minor version bump for each?
   
   well i don't want that. i'll look into it.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r583796204



##########
File path: traffic_ops/traffic_ops_golang/routing/routes.go
##########
@@ -355,6 +356,11 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
 		{api.Version{4, 0}, http.MethodPost, `coordinates/?$`, api.CreateHandler(&coordinate.TOCoordinate{}), auth.PrivLevelOperations, Authenticated, nil, 44281121573},
 		{api.Version{4, 0}, http.MethodDelete, `coordinates/?$`, api.DeleteHandler(&coordinate.TOCoordinate{}), auth.PrivLevelOperations, Authenticated, nil, 43038498893},
 
+		//CDN notification
+		{api.Version{4, 0}, http.MethodGet, `cdn_notifications/?$`, cdnnotification.Read, auth.PrivLevelReadOnly, Authenticated, nil, 2221224514},
+		{api.Version{4, 0}, http.MethodPost, `cdn_notifications`, cdnnotification.Create, auth.PrivLevelOperations, Authenticated, nil, 2765223513},

Review comment:
       oh sorry, maybe i'm looking at the wrong one




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r578604686



##########
File path: docs/source/api/v4/cdns_id_notification.rst
##########
@@ -0,0 +1,123 @@
+..
+..
+.. 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-cdns-id-notification:
+
+****************************
+``cdns/{{ID}}/notification``

Review comment:
       > Can you not GET the notification?
   
   a notification is attached to the cdn so you "get" it  by calling GET /cdns. think that's ok? i hate to add a route that has no value add.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r583945114



##########
File path: traffic_ops/testing/api/v4/cdnnotifications_test.go
##########
@@ -0,0 +1,61 @@
+package v4
+
+/*
+
+   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.
+*/
+
+import (
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"testing"

Review comment:
       That's a weird-sounding button




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r582460865



##########
File path: lib/go-tc/cdn_notification.go
##########
@@ -0,0 +1,58 @@
+package tc
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+
+	"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
+	"github.com/apache/trafficcontrol/lib/go-util"
+
+	"github.com/go-ozzo/ozzo-validation"
+)
+
+// CDNNotificationsResponse is a list of CDN notifications as a response.
+type CDNNotificationsResponse struct {
+	Response []CDNNotification `json:"response"`
+	Alerts
+}
+
+// CDNNotificationRequest encodes the request data for the POST
+// cdn_notifications endpoint.
+type CDNNotificationRequest struct {
+	CDN          string `json:"cdn"`
+	Notification string `json:"notification"`
+}
+
+// CDNNotification is a notification created for a specific CDN
+type CDNNotification struct {
+	CDN          *string    `json:"cdn" db:"cdn"`
+	LastUpdated  *TimeNoMod `json:"lastUpdated" db:"last_updated"`

Review comment:
       sure. i really don't know the difference tbh. i was just following a pattern that someone introduced.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r583807908



##########
File path: traffic_ops/traffic_ops_golang/cdnnotification/cdnnotifications.go
##########
@@ -0,0 +1,191 @@
+package cdnnotification
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+	"errors"
+	"fmt"
+	"net/http"
+
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/lib/go-util"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+)
+
+const readQuery = `
+SELECT cn.cdn, 
+	cn.last_updated,
+	cn.user, 
+	cn.notification 
+FROM cdn_notification as cn
+INNER JOIN cdn ON cdn.name = cn.cdn
+INNER JOIN tm_user ON tm_user.username = cn.user
+`
+
+const insertQuery = `
+INSERT INTO cdn_notification (cdn, "user", notification)
+VALUES ($1, $2, $3)
+RETURNING cdn_notification.cdn,
+          cdn_notification.last_updated,
+          cdn_notification.user,
+          cdn_notification.notification
+`
+
+const deleteQuery = `
+DELETE FROM cdn_notification
+WHERE cdn_notification.cdn = $1
+RETURNING cdn_notification.cdn,
+          cdn_notification.last_updated,
+          cdn_notification.user,
+          cdn_notification.notification
+`
+
+// Read is the handler for GET requests to /cdn_notifications.
+func Read(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	tx := inf.Tx.Tx
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	cdnNotifications := []tc.CDNNotification{}
+
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cdn":  dbhelpers.WhereColumnInfo{"cdn.name", nil},
+		"user": dbhelpers.WhereColumnInfo{"tm_user.username", nil},
+	}
+
+	where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		sysErr = util.JoinErrs(errs)
+		errCode = http.StatusBadRequest
+		api.HandleErr(w, r, tx, errCode, nil, sysErr)
+		return
+	}
+
+	query := readQuery + where + orderBy + pagination
+	rows, err := inf.Tx.NamedQuery(query, queryValues)
+	if err != nil {
+		userErr, sysErr, errCode = api.ParseDBError(err)
+		if sysErr != nil {
+			sysErr = fmt.Errorf("notification read query: %v", sysErr)
+		}
+
+		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+		return
+	}
+	defer rows.Close()
+
+	for rows.Next() {
+		var n tc.CDNNotification
+		if err = rows.Scan(&n.CDN, &n.LastUpdated, &n.User, &n.Notification); err != nil {
+			api.HandleErr(w, r, tx, http.StatusInternalServerError, nil, errors.New("scanning cdn notifications: "+err.Error()))
+			return
+		}
+		cdnNotifications = append(cdnNotifications, n)
+	}
+
+	api.WriteResp(w, r, cdnNotifications)
+}
+
+// Create is the handler for POST requests to /cdn_notifications.
+func Create(w http.ResponseWriter, r *http.Request) {
+	inf, sysErr, userErr, errCode := api.NewInfo(r, nil, nil)
+	tx := inf.Tx.Tx
+	if sysErr != nil || userErr != nil {
+		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	var req tc.CDNNotificationRequest
+	if userErr = api.Parse(r.Body, tx, &req); userErr != nil {
+		api.HandleErr(w, r, tx, http.StatusBadRequest, userErr, nil)
+		return
+	}
+
+	var resp tc.CDNNotification
+	err := tx.QueryRow(insertQuery, req.CDN, inf.User.UserName, req.Notification).Scan(&resp.CDN, &resp.LastUpdated, &resp.User, &resp.Notification)
+	if err != nil {
+		userErr, sysErr, errCode = api.ParseDBError(err)
+		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+		return
+	}
+
+	changeLogMsg := fmt.Sprintf("CDN_NOTIFICATION: %s, CDN: %s, ACTION: Created", *resp.Notification, resp.CDN)
+	api.CreateChangeLogRawTx(api.ApiChange, changeLogMsg, inf.User, tx)
+
+	alertMsg := fmt.Sprintf("CDN notification created [ User = %s ] for CDN: %s", resp.User, resp.CDN)
+	api.WriteRespAlertObj(w, r, tc.SuccessLevel, alertMsg, resp)

Review comment:
       `traffic_ops/traffic_ops_golang/acme/acme_account.go`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r578021619



##########
File path: docs/source/api/v4/cdns_id_notification.rst
##########
@@ -0,0 +1,123 @@
+..
+..
+.. 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-cdns-id-notification:
+
+****************************
+``cdns/{{ID}}/notification``

Review comment:
       Also, instead of ID did you consider using the Name instead? It's just much easier for humans to use

##########
File path: docs/source/api/v4/cdns_id_notification.rst
##########
@@ -0,0 +1,123 @@
+..
+..
+.. 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-cdns-id-notification:
+
+****************************
+``cdns/{{ID}}/notification``
+****************************
+
+``POST``
+========
+Create a notification for a specific CDN.
+
+:Auth. Required: Yes
+:Roles Required: "admin" or "operations"
+:Response Type:  Object
+
+Request Structure
+-----------------
+.. table:: Request Path Parameters
+
+	+------+-------------------------------------------------------------------------------+
+	| Name | Description                                                                   |
+	+======+===============================================================================+
+	| ID   | The integral, unique identifier for the CDN on which to create a notification.|
+	+------+-------------------------------------------------------------------------------+
+
+:notification: The content of the CDN notification
+
+.. code-block:: http
+	:caption: Request Example
+
+	POST /api/4.0/cdns/2/notification HTTP/1.1
+	Host: trafficops.infra.ciab.test
+	User-Agent: curl/7.47.0
+	Accept: */*
+	Cookie: mojolicious=...
+	Content-Length: 19
+	Content-Type: application/json
+
+	{"notification": "No changes to Traffic Ops over the weekend."}
+
+Response Structure
+------------------
+:cdnId:			The integral, unique identifier for the CDN on which :term:`Queue Updates` was performed or cleared
+:notification:	The notification added to the CDN
+:username:		The username of the user responsible for creating the CDN notification
+
+.. 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-Type: application/json
+	Set-Cookie: mojolicious=...; Path=/; Expires=Mon, 18 Nov 2019 17:40:54 GMT; Max-Age=3600; HttpOnly
+	Whole-Content-Sha512: rBpFfrrP+9IFkwsRloEM+v+I8MuBZDXqFu+WUTGtRGypnAn2gHooPoNQRyVvJGjyIQrLXLvqjEtve+lH2Tj4uw==
+	X-Server-Name: traffic_ops_golang/
+	Date: Wed, 14 Nov 2018 21:02:07 GMT
+	Content-Length: 41
+
+	{ "response": {
+		"cdnId": 2,

Review comment:
       I have to know the CDN ID to call this endpoint, I'm not sure I need this in the response

##########
File path: docs/source/api/v4/cdns_id_notification.rst
##########
@@ -0,0 +1,123 @@
+..
+..
+.. 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-cdns-id-notification:
+
+****************************
+``cdns/{{ID}}/notification``

Review comment:
       Can you not GET the notification?
   
   From [the API guidelines](https://traffic-control-cdn.readthedocs.io/en/latest/development/api_guidelines.html#get):
   
   > _"All endpoints dealing with the manipulation or fetching representations of “Traffic Control Objects” MUST support this method."_




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r582473857



##########
File path: lib/go-tc/cdn_notification.go
##########
@@ -0,0 +1,58 @@
+package tc
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+
+	"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
+	"github.com/apache/trafficcontrol/lib/go-util"
+
+	"github.com/go-ozzo/ozzo-validation"
+)
+
+// CDNNotificationsResponse is a list of CDN notifications as a response.
+type CDNNotificationsResponse struct {
+	Response []CDNNotification `json:"response"`
+	Alerts
+}
+
+// CDNNotificationRequest encodes the request data for the POST
+// cdn_notifications endpoint.
+type CDNNotificationRequest struct {
+	CDN          string `json:"cdn"`
+	Notification string `json:"notification"`
+}
+
+// CDNNotification is a notification created for a specific CDN
+type CDNNotification struct {
+	CDN          *string    `json:"cdn" db:"cdn"`

Review comment:
       no, can't be null. so just remove the pointer?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r583764036



##########
File path: traffic_ops/traffic_ops_golang/routing/routes.go
##########
@@ -355,6 +356,11 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
 		{api.Version{4, 0}, http.MethodPost, `coordinates/?$`, api.CreateHandler(&coordinate.TOCoordinate{}), auth.PrivLevelOperations, Authenticated, nil, 44281121573},
 		{api.Version{4, 0}, http.MethodDelete, `coordinates/?$`, api.DeleteHandler(&coordinate.TOCoordinate{}), auth.PrivLevelOperations, Authenticated, nil, 43038498893},
 
+		//CDN notification
+		{api.Version{4, 0}, http.MethodGet, `cdn_notifications/?$`, cdnnotification.Read, auth.PrivLevelReadOnly, Authenticated, nil, 2221224514},
+		{api.Version{4, 0}, http.MethodPost, `cdn_notifications`, cdnnotification.Create, auth.PrivLevelOperations, Authenticated, nil, 2765223513},

Review comment:
       This one can't end with a `/`? why not? Should be anchored with a `$` either way - we've had that introduce weird bugs in the past when that wasn't done.

##########
File path: traffic_ops/traffic_ops_golang/cdnnotification/cdnnotifications.go
##########
@@ -0,0 +1,191 @@
+package cdnnotification
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+	"errors"
+	"fmt"
+	"net/http"
+
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/lib/go-util"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+)
+
+const readQuery = `
+SELECT cn.cdn, 
+	cn.last_updated,
+	cn.user, 
+	cn.notification 
+FROM cdn_notification as cn
+INNER JOIN cdn ON cdn.name = cn.cdn
+INNER JOIN tm_user ON tm_user.username = cn.user
+`
+
+const insertQuery = `
+INSERT INTO cdn_notification (cdn, "user", notification)
+VALUES ($1, $2, $3)
+RETURNING cdn_notification.cdn,
+          cdn_notification.last_updated,
+          cdn_notification.user,
+          cdn_notification.notification
+`
+
+const deleteQuery = `
+DELETE FROM cdn_notification
+WHERE cdn_notification.cdn = $1
+RETURNING cdn_notification.cdn,
+          cdn_notification.last_updated,
+          cdn_notification.user,
+          cdn_notification.notification
+`
+
+// Read is the handler for GET requests to /cdn_notifications.
+func Read(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	tx := inf.Tx.Tx
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	cdnNotifications := []tc.CDNNotification{}
+
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cdn":  dbhelpers.WhereColumnInfo{"cdn.name", nil},
+		"user": dbhelpers.WhereColumnInfo{"tm_user.username", nil},
+	}
+
+	where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		sysErr = util.JoinErrs(errs)
+		errCode = http.StatusBadRequest
+		api.HandleErr(w, r, tx, errCode, nil, sysErr)
+		return
+	}
+
+	query := readQuery + where + orderBy + pagination
+	rows, err := inf.Tx.NamedQuery(query, queryValues)
+	if err != nil {
+		userErr, sysErr, errCode = api.ParseDBError(err)
+		if sysErr != nil {
+			sysErr = fmt.Errorf("notification read query: %v", sysErr)
+		}
+
+		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+		return
+	}
+	defer rows.Close()
+
+	for rows.Next() {
+		var n tc.CDNNotification
+		if err = rows.Scan(&n.CDN, &n.LastUpdated, &n.User, &n.Notification); err != nil {
+			api.HandleErr(w, r, tx, http.StatusInternalServerError, nil, errors.New("scanning cdn notifications: "+err.Error()))
+			return
+		}
+		cdnNotifications = append(cdnNotifications, n)
+	}
+
+	api.WriteResp(w, r, cdnNotifications)
+}
+
+// Create is the handler for POST requests to /cdn_notifications.
+func Create(w http.ResponseWriter, r *http.Request) {
+	inf, sysErr, userErr, errCode := api.NewInfo(r, nil, nil)
+	tx := inf.Tx.Tx
+	if sysErr != nil || userErr != nil {
+		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	var req tc.CDNNotificationRequest
+	if userErr = api.Parse(r.Body, tx, &req); userErr != nil {
+		api.HandleErr(w, r, tx, http.StatusBadRequest, userErr, nil)
+		return
+	}
+
+	var resp tc.CDNNotification
+	err := tx.QueryRow(insertQuery, req.CDN, inf.User.UserName, req.Notification).Scan(&resp.CDN, &resp.LastUpdated, &resp.User, &resp.Notification)
+	if err != nil {
+		userErr, sysErr, errCode = api.ParseDBError(err)
+		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+		return
+	}
+
+	changeLogMsg := fmt.Sprintf("CDN_NOTIFICATION: %s, CDN: %s, ACTION: Created", *resp.Notification, resp.CDN)
+	api.CreateChangeLogRawTx(api.ApiChange, changeLogMsg, inf.User, tx)
+
+	alertMsg := fmt.Sprintf("CDN notification created [ User = %s ] for CDN: %s", resp.User, resp.CDN)
+	api.WriteRespAlertObj(w, r, tc.SuccessLevel, alertMsg, resp)

Review comment:
       creation should use a `201 Created` response code and ideally set a `Location` header with to a request path where the new object representation can be fetched.

##########
File path: lib/go-tc/cdn_notification.go
##########
@@ -0,0 +1,59 @@
+package tc
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+	"time"
+
+	"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
+	"github.com/apache/trafficcontrol/lib/go-util"
+
+	"github.com/go-ozzo/ozzo-validation"
+)
+
+// CDNNotificationsResponse is a list of CDN notifications as a response.
+type CDNNotificationsResponse struct {
+	Response []CDNNotification `json:"response"`
+	Alerts
+}
+
+// CDNNotificationRequest encodes the request data for the POST
+// cdn_notifications endpoint.
+type CDNNotificationRequest struct {
+	CDN          string `json:"cdn"`
+	Notification string `json:"notification"`
+}
+
+// CDNNotification is a notification created for a specific CDN

Review comment:
       GoDoc should end with a period

##########
File path: traffic_ops/v4-client/cdn_notifications.go
##########
@@ -0,0 +1,50 @@
+/*
+
+   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.
+*/
+
+package client
+
+import (
+	"fmt"
+	"net/http"
+
+	"github.com/apache/trafficcontrol/lib/go-tc"
+)
+
+const (
+	API_CDN_NOTIFICATIONS = apiBase + "/cdn_notifications"
+)
+
+// GetCDNNotificationsWithHdr returns a list of CDN Notifications.
+func (to *Session) GetCDNNotificationsWithHdr(cdnName string, header http.Header) ([]tc.CDNNotification, ReqInf, error) {
+	var data tc.CDNNotificationsResponse
+	route := fmt.Sprintf("%s?cdn=%s", API_CDN_NOTIFICATIONS, cdnName)
+	reqInf, err := to.get(route, header, &data)
+	return data.Response, reqInf, err
+}
+
+// CreateCDNNotification creates a CDN notification.
+func (to *Session) CreateCDNNotification(notification tc.CDNNotificationRequest) (tc.Alerts, ReqInf, error) {
+	var alerts tc.Alerts
+	reqInf, err := to.post(API_CDN_NOTIFICATIONS, notification, nil, &alerts)
+	return alerts, reqInf, err
+}
+
+// DeleteCDNNotification deletes a CDN Notification by CDN name.
+func (to *Session) DeleteCDNNotification(cdnName string) (tc.Alerts, ReqInf, error) {
+	route := fmt.Sprintf("%s?cdn=%s", API_CDN_NOTIFICATIONS, cdnName)

Review comment:
       cdnName should be properly encoded. I think `net/url` exports some way to do that besides putting it in a `Values` and using its `Encode` method, but I can't remember for sure.

##########
File path: traffic_ops/v4-client/cdn_notifications.go
##########
@@ -0,0 +1,50 @@
+/*
+
+   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.
+*/
+
+package client
+
+import (
+	"fmt"
+	"net/http"
+
+	"github.com/apache/trafficcontrol/lib/go-tc"
+)
+
+const (
+	API_CDN_NOTIFICATIONS = apiBase + "/cdn_notifications"
+)
+
+// GetCDNNotificationsWithHdr returns a list of CDN Notifications.
+func (to *Session) GetCDNNotificationsWithHdr(cdnName string, header http.Header) ([]tc.CDNNotification, ReqInf, error) {

Review comment:
       This doesn't need to include `WithHdr` - there's no alternative without a header. You might also consider just allowing a `net/url.Values` instead of `cdnName`, so that the endpoint's full functionality is exposed, including pagination and sorting.

##########
File path: traffic_ops/v4-client/cdn_notifications.go
##########
@@ -0,0 +1,50 @@
+/*
+
+   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.
+*/
+
+package client
+
+import (
+	"fmt"
+	"net/http"
+
+	"github.com/apache/trafficcontrol/lib/go-tc"
+)
+
+const (
+	API_CDN_NOTIFICATIONS = apiBase + "/cdn_notifications"
+)
+
+// GetCDNNotificationsWithHdr returns a list of CDN Notifications.
+func (to *Session) GetCDNNotificationsWithHdr(cdnName string, header http.Header) ([]tc.CDNNotification, ReqInf, error) {
+	var data tc.CDNNotificationsResponse
+	route := fmt.Sprintf("%s?cdn=%s", API_CDN_NOTIFICATIONS, cdnName)

Review comment:
       This also needs to be encoded




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] jhg03a commented on pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
jhg03a commented on pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#issuecomment-781704205


   Unless the lack of those fields in POST/PUT cause TO to reject the request.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r578081458



##########
File path: docs/source/api/v4/cdns_id_notification.rst
##########
@@ -0,0 +1,123 @@
+..
+..
+.. 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-cdns-id-notification:
+
+****************************
+``cdns/{{ID}}/notification``

Review comment:
       yeah, you're right. name is probably a better option. i was just following the pattern but it looks like there is a pattern for both id _and_ name :)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r582457937



##########
File path: traffic_portal/app/src/common/modules/form/cdn/FormCDNController.js
##########
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-var FormCDNController = function(cdn, $scope, $location, $uibModal, formUtils, stringUtils, locationUtils, cdnService) {
+var FormCDNController = function(cdn, $scope, $location, $state, $uibModal, formUtils, stringUtils, locationUtils, cdnService, messageModel) {

Review comment:
       i'll check




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r578780646



##########
File path: traffic_portal/app/src/common/modules/notifications/notifications.tpl.html
##########
@@ -0,0 +1,24 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+-->
+
+<div id="notificationsContainer">
+    <div ng-show="cdn.notificationCreatedBy" class="alert alert-info" ng-repeat="cdn in cdns">
+        <div ng-bind-html="cdn.name + ': ' + cdn.notification + ' (' + cdn.notificationCreatedBy + ')' | linky:'_blank'"></div>

Review comment:
       Is that safe? I think using invalidated user input to provide functionality like this could technically be an XSS vulnerability (is "XSS" appropriate here? Not sure)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] rawlinp commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
rawlinp commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r583071665



##########
File path: traffic_ops/v4-client/cdn_notifications.go
##########
@@ -0,0 +1,49 @@
+/*
+
+   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.
+*/
+
+package client
+
+import (
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"net/http"
+)
+
+const (
+	API_CDN_NOTIFICATIONS = apiBase + "/cdn_notifications"

Review comment:
       FYI the client changes here will need to be updated once https://github.com/apache/trafficcontrol/pull/5552 is merged. That PR replaces all the snake casing w/ more "Go idiomatic" casing -- e.g. `APICDNNotifications`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r578807190



##########
File path: traffic_portal/app/src/common/modules/notifications/notifications.tpl.html
##########
@@ -0,0 +1,24 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+-->
+
+<div id="notificationsContainer">
+    <div ng-show="cdn.notificationCreatedBy" class="alert alert-info" ng-repeat="cdn in cdns">
+        <div ng-bind-html="cdn.name + ': ' + cdn.notification + ' (' + cdn.notificationCreatedBy + ')' | linky:'_blank'"></div>

Review comment:
       https://docs.angularjs.org/api/ngSanitize/filter/linky
   
   ```
   Requires the ngSanitize module to be installed.
   ```
   
   I think we're good :)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r583795398



##########
File path: traffic_ops/traffic_ops_golang/routing/routes.go
##########
@@ -355,6 +356,11 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
 		{api.Version{4, 0}, http.MethodPost, `coordinates/?$`, api.CreateHandler(&coordinate.TOCoordinate{}), auth.PrivLevelOperations, Authenticated, nil, 44281121573},
 		{api.Version{4, 0}, http.MethodDelete, `coordinates/?$`, api.DeleteHandler(&coordinate.TOCoordinate{}), auth.PrivLevelOperations, Authenticated, nil, 43038498893},
 
+		//CDN notification
+		{api.Version{4, 0}, http.MethodGet, `cdn_notifications/?$`, cdnnotification.Read, auth.PrivLevelReadOnly, Authenticated, nil, 2221224514},
+		{api.Version{4, 0}, http.MethodPost, `cdn_notifications`, cdnnotification.Create, auth.PrivLevelOperations, Authenticated, nil, 2765223513},

Review comment:
       what _should_ it look like?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#issuecomment-781684894


   Doesn't that technically require a minor version bump for each?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r578764303



##########
File path: traffic_portal/app/src/common/modules/notifications/notifications.tpl.html
##########
@@ -0,0 +1,24 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+-->
+
+<div id="notificationsContainer">
+    <div ng-show="cdn.notificationCreatedBy" class="alert alert-info" ng-repeat="cdn in cdns">
+        <div ng-bind-html="cdn.name + ': ' + cdn.notification + ' (' + cdn.notificationCreatedBy + ')' | linky:'_blank'"></div>

Review comment:
       converts urls to links. i.e. you can have a notification like this:
   
   ```
   Please go to http://www.website.com for more information
   ```
   
   and it will turn that into a link.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r582439148



##########
File path: docs/source/api/v4/cdn_notifications.rst
##########
@@ -0,0 +1,201 @@
+..
+..
+.. 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-cdn-notifications:
+
+*********************
+``cdn_notifications``
+*********************
+
+``GET``
+=======
+List all CDN notifications.
+
+:Auth. Required: Yes
+:Roles Required: Read-Only
+:Response Type:  Array
+
+Request Structure
+-----------------
+.. table:: Request Query Parameters
+
+	+------------+----------+-----------------------------------------------------------------------------------------------------+
+	| Parameter  | Required | Description                                                                                         |
+	+============+==========+=====================================================================================================+
+	| cdn        | no       | The CDN name of the notification you wish to retrieve.                                              |
+	+------------+----------+-----------------------------------------------------------------------------------------------------+
+	| user       | no       | The username of the user responsible for creating the CDN notification.                             |
+	+------------+----------+-----------------------------------------------------------------------------------------------------+
+
+.. code-block:: http
+	:caption: Request Example
+
+	GET /api/4.0/cdn_notifications HTTP/1.1
+	User-Agent: python-requests/2.22.0
+	Accept-Encoding: gzip, deflate
+	Accept: */*
+	Connection: keep-alive
+	Cookie: mojolicious=...
+
+Response Structure
+------------------
+:cdn:			The name of the CDN to which the notification belongs to
+:lastUpdated:	The time and date this server entry was last updated in an ISO-like format
+:notification:	The content of the notification
+:user:			The user responsible for creating the notification
+
+.. 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=Mon, 02 Dec 2019 22:51:14 GMT; Max-Age=3600; HttpOnly
+	Whole-Content-Sha512: F2NmDbTpXqrIQDX7IBKH9+1drtTL4XedSfJv6klMgLEZwbLCkddIXuSLpmgVCID6kTVqy3fTKjZS3U+HJ3YUEQ==
+	X-Server-Name: traffic_ops_golang/
+	Date: Mon, 02 Dec 2019 21:51:14 GMT
+	Content-Length: 128
+
+	{ "response": [
+		{
+			"cdn": "cdn1",
+			"lastUpdated": "2019-12-02 21:49:08+00",
+			"notification": "the content of the notification",
+			"user": "username123",
+		}
+	]}
+
+``POST``
+========
+Creates a notification for a specific CDN.
+
+.. note:: Currently only one notification per CDN is supported.
+
+:Auth. Required:	Yes
+:Roles Required:	"admin" or "operations"
+:Response Type:		Object
+
+Request Structure
+-----------------
+:cdn:			The name of the CDN to which the notification shall belong
+:notification:	The content of the notification
+
+.. code-block:: http
+	:caption: Request Example
+
+	POST /api/4.0/cdn_notifications HTTP/1.1
+	User-Agent: python-requests/2.22.0
+	Accept-Encoding: gzip, deflate
+	Accept: */*
+	Connection: keep-alive
+	Cookie: mojolicious=...
+	Content-Length: 29
+
+	{"cdn": "cdn1", "notification": "the content of the notification"}
+
+
+Response Structure
+------------------
+:cdn:			The name of the CDN to which the notification belongs to
+:lastUpdated:	The time and date this server entry was last updated in an ISO-like format
+:notification:	The content of the notification
+:user:			The user responsible for creating the notification
+
+
+.. 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=Mon, 02 Dec 2019 22:49:08 GMT; Max-Age=3600; HttpOnly
+	Whole-Content-Sha512: mx8b2GTYojz4QtMxXCMoQyZogCB504vs0yv6WGly4dwM81W3XiejWNuUwchRBYYi8QHaWsMZ3DaiGGfQi/8Giw==
+	X-Server-Name: traffic_ops_golang/
+	Date: Mon, 02 Dec 2019 21:49:08 GMT
+	Content-Length: 150
+
+	{ "alerts": [
+		{
+			"text": "notification was created.",
+			"level": "success"
+		}
+	],
+	"response": {
+		"cdn": "cdn1",
+		"lastUpdated": "2019-12-02 21:49:08+00",
+		"notification": "the content of the notification",
+		"user": "username123",
+	}
+}

Review comment:
       This closing brace needs to be indented. Or probably just at the end of the previous line.

##########
File path: lib/go-tc/cdn_notification.go
##########
@@ -0,0 +1,58 @@
+package tc
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+
+	"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
+	"github.com/apache/trafficcontrol/lib/go-util"
+
+	"github.com/go-ozzo/ozzo-validation"
+)
+
+// CDNNotificationsResponse is a list of CDN notifications as a response.
+type CDNNotificationsResponse struct {
+	Response []CDNNotification `json:"response"`
+	Alerts
+}
+
+// CDNNotificationRequest encodes the request data for the POST
+// cdn_notifications endpoint.
+type CDNNotificationRequest struct {
+	CDN          string `json:"cdn"`
+	Notification string `json:"notification"`
+}
+
+// CDNNotification is a notification created for a specific CDN
+type CDNNotification struct {
+	CDN          *string    `json:"cdn" db:"cdn"`

Review comment:
       Is this allowed to be `null`?

##########
File path: docs/source/api/v4/cdn_notifications.rst
##########
@@ -0,0 +1,201 @@
+..
+..
+.. 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-cdn-notifications:
+
+*********************
+``cdn_notifications``
+*********************
+
+``GET``
+=======
+List all CDN notifications.
+
+:Auth. Required: Yes
+:Roles Required: Read-Only
+:Response Type:  Array
+
+Request Structure
+-----------------
+.. table:: Request Query Parameters
+
+	+------------+----------+-----------------------------------------------------------------------------------------------------+
+	| Parameter  | Required | Description                                                                                         |
+	+============+==========+=====================================================================================================+
+	| cdn        | no       | The CDN name of the notification you wish to retrieve.                                              |
+	+------------+----------+-----------------------------------------------------------------------------------------------------+
+	| user       | no       | The username of the user responsible for creating the CDN notification.                             |
+	+------------+----------+-----------------------------------------------------------------------------------------------------+
+
+.. code-block:: http
+	:caption: Request Example
+
+	GET /api/4.0/cdn_notifications HTTP/1.1
+	User-Agent: python-requests/2.22.0
+	Accept-Encoding: gzip, deflate
+	Accept: */*
+	Connection: keep-alive
+	Cookie: mojolicious=...
+
+Response Structure
+------------------
+:cdn:			The name of the CDN to which the notification belongs to
+:lastUpdated:	The time and date this server entry was last updated in an ISO-like format
+:notification:	The content of the notification
+:user:			The user responsible for creating the notification
+
+.. 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=Mon, 02 Dec 2019 22:51:14 GMT; Max-Age=3600; HttpOnly
+	Whole-Content-Sha512: F2NmDbTpXqrIQDX7IBKH9+1drtTL4XedSfJv6klMgLEZwbLCkddIXuSLpmgVCID6kTVqy3fTKjZS3U+HJ3YUEQ==
+	X-Server-Name: traffic_ops_golang/
+	Date: Mon, 02 Dec 2019 21:51:14 GMT
+	Content-Length: 128
+
+	{ "response": [
+		{
+			"cdn": "cdn1",
+			"lastUpdated": "2019-12-02 21:49:08+00",
+			"notification": "the content of the notification",
+			"user": "username123",
+		}
+	]}
+
+``POST``
+========
+Creates a notification for a specific CDN.
+
+.. note:: Currently only one notification per CDN is supported.
+
+:Auth. Required:	Yes
+:Roles Required:	"admin" or "operations"
+:Response Type:		Object
+
+Request Structure
+-----------------
+:cdn:			The name of the CDN to which the notification shall belong

Review comment:
       I don't think it's actually a problem, but there's a lot of weird whitespace between these field properties and their values. Looks like a tab character or three.

##########
File path: docs/source/api/v4/cdn_notifications.rst
##########
@@ -0,0 +1,201 @@
+..
+..
+.. 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-cdn-notifications:
+
+*********************
+``cdn_notifications``
+*********************
+
+``GET``
+=======
+List all CDN notifications.
+
+:Auth. Required: Yes
+:Roles Required: Read-Only
+:Response Type:  Array
+
+Request Structure
+-----------------
+.. table:: Request Query Parameters
+
+	+------------+----------+-----------------------------------------------------------------------------------------------------+
+	| Parameter  | Required | Description                                                                                         |
+	+============+==========+=====================================================================================================+
+	| cdn        | no       | The CDN name of the notification you wish to retrieve.                                              |
+	+------------+----------+-----------------------------------------------------------------------------------------------------+
+	| user       | no       | The username of the user responsible for creating the CDN notification.                             |
+	+------------+----------+-----------------------------------------------------------------------------------------------------+
+
+.. code-block:: http
+	:caption: Request Example
+
+	GET /api/4.0/cdn_notifications HTTP/1.1
+	User-Agent: python-requests/2.22.0
+	Accept-Encoding: gzip, deflate
+	Accept: */*
+	Connection: keep-alive
+	Cookie: mojolicious=...
+
+Response Structure
+------------------
+:cdn:			The name of the CDN to which the notification belongs to
+:lastUpdated:	The time and date this server entry was last updated in an ISO-like format
+:notification:	The content of the notification
+:user:			The user responsible for creating the notification
+
+.. 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=Mon, 02 Dec 2019 22:51:14 GMT; Max-Age=3600; HttpOnly
+	Whole-Content-Sha512: F2NmDbTpXqrIQDX7IBKH9+1drtTL4XedSfJv6klMgLEZwbLCkddIXuSLpmgVCID6kTVqy3fTKjZS3U+HJ3YUEQ==
+	X-Server-Name: traffic_ops_golang/
+	Date: Mon, 02 Dec 2019 21:51:14 GMT
+	Content-Length: 128
+
+	{ "response": [
+		{
+			"cdn": "cdn1",
+			"lastUpdated": "2019-12-02 21:49:08+00",
+			"notification": "the content of the notification",
+			"user": "username123",
+		}
+	]}
+
+``POST``
+========
+Creates a notification for a specific CDN.
+
+.. note:: Currently only one notification per CDN is supported.
+
+:Auth. Required:	Yes
+:Roles Required:	"admin" or "operations"
+:Response Type:		Object
+
+Request Structure
+-----------------
+:cdn:			The name of the CDN to which the notification shall belong
+:notification:	The content of the notification
+
+.. code-block:: http
+	:caption: Request Example
+
+	POST /api/4.0/cdn_notifications HTTP/1.1
+	User-Agent: python-requests/2.22.0
+	Accept-Encoding: gzip, deflate
+	Accept: */*
+	Connection: keep-alive
+	Cookie: mojolicious=...
+	Content-Length: 29
+
+	{"cdn": "cdn1", "notification": "the content of the notification"}
+
+
+Response Structure
+------------------
+:cdn:			The name of the CDN to which the notification belongs to
+:lastUpdated:	The time and date this server entry was last updated in an ISO-like format
+:notification:	The content of the notification
+:user:			The user responsible for creating the notification
+
+
+.. 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=Mon, 02 Dec 2019 22:49:08 GMT; Max-Age=3600; HttpOnly
+	Whole-Content-Sha512: mx8b2GTYojz4QtMxXCMoQyZogCB504vs0yv6WGly4dwM81W3XiejWNuUwchRBYYi8QHaWsMZ3DaiGGfQi/8Giw==
+	X-Server-Name: traffic_ops_golang/
+	Date: Mon, 02 Dec 2019 21:49:08 GMT
+	Content-Length: 150
+
+	{ "alerts": [
+		{
+			"text": "notification was created.",
+			"level": "success"
+		}
+	],
+	"response": {
+		"cdn": "cdn1",
+		"lastUpdated": "2019-12-02 21:49:08+00",
+		"notification": "the content of the notification",
+		"user": "username123",
+	}
+}
+
+
+``DELETE``
+----------
+Deletes an existing CDN notification.
+
+:Auth. Required: Yes
+:Roles Required: "admin" or "operations"
+:Response Type: ``undefined``
+
+Request Structure
+-----------------
+
+.. code-block:: http
+	:caption: Request Example
+
+	DELETE /api/4.0/cdn_notifications?cdn=cdn1 HTTP/1.1

Review comment:
       Looks like an undocumented, required query parameter here.

##########
File path: traffic_ops/traffic_ops_golang/cdnnotification/cdnnotifications.go
##########
@@ -0,0 +1,190 @@
+package cdnnotification
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+	"errors"
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-util"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+	"net/http"
+
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"

Review comment:
       project-internal imports should be grouped beneath standard library imports

##########
File path: lib/go-tc/cdn_notification.go
##########
@@ -0,0 +1,58 @@
+package tc
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+
+	"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
+	"github.com/apache/trafficcontrol/lib/go-util"
+
+	"github.com/go-ozzo/ozzo-validation"
+)
+
+// CDNNotificationsResponse is a list of CDN notifications as a response.
+type CDNNotificationsResponse struct {
+	Response []CDNNotification `json:"response"`
+	Alerts
+}
+
+// CDNNotificationRequest encodes the request data for the POST
+// cdn_notifications endpoint.
+type CDNNotificationRequest struct {
+	CDN          string `json:"cdn"`
+	Notification string `json:"notification"`
+}
+
+// CDNNotification is a notification created for a specific CDN
+type CDNNotification struct {
+	CDN          *string    `json:"cdn" db:"cdn"`
+	LastUpdated  *TimeNoMod `json:"lastUpdated" db:"last_updated"`

Review comment:
       Can we stop using `TimeNoMod`? If you just use `time.Time` it'll automatically use RFC3339, which is a lot easier to deal with.

##########
File path: traffic_portal/app/src/common/modules/header/HeaderController.js
##########
@@ -64,6 +78,68 @@ var HeaderController = function($rootScope, $scope, $state, $uibModal, $location
         trafficPortalService.dbDump();
     };
 
+    $scope.toggleNotification = function(cdn) {
+        if (cdn.notificationCreatedBy) {
+            confirmDeleteNotification(cdn);
+        } else {
+            confirmCreateNotification(cdn);
+        }
+    };
+
+    let confirmCreateNotification = function(cdn) {
+        const params = {
+            title: 'Create Global ' + cdn.name + ' Notification',
+            message: 'What is the content of your global notification for the ' + cdn.name + ' CDN?'
+        };
+        const modalInstance = $uibModal.open({
+            templateUrl: 'common/modules/dialog/input/dialog.input.tpl.html',
+            controller: 'DialogInputController',
+            size: 'md',
+            resolve: {
+                params: function () {
+                    return params;
+                }
+            }
+        });
+        modalInstance.result.then(function(notification) {
+            cdnService.createNotification(cdn, notification).
+                then(
+                    function() {
+                        $rootScope.$broadcast('headerController::notificationCreated');
+                    }
+                );
+        }, function () {
+            // do nothing

Review comment:
       Do you wanna just `console.error` the error?

##########
File path: traffic_ops/v4-client/cdn_notifications.go
##########
@@ -0,0 +1,49 @@
+/*
+
+   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.
+*/
+
+package client
+
+import (
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"net/http"
+)
+
+const (
+	API_CDN_NOTIFICATIONS = apiBase + "/cdn_notifications"

Review comment:
       Can you add a GoDoc to this exported symbol? Or just un-export it, I don't think anything needs it. Although I know (almost) all other client files use this casing for their request paths.

##########
File path: traffic_ops/v4-client/cdn_notifications.go
##########
@@ -0,0 +1,49 @@
+/*
+
+   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.
+*/
+
+package client
+
+import (
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"net/http"
+)
+
+const (
+	API_CDN_NOTIFICATIONS = apiBase + "/cdn_notifications"
+)
+
+// Returns a list of CDN Notifications.

Review comment:
       GoDoc should begin with the name of the documented symbol.

##########
File path: traffic_portal/app/src/common/modules/header/HeaderController.js
##########
@@ -64,6 +78,68 @@ var HeaderController = function($rootScope, $scope, $state, $uibModal, $location
         trafficPortalService.dbDump();
     };
 
+    $scope.toggleNotification = function(cdn) {
+        if (cdn.notificationCreatedBy) {
+            confirmDeleteNotification(cdn);
+        } else {
+            confirmCreateNotification(cdn);
+        }
+    };
+
+    let confirmCreateNotification = function(cdn) {
+        const params = {
+            title: 'Create Global ' + cdn.name + ' Notification',
+            message: 'What is the content of your global notification for the ' + cdn.name + ' CDN?'
+        };
+        const modalInstance = $uibModal.open({
+            templateUrl: 'common/modules/dialog/input/dialog.input.tpl.html',
+            controller: 'DialogInputController',
+            size: 'md',
+            resolve: {
+                params: function () {
+                    return params;
+                }
+            }
+        });
+        modalInstance.result.then(function(notification) {
+            cdnService.createNotification(cdn, notification).
+                then(
+                    function() {
+                        $rootScope.$broadcast('headerController::notificationCreated');
+                    }
+                );
+        }, function () {
+            // do nothing
+        });
+    };
+
+    let confirmDeleteNotification = function(cdn) {
+        const params = {
+            title: 'Delete Global ' + cdn.name + ' Notification',
+            message: 'Are you sure you want to delete the global notification for the ' + cdn.name + ' CDN? This will remove the notification from the view of all users.'
+        };
+        const modalInstance = $uibModal.open({
+            templateUrl: 'common/modules/dialog/confirm/dialog.confirm.tpl.html',
+            controller: 'DialogConfirmController',
+            size: 'md',
+            resolve: {
+                params: function () {
+                    return params;
+                }
+            }
+        });
+        modalInstance.result.then(function() {
+            cdnService.deleteNotification(cdn).
+                then(
+                    function() {
+                        $rootScope.$broadcast('headerController::notificationDeleted');
+                    }
+                );
+        }, function () {
+            // do nothing

Review comment:
       Same as above RE: `console.error`

##########
File path: traffic_portal/app/src/common/modules/header/header.tpl.html
##########
@@ -40,7 +40,7 @@
             <li role="presentation" class="dropdown" ng-if="hasCapability('change-logs-read')">
                 <div class="btn-group" title="Change Logs" uib-dropdown is-open="alerts.isopen">
                     <button id="alertsButton" type="button" class="btn btn-link" ng-click="getChangeLogs()" uib-dropdown-toggle>
-                        <i class="fa fa-comment-o"></i>
+                        <i class="fa" ng-class="{ 'fa-comment': newLogCount() > 0, 'fa-comment-o': newLogCount() == 0 }"></i>

Review comment:
       `ng-class` supports expresions that evaluate to strings and arrays of strings as well as object property mappings. What I'm getting at is I think it's simpler - and calls `newLogCount` less times - to use `ng-class="{ newLogCount() > 0 ? 'fa-comment' : 'fa-comment-o'}"`

##########
File path: traffic_ops/traffic_ops_golang/routing/routes.go
##########
@@ -23,6 +23,7 @@ import (
 	"encoding/json"
 	"errors"
 	"fmt"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/cdnnotification"

Review comment:
       project-local imports should be grouped beneath standard library imports

##########
File path: lib/go-tc/cdn_notification.go
##########
@@ -0,0 +1,58 @@
+package tc
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+
+	"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
+	"github.com/apache/trafficcontrol/lib/go-util"
+
+	"github.com/go-ozzo/ozzo-validation"
+)
+
+// CDNNotificationsResponse is a list of CDN notifications as a response.
+type CDNNotificationsResponse struct {
+	Response []CDNNotification `json:"response"`
+	Alerts
+}
+
+// CDNNotificationRequest encodes the request data for the POST
+// cdn_notifications endpoint.
+type CDNNotificationRequest struct {
+	CDN          string `json:"cdn"`
+	Notification string `json:"notification"`
+}
+
+// CDNNotification is a notification created for a specific CDN
+type CDNNotification struct {
+	CDN          *string    `json:"cdn" db:"cdn"`
+	LastUpdated  *TimeNoMod `json:"lastUpdated" db:"last_updated"`
+	Notification *string    `json:"notification" db:"notification"`
+	User         *string    `json:"user" db:"user"`
+}
+
+// Validate validates the CDNNotification request is valid for creation.
+func (n *CDNNotification) Validate(tx *sql.Tx) error {
+	errs := validation.Errors{
+		"cdn": validation.Validate(n.CDN, validation.Required),
+	}
+	return util.JoinErrs(tovalidate.ToErrors(errs))
+}

Review comment:
       With the recent DS CacheURL removal, we've sort of started putting these into Traffic Ops itself, since it's weird to expose this thing that requires a transaction into the TO database to work.

##########
File path: traffic_ops/v4-client/cdn_notifications.go
##########
@@ -0,0 +1,49 @@
+/*
+
+   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.
+*/
+
+package client
+
+import (
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"net/http"

Review comment:
       project-local imports should be grouped beneath standard library imports

##########
File path: traffic_portal/app/src/common/modules/form/cdn/FormCDNController.js
##########
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-var FormCDNController = function(cdn, $scope, $location, $uibModal, formUtils, stringUtils, locationUtils, cdnService) {
+var FormCDNController = function(cdn, $scope, $location, $state, $uibModal, formUtils, stringUtils, locationUtils, cdnService, messageModel) {

Review comment:
       The only changes I see to this file are adding these  dependency injections and removing a blank line. Does this controller use those injections already, and it was a bug that they weren't being injected?

##########
File path: traffic_portal/app/src/common/api/CDNService.js
##########
@@ -222,7 +222,42 @@ var CDNService = function($http, locationUtils, messageModel, ENV) {
                 throw err;
 			}
 		);
-	};
+	}
+
+    this.getNotifications = function(queryParams) {
+        return $http.get(ENV.api['root'] + 'cdn_notifications', { params: queryParams }).then(
+            function(result) {
+                return result.data.response;
+            },
+            function(err) {
+                throw err;
+            }
+        );
+    };
+
+    this.createNotification = function(cdn, notification) {
+        return $http.post(ENV.api['root'] + 'cdn_notifications', { cdn: cdn.name, notification: notification}).then(
+            function(result) {
+                return result;
+            },
+            function(err) {
+                messageModel.setMessages(err.data.alerts, false);
+                throw err;
+            }
+        );
+    };
+
+    this.deleteNotification = function(cdn) {
+        return $http.delete(ENV.api['root'] + 'cdn_notifications?cdn=' + cdn.name).then(

Review comment:
       You should either pass the `cdn` parameter in the `$http.delete`'s query string parameters optional argument, or use `encodeURIComponent` to ensure proper URI component encoding.

##########
File path: traffic_ops/traffic_ops_golang/cdnnotification/cdnnotifications.go
##########
@@ -0,0 +1,190 @@
+package cdnnotification
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+	"errors"
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-util"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+	"net/http"
+
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+)
+
+const readQuery = `
+SELECT cn.cdn, 
+	cn.last_updated,
+	cn.user, 
+	cn.notification 
+FROM cdn_notification as cn
+INNER JOIN cdn ON cdn.name = cn.cdn
+INNER JOIN tm_user ON tm_user.username = cn.user
+`
+
+const insertQuery = `
+INSERT INTO cdn_notification (cdn, "user", notification)
+VALUES ($1, $2, $3)
+RETURNING cdn_notification.cdn,
+          cdn_notification.last_updated,
+          cdn_notification.user,
+          cdn_notification.notification
+`
+
+const deleteQuery = `
+DELETE FROM cdn_notification
+WHERE cdn_notification.cdn = $1
+RETURNING cdn_notification.cdn,
+          cdn_notification.last_updated,
+          cdn_notification.user,
+          cdn_notification.notification
+`
+
+// Read is the handler for GET requests to /cdn_notifications.
+func Read(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	tx := inf.Tx.Tx
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	cdnNotifications := []tc.CDNNotification{}
+
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cdn":  dbhelpers.WhereColumnInfo{"cdn.name", nil},
+		"user": dbhelpers.WhereColumnInfo{"tm_user.username", nil},
+	}
+
+	where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		sysErr = util.JoinErrs(errs)
+		errCode = http.StatusBadRequest
+		api.HandleErr(w, r, tx, errCode, nil, sysErr)
+		return
+	}
+
+	query := readQuery + where + orderBy + pagination
+	rows, err := inf.Tx.NamedQuery(query, queryValues)
+	if err != nil {
+		userErr, sysErr, errCode = api.ParseDBError(err)
+		if sysErr != nil {
+			sysErr = fmt.Errorf("notification read query: %v", sysErr)
+		}
+
+		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+		return
+	}
+	defer rows.Close()
+
+	for rows.Next() {
+		var n tc.CDNNotification
+		if err = rows.Scan(&n.CDN, &n.LastUpdated, &n.User, &n.Notification); err != nil {
+			api.HandleErr(w, r, tx, http.StatusInternalServerError, nil, errors.New("scanning cdn notifications: "+err.Error()))
+			return
+		}
+		cdnNotifications = append(cdnNotifications, n)
+	}
+
+	api.WriteResp(w, r, cdnNotifications)
+}
+
+// Create is the handler for POST requests to /cdn_notifications.
+func Create(w http.ResponseWriter, r *http.Request) {
+	inf, sysErr, userErr, errCode := api.NewInfo(r, nil, nil)
+	tx := inf.Tx.Tx
+	if sysErr != nil || userErr != nil {
+		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	var n tc.CDNNotification

Review comment:
       Shouldn't this be a `tc.CDNNotificationRequest`? I mean, I think this works since you're using basic `QueryRow`, but I just assume this is the reason you made that struct.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r582459367



##########
File path: traffic_portal/app/src/common/modules/header/header.tpl.html
##########
@@ -40,7 +40,7 @@
             <li role="presentation" class="dropdown" ng-if="hasCapability('change-logs-read')">
                 <div class="btn-group" title="Change Logs" uib-dropdown is-open="alerts.isopen">
                     <button id="alertsButton" type="button" class="btn btn-link" ng-click="getChangeLogs()" uib-dropdown-toggle>
-                        <i class="fa fa-comment-o"></i>
+                        <i class="fa" ng-class="{ 'fa-comment': newLogCount() > 0, 'fa-comment-o': newLogCount() == 0 }"></i>

Review comment:
       yep, that's better




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r578081458



##########
File path: docs/source/api/v4/cdns_id_notification.rst
##########
@@ -0,0 +1,123 @@
+..
+..
+.. 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-cdns-id-notification:
+
+****************************
+``cdns/{{ID}}/notification``

Review comment:
       yeah, you're right. name is probably a better option. i was just following the pattern but it looks like there is a pattern for both methods :)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] rob05c commented on pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
rob05c commented on pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#issuecomment-782218111


   It is not contrived, and it is not misuse by the client. 
   
   Caching is something we have frequently done in the past. ORT has done it, the Monitor has done it. We just implemented IMS and IUS in TO (which does _not_ solve this problem either). TO can only serve so many requests per second, and even if it can network and data is slow.
   
   It's perfectly reasonable for a client to get data, and expect to be able to modify that data and push it back. It's also reasonable to be able to upgrade TO in-place, without breaking ongoing CDN traffic and operational scripts.
   
   Minor versioning in many cases, including this one, makes accidental errors impossible. Yes, the client could willfully ignore the error, like deserializing an older version to a newer struct and then posting that back. That would be misuse. And you're right, we can't prevent intentional bad behavior. But requesting data and posting it back is not misuse, and versioning prevents accidental and unknowable errors. It's not possible to prevent willful bad behavior, but it is possible to prevent accidental mistakes, and make it possible to detect and prevent them.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] rob05c commented on pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
rob05c commented on pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#issuecomment-781712475


   What happens if a new client does a `GET /cdns` from an old TO, silently saves the empty string, and then does a `POST /notifications` with that data (possibly modified) later after TO is upgraded, or maybe to different HA TO?
   
   The client had no way to know the TO was a different version. It's impossible for the client to even know the issue is going to happen, much less prevent it. Because the TO's have the same version, even though they're actually different.
   
   This is one of the fundamental error cases that minor versioning prevents. Giving the same data different GET and POST paths doesn't somehow make that issue not exist. It just confuses it.
   
   I disagree that versioning should only ensure "round trip safety." Versioning prevents clients and servers from breaking for a number of reasons, that's only one of them.
   
   Giving the same data different GET and POST paths doesn't somehow make those errors not happen. 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r583054518



##########
File path: traffic_portal/app/src/common/modules/header/HeaderController.js
##########
@@ -64,6 +78,68 @@ var HeaderController = function($rootScope, $scope, $state, $uibModal, $location
         trafficPortalService.dbDump();
     };
 
+    $scope.toggleNotification = function(cdn) {
+        if (cdn.notificationCreatedBy) {
+            confirmDeleteNotification(cdn);
+        } else {
+            confirmCreateNotification(cdn);
+        }
+    };
+
+    let confirmCreateNotification = function(cdn) {
+        const params = {
+            title: 'Create Global ' + cdn.name + ' Notification',
+            message: 'What is the content of your global notification for the ' + cdn.name + ' CDN?'
+        };
+        const modalInstance = $uibModal.open({
+            templateUrl: 'common/modules/dialog/input/dialog.input.tpl.html',
+            controller: 'DialogInputController',
+            size: 'md',
+            resolve: {
+                params: function () {
+                    return params;
+                }
+            }
+        });
+        modalInstance.result.then(function(notification) {
+            cdnService.createNotification(cdn, notification).
+                then(
+                    function() {
+                        $rootScope.$broadcast('headerController::notificationCreated');
+                    }
+                );
+        }, function () {
+            // do nothing

Review comment:
       Oh, I thought this was related to the `cdnService.createNotification` call. But it is not. Nvm.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r582473857



##########
File path: lib/go-tc/cdn_notification.go
##########
@@ -0,0 +1,58 @@
+package tc
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+
+	"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
+	"github.com/apache/trafficcontrol/lib/go-util"
+
+	"github.com/go-ozzo/ozzo-validation"
+)
+
+// CDNNotificationsResponse is a list of CDN notifications as a response.
+type CDNNotificationsResponse struct {
+	Response []CDNNotification `json:"response"`
+	Alerts
+}
+
+// CDNNotificationRequest encodes the request data for the POST
+// cdn_notifications endpoint.
+type CDNNotificationRequest struct {
+	CDN          string `json:"cdn"`
+	Notification string `json:"notification"`
+}
+
+// CDNNotification is a notification created for a specific CDN
+type CDNNotification struct {
+	CDN          *string    `json:"cdn" db:"cdn"`

Review comment:
       no, can't be null. so just remove the pointer?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r582463413



##########
File path: traffic_ops/v4-client/cdn_notifications.go
##########
@@ -0,0 +1,49 @@
+/*
+
+   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.
+*/
+
+package client
+
+import (
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"net/http"
+)
+
+const (
+	API_CDN_NOTIFICATIONS = apiBase + "/cdn_notifications"

Review comment:
       so api_cdn_notifications instead? sorry, i'm used to constants being uppercase, exported (public) or not (private).




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r578108324



##########
File path: docs/source/api/v4/cdns_id_notification.rst
##########
@@ -0,0 +1,123 @@
+..
+..
+.. 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-cdns-id-notification:
+
+****************************
+``cdns/{{ID}}/notification``
+****************************
+
+``POST``
+========
+Create a notification for a specific CDN.
+
+:Auth. Required: Yes
+:Roles Required: "admin" or "operations"
+:Response Type:  Object
+
+Request Structure
+-----------------
+.. table:: Request Path Parameters
+
+	+------+-------------------------------------------------------------------------------+
+	| Name | Description                                                                   |
+	+======+===============================================================================+
+	| ID   | The integral, unique identifier for the CDN on which to create a notification.|
+	+------+-------------------------------------------------------------------------------+
+
+:notification: The content of the CDN notification
+
+.. code-block:: http
+	:caption: Request Example
+
+	POST /api/4.0/cdns/2/notification HTTP/1.1
+	Host: trafficops.infra.ciab.test
+	User-Agent: curl/7.47.0
+	Accept: */*
+	Cookie: mojolicious=...
+	Content-Length: 19
+	Content-Type: application/json
+
+	{"notification": "No changes to Traffic Ops over the weekend."}
+
+Response Structure
+------------------
+:cdnId:			The integral, unique identifier for the CDN on which :term:`Queue Updates` was performed or cleared
+:notification:	The notification added to the CDN
+:username:		The username of the user responsible for creating the CDN notification
+
+.. 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-Type: application/json
+	Set-Cookie: mojolicious=...; Path=/; Expires=Mon, 18 Nov 2019 17:40:54 GMT; Max-Age=3600; HttpOnly
+	Whole-Content-Sha512: rBpFfrrP+9IFkwsRloEM+v+I8MuBZDXqFu+WUTGtRGypnAn2gHooPoNQRyVvJGjyIQrLXLvqjEtve+lH2Tj4uw==
+	X-Server-Name: traffic_ops_golang/
+	Date: Wed, 14 Nov 2018 21:02:07 GMT
+	Content-Length: 41
+
+	{ "response": {
+		"cdnId": 2,

Review comment:
       gone




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r583056633



##########
File path: traffic_ops/v4-client/cdn_notifications.go
##########
@@ -0,0 +1,49 @@
+/*
+
+   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.
+*/
+
+package client
+
+import (
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"net/http"
+)
+
+const (
+	API_CDN_NOTIFICATIONS = apiBase + "/cdn_notifications"

Review comment:
       Yeah, me too, that's why I casefolded them all to that. But they *will* be exported if we keep doing this, whether that's what we want or not. I think snake_case is ugly, so I'd do `apiCDNNotification`, but `go fmt` won't care either way, so neither do I.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r578727026



##########
File path: docs/source/api/v4/cdns_id_notification.rst
##########
@@ -0,0 +1,123 @@
+..
+..
+.. 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-cdns-id-notification:
+
+****************************
+``cdns/{{ID}}/notification``

Review comment:
       Well by the same token can you not just create a notification by updating the CDN with a PUT?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r583804686



##########
File path: traffic_ops/v4-client/cdn_notifications.go
##########
@@ -0,0 +1,49 @@
+/*
+
+   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.
+*/
+
+package client
+
+import (
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"net/http"
+)
+
+const (
+	API_CDN_NOTIFICATIONS = apiBase + "/cdn_notifications"

Review comment:
       fixing. going to leave out godoc as nowhere else does that.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r582959291



##########
File path: traffic_portal/app/src/common/modules/header/HeaderController.js
##########
@@ -64,6 +78,68 @@ var HeaderController = function($rootScope, $scope, $state, $uibModal, $location
         trafficPortalService.dbDump();
     };
 
+    $scope.toggleNotification = function(cdn) {
+        if (cdn.notificationCreatedBy) {
+            confirmDeleteNotification(cdn);
+        } else {
+            confirmCreateNotification(cdn);
+        }
+    };
+
+    let confirmCreateNotification = function(cdn) {
+        const params = {
+            title: 'Create Global ' + cdn.name + ' Notification',
+            message: 'What is the content of your global notification for the ' + cdn.name + ' CDN?'
+        };
+        const modalInstance = $uibModal.open({
+            templateUrl: 'common/modules/dialog/input/dialog.input.tpl.html',
+            controller: 'DialogInputController',
+            size: 'md',
+            resolve: {
+                params: function () {
+                    return params;
+                }
+            }
+        });
+        modalInstance.result.then(function(notification) {
+            cdnService.createNotification(cdn, notification).
+                then(
+                    function() {
+                        $rootScope.$broadcast('headerController::notificationCreated');
+                    }
+                );
+        }, function () {
+            // do nothing

Review comment:
       oh, this is when you cancel the dialog window. there is no error to throw or log. i mean i could do this:
   
   ```
   console.log('dialog dismissed')
   ```
   
   and i considered that at one time but it pollutes the dev console. if you feel strongly about not doing `do nothing`, maybe we can create an issue to fix this globally?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r578081727



##########
File path: docs/source/api/v4/cdns_id_notification.rst
##########
@@ -0,0 +1,123 @@
+..
+..
+.. 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-cdns-id-notification:
+
+****************************
+``cdns/{{ID}}/notification``

Review comment:
       > Can you not GET the notification?
   
   no, but i can add it




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r578806499



##########
File path: traffic_portal/app/src/common/modules/notifications/notifications.tpl.html
##########
@@ -0,0 +1,24 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+-->
+
+<div id="notificationsContainer">
+    <div ng-show="cdn.notificationCreatedBy" class="alert alert-info" ng-repeat="cdn in cdns">
+        <div ng-bind-html="cdn.name + ': ' + cdn.notification + ' (' + cdn.notificationCreatedBy + ')' | linky:'_blank'"></div>

Review comment:
       not sure. i could remove it i guess but seemed like nice functionality. i'll see if the library does any sanitation.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r582458593



##########
File path: traffic_portal/app/src/common/modules/header/HeaderController.js
##########
@@ -64,6 +78,68 @@ var HeaderController = function($rootScope, $scope, $state, $uibModal, $location
         trafficPortalService.dbDump();
     };
 
+    $scope.toggleNotification = function(cdn) {
+        if (cdn.notificationCreatedBy) {
+            confirmDeleteNotification(cdn);
+        } else {
+            confirmCreateNotification(cdn);
+        }
+    };
+
+    let confirmCreateNotification = function(cdn) {
+        const params = {
+            title: 'Create Global ' + cdn.name + ' Notification',
+            message: 'What is the content of your global notification for the ' + cdn.name + ' CDN?'
+        };
+        const modalInstance = $uibModal.open({
+            templateUrl: 'common/modules/dialog/input/dialog.input.tpl.html',
+            controller: 'DialogInputController',
+            size: 'md',
+            resolve: {
+                params: function () {
+                    return params;
+                }
+            }
+        });
+        modalInstance.result.then(function(notification) {
+            cdnService.createNotification(cdn, notification).
+                then(
+                    function() {
+                        $rootScope.$broadcast('headerController::notificationCreated');
+                    }
+                );
+        }, function () {
+            // do nothing

Review comment:
       sure




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] rawlinp commented on pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
rawlinp commented on pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#issuecomment-781702570


   If `GET /cdns` returns new fields, but you can't use `PUT /cdns` or `POST /cdns` to update/create those fields, I think that might be fine to do without a minor version bump.
   
   IMO minor version bumps are all about "round-trip safety". I.e. can an "old" client do a `GET`, followed by a `PUT` using that response and not accidentally delete any new data fields. If the new data fields are essentially read-only, I don't see a real need for bumping the minor version.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r583804686



##########
File path: traffic_ops/v4-client/cdn_notifications.go
##########
@@ -0,0 +1,49 @@
+/*
+
+   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.
+*/
+
+package client
+
+import (
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"net/http"
+)
+
+const (
+	API_CDN_NOTIFICATIONS = apiBase + "/cdn_notifications"

Review comment:
       fixing casing. going to leave out godoc, however, as nowhere else does that.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r582962597



##########
File path: traffic_portal/app/src/common/modules/header/header.tpl.html
##########
@@ -40,7 +40,7 @@
             <li role="presentation" class="dropdown" ng-if="hasCapability('change-logs-read')">
                 <div class="btn-group" title="Change Logs" uib-dropdown is-open="alerts.isopen">
                     <button id="alertsButton" type="button" class="btn btn-link" ng-click="getChangeLogs()" uib-dropdown-toggle>
-                        <i class="fa fa-comment-o"></i>
+                        <i class="fa" ng-class="{ 'fa-comment': newLogCount() > 0, 'fa-comment-o': newLogCount() == 0 }"></i>

Review comment:
       unfortunately this syntax is not welcome so i'll just leave it as is
   
   ```
   <i class="fa" ng-class="{ newLogCount() &gt 0 ? 'fa-comment' : 'fa-comment-o'}"></i>
   ```

##########
File path: traffic_portal/app/src/common/modules/header/header.tpl.html
##########
@@ -40,7 +40,7 @@
             <li role="presentation" class="dropdown" ng-if="hasCapability('change-logs-read')">
                 <div class="btn-group" title="Change Logs" uib-dropdown is-open="alerts.isopen">
                     <button id="alertsButton" type="button" class="btn btn-link" ng-click="getChangeLogs()" uib-dropdown-toggle>
-                        <i class="fa fa-comment-o"></i>
+                        <i class="fa" ng-class="{ 'fa-comment': newLogCount() > 0, 'fa-comment-o': newLogCount() == 0 }"></i>

Review comment:
       unfortunately this syntax is not welcome so i'll just leave it as is
   
   ```
   <i class="fa" ng-class="{ newLogCount() > 0 ? 'fa-comment' : 'fa-comment-o'}"></i>
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r583063646



##########
File path: traffic_ops/traffic_ops_golang/cdnnotification/cdnnotifications.go
##########
@@ -0,0 +1,190 @@
+package cdnnotification
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+	"errors"
+	"fmt"
+	"github.com/apache/trafficcontrol/lib/go-util"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+	"net/http"
+
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+)
+
+const readQuery = `
+SELECT cn.cdn, 
+	cn.last_updated,
+	cn.user, 
+	cn.notification 
+FROM cdn_notification as cn
+INNER JOIN cdn ON cdn.name = cn.cdn
+INNER JOIN tm_user ON tm_user.username = cn.user
+`
+
+const insertQuery = `
+INSERT INTO cdn_notification (cdn, "user", notification)
+VALUES ($1, $2, $3)
+RETURNING cdn_notification.cdn,
+          cdn_notification.last_updated,
+          cdn_notification.user,
+          cdn_notification.notification
+`
+
+const deleteQuery = `
+DELETE FROM cdn_notification
+WHERE cdn_notification.cdn = $1
+RETURNING cdn_notification.cdn,
+          cdn_notification.last_updated,
+          cdn_notification.user,
+          cdn_notification.notification
+`
+
+// Read is the handler for GET requests to /cdn_notifications.
+func Read(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	tx := inf.Tx.Tx
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	cdnNotifications := []tc.CDNNotification{}
+
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cdn":  dbhelpers.WhereColumnInfo{"cdn.name", nil},
+		"user": dbhelpers.WhereColumnInfo{"tm_user.username", nil},
+	}
+
+	where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		sysErr = util.JoinErrs(errs)
+		errCode = http.StatusBadRequest
+		api.HandleErr(w, r, tx, errCode, nil, sysErr)
+		return
+	}
+
+	query := readQuery + where + orderBy + pagination
+	rows, err := inf.Tx.NamedQuery(query, queryValues)
+	if err != nil {
+		userErr, sysErr, errCode = api.ParseDBError(err)
+		if sysErr != nil {
+			sysErr = fmt.Errorf("notification read query: %v", sysErr)
+		}
+
+		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+		return
+	}
+	defer rows.Close()
+
+	for rows.Next() {
+		var n tc.CDNNotification
+		if err = rows.Scan(&n.CDN, &n.LastUpdated, &n.User, &n.Notification); err != nil {
+			api.HandleErr(w, r, tx, http.StatusInternalServerError, nil, errors.New("scanning cdn notifications: "+err.Error()))
+			return
+		}
+		cdnNotifications = append(cdnNotifications, n)
+	}
+
+	api.WriteResp(w, r, cdnNotifications)
+}
+
+// Create is the handler for POST requests to /cdn_notifications.
+func Create(w http.ResponseWriter, r *http.Request) {
+	inf, sysErr, userErr, errCode := api.NewInfo(r, nil, nil)
+	tx := inf.Tx.Tx
+	if sysErr != nil || userErr != nil {
+		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	var n tc.CDNNotification

Review comment:
       done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r582461615



##########
File path: lib/go-tc/cdn_notification.go
##########
@@ -0,0 +1,58 @@
+package tc
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+
+	"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
+	"github.com/apache/trafficcontrol/lib/go-util"
+
+	"github.com/go-ozzo/ozzo-validation"
+)
+
+// CDNNotificationsResponse is a list of CDN notifications as a response.
+type CDNNotificationsResponse struct {
+	Response []CDNNotification `json:"response"`
+	Alerts
+}
+
+// CDNNotificationRequest encodes the request data for the POST
+// cdn_notifications endpoint.
+type CDNNotificationRequest struct {
+	CDN          string `json:"cdn"`
+	Notification string `json:"notification"`
+}
+
+// CDNNotification is a notification created for a specific CDN
+type CDNNotification struct {
+	CDN          *string    `json:"cdn" db:"cdn"`
+	LastUpdated  *TimeNoMod `json:"lastUpdated" db:"last_updated"`
+	Notification *string    `json:"notification" db:"notification"`
+	User         *string    `json:"user" db:"user"`
+}
+
+// Validate validates the CDNNotification request is valid for creation.
+func (n *CDNNotification) Validate(tx *sql.Tx) error {
+	errs := validation.Errors{
+		"cdn": validation.Validate(n.CDN, validation.Required),
+	}
+	return util.JoinErrs(tovalidate.ToErrors(errs))
+}

Review comment:
       ah i see




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r582457515



##########
File path: traffic_portal/app/src/common/api/CDNService.js
##########
@@ -222,7 +222,42 @@ var CDNService = function($http, locationUtils, messageModel, ENV) {
                 throw err;
 			}
 		);
-	};
+	}
+
+    this.getNotifications = function(queryParams) {
+        return $http.get(ENV.api['root'] + 'cdn_notifications', { params: queryParams }).then(
+            function(result) {
+                return result.data.response;
+            },
+            function(err) {
+                throw err;
+            }
+        );
+    };
+
+    this.createNotification = function(cdn, notification) {
+        return $http.post(ENV.api['root'] + 'cdn_notifications', { cdn: cdn.name, notification: notification}).then(
+            function(result) {
+                return result;
+            },
+            function(err) {
+                messageModel.setMessages(err.data.alerts, false);
+                throw err;
+            }
+        );
+    };
+
+    this.deleteNotification = function(cdn) {
+        return $http.delete(ENV.api['root'] + 'cdn_notifications?cdn=' + cdn.name).then(

Review comment:
       oh right. i meant to fix that.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r578807190



##########
File path: traffic_portal/app/src/common/modules/notifications/notifications.tpl.html
##########
@@ -0,0 +1,24 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+-->
+
+<div id="notificationsContainer">
+    <div ng-show="cdn.notificationCreatedBy" class="alert alert-info" ng-repeat="cdn in cdns">
+        <div ng-bind-html="cdn.name + ': ' + cdn.notification + ' (' + cdn.notificationCreatedBy + ')' | linky:'_blank'"></div>

Review comment:
       https://docs.angularjs.org/api/ngSanitize/filter/linky




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r583805665



##########
File path: traffic_ops/traffic_ops_golang/cdnnotification/cdnnotifications.go
##########
@@ -0,0 +1,191 @@
+package cdnnotification
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+	"errors"
+	"fmt"
+	"net/http"
+
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/lib/go-util"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+)
+
+const readQuery = `
+SELECT cn.cdn, 
+	cn.last_updated,
+	cn.user, 
+	cn.notification 
+FROM cdn_notification as cn
+INNER JOIN cdn ON cdn.name = cn.cdn
+INNER JOIN tm_user ON tm_user.username = cn.user
+`
+
+const insertQuery = `
+INSERT INTO cdn_notification (cdn, "user", notification)
+VALUES ($1, $2, $3)
+RETURNING cdn_notification.cdn,
+          cdn_notification.last_updated,
+          cdn_notification.user,
+          cdn_notification.notification
+`
+
+const deleteQuery = `
+DELETE FROM cdn_notification
+WHERE cdn_notification.cdn = $1
+RETURNING cdn_notification.cdn,
+          cdn_notification.last_updated,
+          cdn_notification.user,
+          cdn_notification.notification
+`
+
+// Read is the handler for GET requests to /cdn_notifications.
+func Read(w http.ResponseWriter, r *http.Request) {
+	inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+	tx := inf.Tx.Tx
+	if userErr != nil || sysErr != nil {
+		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	cdnNotifications := []tc.CDNNotification{}
+
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"cdn":  dbhelpers.WhereColumnInfo{"cdn.name", nil},
+		"user": dbhelpers.WhereColumnInfo{"tm_user.username", nil},
+	}
+
+	where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		sysErr = util.JoinErrs(errs)
+		errCode = http.StatusBadRequest
+		api.HandleErr(w, r, tx, errCode, nil, sysErr)
+		return
+	}
+
+	query := readQuery + where + orderBy + pagination
+	rows, err := inf.Tx.NamedQuery(query, queryValues)
+	if err != nil {
+		userErr, sysErr, errCode = api.ParseDBError(err)
+		if sysErr != nil {
+			sysErr = fmt.Errorf("notification read query: %v", sysErr)
+		}
+
+		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+		return
+	}
+	defer rows.Close()
+
+	for rows.Next() {
+		var n tc.CDNNotification
+		if err = rows.Scan(&n.CDN, &n.LastUpdated, &n.User, &n.Notification); err != nil {
+			api.HandleErr(w, r, tx, http.StatusInternalServerError, nil, errors.New("scanning cdn notifications: "+err.Error()))
+			return
+		}
+		cdnNotifications = append(cdnNotifications, n)
+	}
+
+	api.WriteResp(w, r, cdnNotifications)
+}
+
+// Create is the handler for POST requests to /cdn_notifications.
+func Create(w http.ResponseWriter, r *http.Request) {
+	inf, sysErr, userErr, errCode := api.NewInfo(r, nil, nil)
+	tx := inf.Tx.Tx
+	if sysErr != nil || userErr != nil {
+		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	var req tc.CDNNotificationRequest
+	if userErr = api.Parse(r.Body, tx, &req); userErr != nil {
+		api.HandleErr(w, r, tx, http.StatusBadRequest, userErr, nil)
+		return
+	}
+
+	var resp tc.CDNNotification
+	err := tx.QueryRow(insertQuery, req.CDN, inf.User.UserName, req.Notification).Scan(&resp.CDN, &resp.LastUpdated, &resp.User, &resp.Notification)
+	if err != nil {
+		userErr, sysErr, errCode = api.ParseDBError(err)
+		api.HandleErr(w, r, tx, errCode, userErr, sysErr)
+		return
+	}
+
+	changeLogMsg := fmt.Sprintf("CDN_NOTIFICATION: %s, CDN: %s, ACTION: Created", *resp.Notification, resp.CDN)
+	api.CreateChangeLogRawTx(api.ApiChange, changeLogMsg, inf.User, tx)
+
+	alertMsg := fmt.Sprintf("CDN notification created [ User = %s ] for CDN: %s", resp.User, resp.CDN)
+	api.WriteRespAlertObj(w, r, tc.SuccessLevel, alertMsg, resp)

Review comment:
       where can i find an example of that?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r583795219



##########
File path: traffic_ops/traffic_ops_golang/routing/routes.go
##########
@@ -355,6 +356,11 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
 		{api.Version{4, 0}, http.MethodPost, `coordinates/?$`, api.CreateHandler(&coordinate.TOCoordinate{}), auth.PrivLevelOperations, Authenticated, nil, 44281121573},
 		{api.Version{4, 0}, http.MethodDelete, `coordinates/?$`, api.DeleteHandler(&coordinate.TOCoordinate{}), auth.PrivLevelOperations, Authenticated, nil, 43038498893},
 
+		//CDN notification
+		{api.Version{4, 0}, http.MethodGet, `cdn_notifications/?$`, cdnnotification.Read, auth.PrivLevelReadOnly, Authenticated, nil, 2221224514},
+		{api.Version{4, 0}, http.MethodPost, `cdn_notifications`, cdnnotification.Create, auth.PrivLevelOperations, Authenticated, nil, 2765223513},

Review comment:
       what's the problem? this is how all GETs look




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r582457937



##########
File path: traffic_portal/app/src/common/modules/form/cdn/FormCDNController.js
##########
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-var FormCDNController = function(cdn, $scope, $location, $uibModal, formUtils, stringUtils, locationUtils, cdnService) {
+var FormCDNController = function(cdn, $scope, $location, $state, $uibModal, formUtils, stringUtils, locationUtils, cdnService, messageModel) {

Review comment:
       i'll check. sometimes things are injected that were not used but not sure why i added one...




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r578727957



##########
File path: traffic_portal/app/src/common/modules/form/cdn/form.cdn.tpl.html
##########
@@ -41,6 +41,9 @@
                     <span class="caret"></span>
                 </button>
                 <ul class="dropdown-menu-right dropdown-menu" uib-dropdown-menu>
+                    <li ng-if="!cdn.notificationCreatedBy" role="menuitem"><a ng-click="toggleNotification(cdn)">Create CDN Notification</a></li>
+                    <li ng-if="cdn.notificationCreatedBy" role="menuitem"><a ng-click="toggleNotification(cdn)">Delete CDN Notification</a></li>

Review comment:
       Anchor tags should be links - these aren't performing navigation, so they ought to be `button[type="button"]`s

##########
File path: traffic_portal/app/src/common/modules/notifications/notifications.tpl.html
##########
@@ -0,0 +1,24 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+-->
+
+<div id="notificationsContainer">
+    <div ng-show="cdn.notificationCreatedBy" class="alert alert-info" ng-repeat="cdn in cdns">
+        <div ng-bind-html="cdn.name + ': ' + cdn.notification + ' (' + cdn.notificationCreatedBy + ')' | linky:'_blank'"></div>

Review comment:
       What is the `linky` pipe doing here?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#issuecomment-781659632


   > It looks like currently this change is adding two fields to CDNs in all API versions - is that correct?
   
   yes, that is correct.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r583901893



##########
File path: traffic_ops/testing/api/v4/cdnnotifications_test.go
##########
@@ -0,0 +1,61 @@
+package v4
+
+/*
+
+   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.
+*/
+
+import (
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"testing"

Review comment:
       i guess my "optimize imports" button doesn't work :(




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r583052646



##########
File path: lib/go-tc/cdn_notification.go
##########
@@ -0,0 +1,58 @@
+package tc
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import (
+	"database/sql"
+
+	"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
+	"github.com/apache/trafficcontrol/lib/go-util"
+
+	"github.com/go-ozzo/ozzo-validation"
+)
+
+// CDNNotificationsResponse is a list of CDN notifications as a response.
+type CDNNotificationsResponse struct {
+	Response []CDNNotification `json:"response"`
+	Alerts
+}
+
+// CDNNotificationRequest encodes the request data for the POST
+// cdn_notifications endpoint.
+type CDNNotificationRequest struct {
+	CDN          string `json:"cdn"`
+	Notification string `json:"notification"`
+}
+
+// CDNNotification is a notification created for a specific CDN
+type CDNNotification struct {
+	CDN          *string    `json:"cdn" db:"cdn"`
+	LastUpdated  *TimeNoMod `json:"lastUpdated" db:"last_updated"`

Review comment:
       The intention was for you to not be able to modify the `last_updated` time manually with a `POST` or `PUT`, but that's only a problem if you read into the entire struct and then use `sqlx.QueryRowx` to dump a struct's properties into a values row. But since you're using plain `sql.QueryRow` and have `CDNNotificationRequest` it's not going to cause any issues.
   
   I believe the proprietary format is meant to mirror Perl's returned date/time format, which wasn't RFC3339 for whatever reason.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] rawlinp commented on pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
rawlinp commented on pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#issuecomment-781705214


   Right, if that were the case, it would be a _major_ version bump (adding new required fields).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] mitchell852 commented on a change in pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
mitchell852 commented on a change in pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#discussion_r578806745



##########
File path: traffic_portal/app/src/common/modules/form/cdn/form.cdn.tpl.html
##########
@@ -41,6 +41,9 @@
                     <span class="caret"></span>
                 </button>
                 <ul class="dropdown-menu-right dropdown-menu" uib-dropdown-menu>
+                    <li ng-if="!cdn.notificationCreatedBy" role="menuitem"><a ng-click="toggleNotification(cdn)">Create CDN Notification</a></li>
+                    <li ng-if="cdn.notificationCreatedBy" role="menuitem"><a ng-click="toggleNotification(cdn)">Delete CDN Notification</a></li>

Review comment:
       removing. these were supposed to be removed but i forgot about them.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficcontrol] rawlinp commented on pull request #5179: Adds the ability to create a CDN-level notification via TP/TO API

Posted by GitBox <gi...@apache.org>.
rawlinp commented on pull request #5179:
URL: https://github.com/apache/trafficcontrol/pull/5179#issuecomment-782176961


   > What happens if a new client does a GET /cdns from an old TO, silently saves the empty string, and then does a POST /notifications with that data (possibly modified) later after TO is upgraded, or maybe to different HA TO?
   
   I'm sorry, but that is an extremely contrived example of something a user would most likely never have a valid reason to even do. You can't stop clients from misusing an API like that, even with 100% semantic versioning.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org