You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2018/04/10 18:22:06 UTC

[incubator-trafficcontrol] branch master updated (d28b128 -> 5bbf52b)

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

dangogh pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git.


    from d28b128  removes path params from ds request endpoints per api guidelines
     new 4684ced  added for api 1.3 support
     new 16ba623  updated for the v13 profile struct
     new 638818b  added swagger documentation for profiles
     new 4e549d0  updated to use constants to make query parameters more clear
     new b844bf9  added support for attaching parameters to profiles with an id query parameter
     new 1479db5  added parameter creation to the API test for profiles
     new 5bbf52b  added a test case to check that a Profile with Parameters gets retrieved

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 lib/go-tc/{ => v13}/parameters.go                  |  12 +-
 lib/go-tc/v13/profiles.go                          |  92 ++++++++++++
 traffic_ops/client/v13/profile.go                  |  19 +--
 traffic_ops/testing/api/v13/profiles_test.go       |  26 ++++
 traffic_ops/testing/api/v13/traffic_control.go     |   2 +-
 .../traffic_ops_golang/parameter/parameters.go     |  40 +++--
 traffic_ops/traffic_ops_golang/profile/profiles.go | 105 +++++++++++---
 traffic_ops/traffic_ops_golang/routes.go           |  10 +-
 .../traffic_ops_golang/swaggerdocs/v13/cdns.go     |   2 +-
 .../traffic_ops_golang/swaggerdocs/v13/profiles.go | 161 +++++++++++++++++++++
 10 files changed, 416 insertions(+), 53 deletions(-)
 copy lib/go-tc/{ => v13}/parameters.go (89%)
 create mode 100644 lib/go-tc/v13/profiles.go
 create mode 100644 traffic_ops/traffic_ops_golang/swaggerdocs/v13/profiles.go

-- 
To stop receiving notification emails like this one, please contact
dangogh@apache.org.

[incubator-trafficcontrol] 07/07: added a test case to check that a Profile with Parameters gets retrieved

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dangogh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git

commit 5bbf52b2b5fdb401daaeda6ac0d478966a3acb60
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Fri Apr 6 13:47:30 2018 -0600

    added a test case to check that a Profile with Parameters gets retrieved
    
    uncommented the deletes
---
 traffic_ops/client/v13/profile.go              | 17 +++++++++--------
 traffic_ops/testing/api/v13/profiles_test.go   | 24 ++++++++++++++++++++++++
 traffic_ops/testing/api/v13/traffic_control.go |  2 +-
 3 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/traffic_ops/client/v13/profile.go b/traffic_ops/client/v13/profile.go
index bbcc799..dba1b12 100644
--- a/traffic_ops/client/v13/profile.go
+++ b/traffic_ops/client/v13/profile.go
@@ -23,6 +23,7 @@ import (
 	"net/url"
 
 	"github.com/apache/incubator-trafficcontrol/lib/go-tc"
+	"github.com/apache/incubator-trafficcontrol/lib/go-tc/v13"
 )
 
 const (
@@ -30,7 +31,7 @@ const (
 )
 
 // Create a Profile
-func (to *Session) CreateProfile(pl tc.Profile) (tc.Alerts, ReqInf, error) {
+func (to *Session) CreateProfile(pl v13.Profile) (tc.Alerts, ReqInf, error) {
 
 	var remoteAddr net.Addr
 	reqBody, err := json.Marshal(pl)
@@ -49,7 +50,7 @@ func (to *Session) CreateProfile(pl tc.Profile) (tc.Alerts, ReqInf, error) {
 }
 
 // Update a Profile by ID
-func (to *Session) UpdateProfileByID(id int, pl tc.Profile) (tc.Alerts, ReqInf, error) {
+func (to *Session) UpdateProfileByID(id int, pl v13.Profile) (tc.Alerts, ReqInf, error) {
 
 	var remoteAddr net.Addr
 	reqBody, err := json.Marshal(pl)
@@ -69,7 +70,7 @@ func (to *Session) UpdateProfileByID(id int, pl tc.Profile) (tc.Alerts, ReqInf,
 }
 
 // Returns a list of Profiles
-func (to *Session) GetProfiles() ([]tc.Profile, ReqInf, error) {
+func (to *Session) GetProfiles() ([]v13.Profile, ReqInf, error) {
 	resp, remoteAddr, err := to.request(http.MethodGet, API_v13_Profiles, nil)
 	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
 	if err != nil {
@@ -77,13 +78,13 @@ func (to *Session) GetProfiles() ([]tc.Profile, ReqInf, error) {
 	}
 	defer resp.Body.Close()
 
-	var data tc.ProfilesResponse
+	var data v13.ProfilesResponse
 	err = json.NewDecoder(resp.Body).Decode(&data)
 	return data.Response, reqInf, nil
 }
 
 // GET a Profile by the Profile ID
-func (to *Session) GetProfileByID(id int) ([]tc.Profile, ReqInf, error) {
+func (to *Session) GetProfileByID(id int) ([]v13.Profile, ReqInf, error) {
 	route := fmt.Sprintf("%s/%d", API_v13_Profiles, id)
 	resp, remoteAddr, err := to.request(http.MethodGet, route, nil)
 	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
@@ -92,7 +93,7 @@ func (to *Session) GetProfileByID(id int) ([]tc.Profile, ReqInf, error) {
 	}
 	defer resp.Body.Close()
 
-	var data tc.ProfilesResponse
+	var data v13.ProfilesResponse
 	if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
 		return nil, reqInf, err
 	}
@@ -101,7 +102,7 @@ func (to *Session) GetProfileByID(id int) ([]tc.Profile, ReqInf, error) {
 }
 
 // GET a Profile by the Profile name
-func (to *Session) GetProfileByName(name string) ([]tc.Profile, ReqInf, error) {
+func (to *Session) GetProfileByName(name string) ([]v13.Profile, ReqInf, error) {
 	URI := API_v13_Profiles + "?name=" + url.QueryEscape(name)
 	resp, remoteAddr, err := to.request(http.MethodGet, URI, nil)
 	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
@@ -110,7 +111,7 @@ func (to *Session) GetProfileByName(name string) ([]tc.Profile, ReqInf, error) {
 	}
 	defer resp.Body.Close()
 
-	var data tc.ProfilesResponse
+	var data v13.ProfilesResponse
 	if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
 		return nil, reqInf, err
 	}
diff --git a/traffic_ops/testing/api/v13/profiles_test.go b/traffic_ops/testing/api/v13/profiles_test.go
index 50ee4ab..94677f8 100644
--- a/traffic_ops/testing/api/v13/profiles_test.go
+++ b/traffic_ops/testing/api/v13/profiles_test.go
@@ -28,8 +28,11 @@ func TestProfiles(t *testing.T) {
 	CreateTestTypes(t)
 	CreateTestProfiles(t)
 	CreateTestParameters(t)
+	CreateTestProfileParameters(t)
 	UpdateTestProfiles(t)
 	GetTestProfiles(t)
+	GetTestProfilesWithParameters(t)
+	DeleteTestProfileParameters(t)
 	DeleteTestParameters(t)
 	DeleteTestProfiles(t)
 	DeleteTestTypes(t)
@@ -92,6 +95,27 @@ func GetTestProfiles(t *testing.T) {
 		}
 	}
 }
+func GetTestProfilesWithParameters(t *testing.T) {
+	firstProfile := testData.Profiles[0]
+	resp, _, err := TOSession.GetProfileByName(firstProfile.Name)
+	if len(resp) > 0 {
+		respProfile := resp[0]
+		resp, _, err := TOSession.GetProfileByID(respProfile.ID)
+		if err != nil {
+			t.Errorf("cannot GET Profile by name: %v - %v\n", err, resp)
+		}
+		if len(resp) > 0 {
+			respProfile = resp[0]
+			respParameters := respProfile.Parameters
+			if len(respParameters) == 0 {
+				t.Errorf("expected a profile with parameters to be retrieved: %v - %v\n", err, respParameters)
+			}
+		}
+	}
+	if err != nil {
+		t.Errorf("cannot GET Profile by name: %v - %v\n", err, resp)
+	}
+}
 
 func DeleteTestProfiles(t *testing.T) {
 
diff --git a/traffic_ops/testing/api/v13/traffic_control.go b/traffic_ops/testing/api/v13/traffic_control.go
index f21198b..015089e 100644
--- a/traffic_ops/testing/api/v13/traffic_control.go
+++ b/traffic_ops/testing/api/v13/traffic_control.go
@@ -29,7 +29,7 @@ type TrafficControl struct {
 	DeliveryServiceRequestComments []v12.DeliveryServiceRequestComment `json:"deliveryServiceRequestComments"`
 	DeliveryServices               []v12.DeliveryService               `json:"deliveryservices"`
 	Divisions                      []v12.Division                      `json:"divisions"`
-	Profiles                       []v12.Profile                       `json:"profiles"`
+	Profiles                       []v13.Profile                       `json:"profiles"`
 	Parameters                     []v12.Parameter                     `json:"parameters"`
 	ProfileParameters              []v13.ProfileParameter              `json:"profileParameters"`
 	PhysLocations                  []v12.PhysLocation                  `json:"physLocations"`

-- 
To stop receiving notification emails like this one, please contact
dangogh@apache.org.

[incubator-trafficcontrol] 06/07: added parameter creation to the API test for profiles

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dangogh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git

commit 1479db504380c519057ece761f809387619d1074
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Fri Apr 6 13:28:20 2018 -0600

    added parameter creation to the API test for profiles
---
 lib/go-tc/v13/profiles.go                    | 17 ++++++++++-------
 traffic_ops/client/v13/profile.go            |  2 +-
 traffic_ops/testing/api/v13/profiles_test.go |  2 ++
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/lib/go-tc/v13/profiles.go b/lib/go-tc/v13/profiles.go
index 098e331..71587df 100644
--- a/lib/go-tc/v13/profiles.go
+++ b/lib/go-tc/v13/profiles.go
@@ -42,12 +42,13 @@ type Profile struct {
 	//
 	LastUpdated tc.TimeNoMod `json:"lastUpdated" db:"last_updated"`
 
-	Name            string `json:"name"`
-	Description     string `json:"description"`
-	CDNName         string `json:"cdnName"`
-	CDNID           int    `json:"cdn"`
-	RoutingDisabled bool   `json:"routingDisabled"`
-	Type            string `json:"type"`
+	Name            string              `json:"name"`
+	Description     string              `json:"description"`
+	CDNName         string              `json:"cdnName"`
+	CDNID           int                 `json:"cdn"`
+	RoutingDisabled bool                `json:"routingDisabled"`
+	Type            string              `json:"type"`
+	Parameters      []ParameterNullable `json:"params,omitempty"`
 }
 
 // ProfileNullable ...
@@ -85,5 +86,7 @@ type ProfileNullable struct {
 	//
 	Type *string `json:"type" db:"type"`
 
-	Parameters []ParameterNullable `json:"params"`
+	// Parameters associated to the profile
+	//
+	Parameters []ParameterNullable `json:"params,omitempty"`
 }
diff --git a/traffic_ops/client/v13/profile.go b/traffic_ops/client/v13/profile.go
index 0eb9b66..bbcc799 100644
--- a/traffic_ops/client/v13/profile.go
+++ b/traffic_ops/client/v13/profile.go
@@ -26,7 +26,7 @@ import (
 )
 
 const (
-	API_v13_Profiles = "/api/1.3/profiles-wip"
+	API_v13_Profiles = "/api/1.3/profiles"
 )
 
 // Create a Profile
diff --git a/traffic_ops/testing/api/v13/profiles_test.go b/traffic_ops/testing/api/v13/profiles_test.go
index c7fa48b..50ee4ab 100644
--- a/traffic_ops/testing/api/v13/profiles_test.go
+++ b/traffic_ops/testing/api/v13/profiles_test.go
@@ -27,8 +27,10 @@ func TestProfiles(t *testing.T) {
 	CreateTestCDNs(t)
 	CreateTestTypes(t)
 	CreateTestProfiles(t)
+	CreateTestParameters(t)
 	UpdateTestProfiles(t)
 	GetTestProfiles(t)
+	DeleteTestParameters(t)
 	DeleteTestProfiles(t)
 	DeleteTestTypes(t)
 	DeleteTestCDNs(t)

-- 
To stop receiving notification emails like this one, please contact
dangogh@apache.org.

[incubator-trafficcontrol] 05/07: added support for attaching parameters to profiles with an id query parameter

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dangogh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git

commit b844bf97396f456839dbd721605fe69b4d4393ad
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Fri Apr 6 13:13:48 2018 -0600

    added support for attaching parameters to profiles with an id query parameter
---
 lib/go-tc/v13/parameters.go                        | 56 +++++++++++++++++
 lib/go-tc/v13/profiles.go                          |  2 +
 .../traffic_ops_golang/parameter/parameters.go     |  7 ++-
 traffic_ops/traffic_ops_golang/profile/profiles.go | 70 ++++++++++++++++++++--
 4 files changed, 128 insertions(+), 7 deletions(-)

diff --git a/lib/go-tc/v13/parameters.go b/lib/go-tc/v13/parameters.go
new file mode 100644
index 0000000..e02d9b5
--- /dev/null
+++ b/lib/go-tc/v13/parameters.go
@@ -0,0 +1,56 @@
+package v13
+
+import (
+	"encoding/json"
+
+	tc "github.com/apache/incubator-trafficcontrol/lib/go-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.
+ */
+
+// ParametersResponse ...
+type ParametersResponse struct {
+	Response []Parameter `json:"response"`
+}
+
+// Parameter ...
+type Parameter struct {
+	ConfigFile  string          `json:"configFile" db:"config_file"`
+	ID          int             `json:"id" db:"id"`
+	LastUpdated tc.TimeNoMod    `json:"lastUpdated" db:"last_updated"`
+	Name        string          `json:"name" db:"name"`
+	Profiles    json.RawMessage `json:"profiles" db:"profiles"`
+	Secure      bool            `json:"secure" db:"secure"`
+	Value       string          `json:"value" db:"value"`
+}
+
+// ParameterNullable - a struct version that allows for all fields to be null, mostly used by the API side
+type ParameterNullable struct {
+	//
+	// NOTE: the db: struct tags are used for testing to map to their equivalent database column (if there is one)
+	//
+	ConfigFile  *string         `json:"configFile" db:"config_file"`
+	ID          *int            `json:"id" db:"id"`
+	LastUpdated *tc.TimeNoMod   `json:"lastUpdated" db:"last_updated"`
+	Name        *string         `json:"name" db:"name"`
+	Profiles    json.RawMessage `json:"profiles" db:"profiles"`
+	Secure      *bool           `json:"secure" db:"secure"`
+	Value       *string         `json:"value" db:"value"`
+}
diff --git a/lib/go-tc/v13/profiles.go b/lib/go-tc/v13/profiles.go
index 19899b4..098e331 100644
--- a/lib/go-tc/v13/profiles.go
+++ b/lib/go-tc/v13/profiles.go
@@ -84,4 +84,6 @@ type ProfileNullable struct {
 	// The Type name associated with the Profile
 	//
 	Type *string `json:"type" db:"type"`
+
+	Parameters []ParameterNullable `json:"params"`
 }
diff --git a/traffic_ops/traffic_ops_golang/parameter/parameters.go b/traffic_ops/traffic_ops_golang/parameter/parameters.go
index 7d1af69..6eb6b30 100644
--- a/traffic_ops/traffic_ops_golang/parameter/parameters.go
+++ b/traffic_ops/traffic_ops_golang/parameter/parameters.go
@@ -44,6 +44,10 @@ const (
 	ValueQueryParam      = "value"
 )
 
+var (
+	HiddenField = "********"
+)
+
 //we need a type alias to define functions on
 type TOParameter tc.ParameterNullable
 
@@ -214,7 +218,6 @@ func (parameter *TOParameter) Read(db *sqlx.DB, parameters map[string]string, us
 	defer rows.Close()
 
 	params := []interface{}{}
-	hiddenField := "********"
 	for rows.Next() {
 		var p tc.ParameterNullable
 		if err = rows.StructScan(&p); err != nil {
@@ -227,7 +230,7 @@ func (parameter *TOParameter) Read(db *sqlx.DB, parameters map[string]string, us
 		}
 
 		if isSecure && (privLevel < auth.PrivLevelAdmin) {
-			p.Value = &hiddenField
+			p.Value = &HiddenField
 		}
 		params = append(params, p)
 	}
diff --git a/traffic_ops/traffic_ops_golang/profile/profiles.go b/traffic_ops/traffic_ops_golang/profile/profiles.go
index 189ba54..d848c6e 100644
--- a/traffic_ops/traffic_ops_golang/profile/profiles.go
+++ b/traffic_ops/traffic_ops_golang/profile/profiles.go
@@ -30,6 +30,7 @@ import (
 	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/api"
 	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/auth"
 	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/parameter"
 	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/tovalidate"
 	validation "github.com/go-ozzo/ozzo-validation"
 	"github.com/jmoiron/sqlx"
@@ -46,6 +47,7 @@ const (
 
 //we need a type alias to define functions on
 type TOProfile v13.ProfileNullable
+type TOParameter v13.ParameterNullable
 
 //the refType is passed into the handlers where a copy of its type is used to decode the json.
 var refType = TOProfile{}
@@ -112,7 +114,7 @@ func (prof *TOProfile) Read(db *sqlx.DB, parameters map[string]string, user auth
 		return nil, errs, tc.DataConflictError
 	}
 
-	query := selectQuery() + where + orderBy
+	query := selectProfilesQuery() + where + orderBy
 	log.Debugln("Query is ", query)
 
 	rows, err := db.NamedQuery(query, queryValues)
@@ -124,11 +126,21 @@ func (prof *TOProfile) Read(db *sqlx.DB, parameters map[string]string, user auth
 
 	profiles := []interface{}{}
 	for rows.Next() {
-		var p tc.ProfileNullable
+		var p v13.ProfileNullable
 		if err = rows.StructScan(&p); err != nil {
 			log.Errorf("error parsing Profile rows: %v", err)
 			return nil, []error{tc.DBError}, tc.SystemError
 		}
+
+		// Attach Parameters if the 'id' parameter is sent
+		if _, ok := parameters[IDQueryParam]; ok {
+			params, err := ReadParameters(db, parameters, user, p)
+			p.Parameters = params
+			if len(errs) > 0 {
+				log.Errorf("Error getting Parameters: %v", err)
+				return nil, []error{tc.DBError}, tc.SystemError
+			}
+		}
 		profiles = append(profiles, p)
 	}
 
@@ -136,7 +148,7 @@ func (prof *TOProfile) Read(db *sqlx.DB, parameters map[string]string, user auth
 
 }
 
-func selectQuery() string {
+func selectProfilesQuery() string {
 
 	query := `SELECT
 prof.description,
@@ -153,6 +165,56 @@ JOIN cdn c ON prof.cdn = c.id`
 	return query
 }
 
+func ReadParameters(db *sqlx.DB, parameters map[string]string, user auth.CurrentUser, profile v13.ProfileNullable) ([]v13.ParameterNullable, []error) {
+
+	var rows *sqlx.Rows
+	privLevel := user.PrivLevel
+	queryValues := make(map[string]interface{})
+	queryValues["profile_id"] = *profile.ID
+
+	query := selectParametersQuery()
+	rows, err := db.NamedQuery(query, queryValues)
+	if err != nil {
+		log.Errorf("Error querying Parameter: %v", err)
+		return nil, []error{tc.DBError}
+	}
+	defer rows.Close()
+
+	var params []v13.ParameterNullable
+	for rows.Next() {
+		var param v13.ParameterNullable
+
+		if err = rows.StructScan(&param); err != nil {
+			log.Errorf("error parsing parameter rows: %v", err)
+			return nil, []error{tc.DBError}
+		}
+		var isSecure bool
+		if param.Secure != nil {
+			isSecure = *param.Secure
+		}
+		if isSecure && (privLevel < auth.PrivLevelAdmin) {
+			param.Value = &parameter.HiddenField
+		}
+		params = append(params, param)
+	}
+	return params, []error{}
+}
+
+func selectParametersQuery() string {
+
+	query := `SELECT
+p.id,
+p.name,
+p.config_file,
+p.value,
+p.secure
+FROM parameter p
+JOIN profile_parameter pp ON pp.parameter = p.id 
+WHERE pp.profile = :profile_id`
+
+	return query
+}
+
 //The TOProfile implementation of the Updater interface
 //all implementations of Updater should use transactions and return the proper errorType
 //ParsePQUniqueConstraintError is used to determine if a profile with conflicting values exists
@@ -240,8 +302,6 @@ func (prof *TOProfile) Create(db *sqlx.DB, user auth.CurrentUser) (error, tc.Api
 		log.Error.Printf("could not begin transaction: %v", err)
 		return tc.DBError, tc.SystemError
 	}
-	q := insertQuery()
-	fmt.Printf("q ---> %v\n", q)
 	resultRows, err := tx.NamedQuery(insertQuery(), prof)
 	if err != nil {
 		if pqErr, ok := err.(*pq.Error); ok {

-- 
To stop receiving notification emails like this one, please contact
dangogh@apache.org.

[incubator-trafficcontrol] 02/07: updated for the v13 profile struct

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dangogh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git

commit 16ba6238a6338f1bf97d39f6fb56655d07c05a80
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Wed Apr 4 13:44:21 2018 -0600

    updated for the v13 profile struct
    
    uncommented the -wip
---
 traffic_ops/traffic_ops_golang/profile/profiles.go |  5 +++--
 traffic_ops/traffic_ops_golang/routes.go           | 10 +++++-----
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/traffic_ops/traffic_ops_golang/profile/profiles.go b/traffic_ops/traffic_ops_golang/profile/profiles.go
index faccb26..4ead452 100644
--- a/traffic_ops/traffic_ops_golang/profile/profiles.go
+++ b/traffic_ops/traffic_ops_golang/profile/profiles.go
@@ -26,6 +26,7 @@ import (
 
 	"github.com/apache/incubator-trafficcontrol/lib/go-log"
 	"github.com/apache/incubator-trafficcontrol/lib/go-tc"
+	"github.com/apache/incubator-trafficcontrol/lib/go-tc/v13"
 	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/api"
 	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/auth"
 	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
@@ -36,10 +37,10 @@ import (
 )
 
 //we need a type alias to define functions on
-type TOProfile tc.ProfileNullable
+type TOProfile v13.ProfileNullable
 
 //the refType is passed into the handlers where a copy of its type is used to decode the json.
-var refType = TOProfile(tc.ProfileNullable{})
+var refType = TOProfile{}
 
 func GetRefType() *TOProfile {
 	return &refType
diff --git a/traffic_ops/traffic_ops_golang/routes.go b/traffic_ops/traffic_ops_golang/routes.go
index baca2e3..c6c72be 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -192,11 +192,11 @@ func Routes(d ServerData) ([]Route, http.Handler, error) {
 		{1.2, http.MethodGet, `servers/{host_name}/update_status$`, server.GetServerUpdateStatusHandler(d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
 
 		//Profiles
-		{1.3, http.MethodGet, `profiles-wip/?(\.json)?$`, api.ReadHandler(profile.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
-		{1.3, http.MethodGet, `profiles-wip/{id}$`, api.ReadHandler(profile.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
-		{1.3, http.MethodPut, `profiles-wip/{id}$`, api.UpdateHandler(profile.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
-		{1.3, http.MethodPost, `profiles-wip/?$`, api.CreateHandler(profile.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
-		{1.3, http.MethodDelete, `profiles-wip/{id}$`, api.DeleteHandler(profile.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
+		{1.3, http.MethodGet, `profiles/?(\.json)?$`, api.ReadHandler(profile.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
+		{1.3, http.MethodGet, `profiles/{id}$`, api.ReadHandler(profile.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
+		{1.3, http.MethodPut, `profiles/{id}$`, api.UpdateHandler(profile.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
+		{1.3, http.MethodPost, `profiles/?$`, api.CreateHandler(profile.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
+		{1.3, http.MethodDelete, `profiles/{id}$`, api.DeleteHandler(profile.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
 
 		//ProfileParameters
 		{1.3, http.MethodGet, `profile_parameters/?(\.json)?$`, api.ReadHandler(profileparameter.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},

-- 
To stop receiving notification emails like this one, please contact
dangogh@apache.org.

[incubator-trafficcontrol] 04/07: updated to use constants to make query parameters more clear

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dangogh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git

commit 4e549d0c987fafff69b4d694aee7572afa7a73c0
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Thu Apr 5 09:23:17 2018 -0600

    updated to use constants to make query parameters more clear
---
 .../traffic_ops_golang/parameter/parameters.go     | 33 +++++++++++++---------
 traffic_ops/traffic_ops_golang/profile/profiles.go | 30 ++++++++++++--------
 2 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/traffic_ops/traffic_ops_golang/parameter/parameters.go b/traffic_ops/traffic_ops_golang/parameter/parameters.go
index a75de8c..7d1af69 100644
--- a/traffic_ops/traffic_ops_golang/parameter/parameters.go
+++ b/traffic_ops/traffic_ops_golang/parameter/parameters.go
@@ -36,6 +36,14 @@ import (
 	"github.com/lib/pq"
 )
 
+const (
+	NameQueryParam       = "name"
+	SecureQueryParam     = "secure"
+	ConfigFileQueryParam = "configFile"
+	IDQueryParam         = "id"
+	ValueQueryParam      = "value"
+)
+
 //we need a type alias to define functions on
 type TOParameter tc.ParameterNullable
 
@@ -47,19 +55,19 @@ func GetRefType() *TOParameter {
 }
 
 func (parameter TOParameter) GetKeyFieldsInfo() []api.KeyFieldInfo {
-	return []api.KeyFieldInfo{{"id", api.GetIntKey}}
+	return []api.KeyFieldInfo{{IDQueryParam, api.GetIntKey}}
 }
 
 //Implementation of the Identifier, Validator interface functions
 func (parameter TOParameter) GetKeys() (map[string]interface{}, bool) {
 	if parameter.ID == nil {
-		return map[string]interface{}{"id": 0}, false
+		return map[string]interface{}{IDQueryParam: 0}, false
 	}
-	return map[string]interface{}{"id": *parameter.ID}, true
+	return map[string]interface{}{IDQueryParam: *parameter.ID}, true
 }
 
 func (parameter *TOParameter) SetKeys(keys map[string]interface{}) {
-	i, _ := keys["id"].(int) //this utilizes the non panicking type assertion, if the thrown away ok variable is false i will be the zero of the type, 0 here.
+	i, _ := keys[IDQueryParam].(int) //this utilizes the non panicking type assertion, if the thrown away ok variable is false i will be the zero of the type, 0 here.
 	parameter.ID = &i
 }
 
@@ -85,9 +93,9 @@ func (parameter TOParameter) Validate(db *sqlx.DB) []error {
 	// - Admin rights only
 	// - Do not allow duplicate parameters by name+config_file+value
 	errs := validation.Errors{
-		"name":       validation.Validate(parameter.Name, validation.Required),
-		"configFile": validation.Validate(parameter.ConfigFile, validation.Required),
-		"value":      validation.Validate(parameter.Value, validation.Required),
+		NameQueryParam:       validation.Validate(parameter.Name, validation.Required),
+		ConfigFileQueryParam: validation.Validate(parameter.ConfigFile, validation.Required),
+		ValueQueryParam:      validation.Validate(parameter.Value, validation.Required),
 	}
 
 	return tovalidate.ToErrors(errs)
@@ -152,7 +160,7 @@ func (pl *TOParameter) Create(db *sqlx.DB, user auth.CurrentUser) (error, tc.Api
 		return tc.DBError, tc.SystemError
 	}
 
-	pl.SetKeys(map[string]interface{}{"id": id})
+	pl.SetKeys(map[string]interface{}{IDQueryParam: id})
 	pl.LastUpdated = &lastUpdated
 	err = tx.Commit()
 	if err != nil {
@@ -184,11 +192,10 @@ func (parameter *TOParameter) Read(db *sqlx.DB, parameters map[string]string, us
 	// Query Parameters to Database Query column mappings
 	// see the fields mapped in the SQL query
 	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
-		"config_file":  dbhelpers.WhereColumnInfo{"p.config_file", nil},
-		"id":           dbhelpers.WhereColumnInfo{"p.id", api.IsInt},
-		"last_updated": dbhelpers.WhereColumnInfo{"p.last_updated", nil},
-		"name":         dbhelpers.WhereColumnInfo{"p.name", nil},
-		"secure":       dbhelpers.WhereColumnInfo{"p.secure", api.IsBool},
+		ConfigFileQueryParam: dbhelpers.WhereColumnInfo{"p.config_file", nil},
+		IDQueryParam:         dbhelpers.WhereColumnInfo{"p.id", api.IsInt},
+		NameQueryParam:       dbhelpers.WhereColumnInfo{"p.name", nil},
+		SecureQueryParam:     dbhelpers.WhereColumnInfo{"p.secure", api.IsBool},
 	}
 
 	where, orderBy, queryValues, errs := dbhelpers.BuildWhereAndOrderBy(parameters, queryParamsToQueryCols)
diff --git a/traffic_ops/traffic_ops_golang/profile/profiles.go b/traffic_ops/traffic_ops_golang/profile/profiles.go
index 4ead452..189ba54 100644
--- a/traffic_ops/traffic_ops_golang/profile/profiles.go
+++ b/traffic_ops/traffic_ops_golang/profile/profiles.go
@@ -36,6 +36,14 @@ import (
 	"github.com/lib/pq"
 )
 
+const (
+	CDNQueryParam         = "cdn"
+	NameQueryParam        = "name"
+	IDQueryParam          = "id"
+	DescriptionQueryParam = "description"
+	TypeQueryParam        = "type"
+)
+
 //we need a type alias to define functions on
 type TOProfile v13.ProfileNullable
 
@@ -47,19 +55,19 @@ func GetRefType() *TOProfile {
 }
 
 func (prof TOProfile) GetKeyFieldsInfo() []api.KeyFieldInfo {
-	return []api.KeyFieldInfo{{"id", api.GetIntKey}}
+	return []api.KeyFieldInfo{{IDQueryParam, api.GetIntKey}}
 }
 
 //Implementation of the Identifier, Validator interface functions
 func (prof TOProfile) GetKeys() (map[string]interface{}, bool) {
 	if prof.ID == nil {
-		return map[string]interface{}{"id": 0}, false
+		return map[string]interface{}{IDQueryParam: 0}, false
 	}
-	return map[string]interface{}{"id": *prof.ID}, true
+	return map[string]interface{}{IDQueryParam: *prof.ID}, true
 }
 
 func (prof *TOProfile) SetKeys(keys map[string]interface{}) {
-	i, _ := keys["id"].(int) //this utilizes the non panicking type assertion, if the thrown away ok variable is false i will be the zero of the type, 0 here.
+	i, _ := keys[IDQueryParam].(int) //this utilizes the non panicking type assertion, if the thrown away ok variable is false i will be the zero of the type, 0 here.
 	prof.ID = &i
 }
 
@@ -79,10 +87,10 @@ func (prof *TOProfile) GetType() string {
 
 func (prof *TOProfile) Validate(db *sqlx.DB) []error {
 	errs := validation.Errors{
-		"name":        validation.Validate(prof.Name, validation.Required),
-		"description": validation.Validate(prof.Description, validation.Required),
-		"cdn":         validation.Validate(prof.CDNID, validation.Required),
-		"type":        validation.Validate(prof.Type, validation.Required),
+		NameQueryParam:        validation.Validate(prof.Name, validation.Required),
+		DescriptionQueryParam: validation.Validate(prof.Description, validation.Required),
+		CDNQueryParam:         validation.Validate(prof.CDNID, validation.Required),
+		TypeQueryParam:        validation.Validate(prof.Type, validation.Required),
 	}
 	if errs != nil {
 		return tovalidate.ToErrors(errs)
@@ -96,8 +104,8 @@ func (prof *TOProfile) Read(db *sqlx.DB, parameters map[string]string, user auth
 	// Query Parameters to Database Query column mappings
 	// see the fields mapped in the SQL query
 	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
-		"name": dbhelpers.WhereColumnInfo{"prof.name", nil},
-		"id":   dbhelpers.WhereColumnInfo{"prof.id", api.IsInt},
+		NameQueryParam: dbhelpers.WhereColumnInfo{"prof.name", nil},
+		IDQueryParam:   dbhelpers.WhereColumnInfo{"prof.id", api.IsInt},
 	}
 	where, orderBy, queryValues, errs := dbhelpers.BuildWhereAndOrderBy(parameters, queryParamsToQueryCols)
 	if len(errs) > 0 {
@@ -269,7 +277,7 @@ func (prof *TOProfile) Create(db *sqlx.DB, user auth.CurrentUser) (error, tc.Api
 		return tc.DBError, tc.SystemError
 	}
 
-	prof.SetKeys(map[string]interface{}{"id": id})
+	prof.SetKeys(map[string]interface{}{IDQueryParam: id})
 	prof.LastUpdated = &lastUpdated
 	err = tx.Commit()
 	if err != nil {

-- 
To stop receiving notification emails like this one, please contact
dangogh@apache.org.

[incubator-trafficcontrol] 01/07: added for api 1.3 support

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dangogh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git

commit 4684cede9b849117770d8f7cb0c74a4a3342fcd7
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Wed Apr 4 13:44:06 2018 -0600

    added for api 1.3 support
---
 lib/go-tc/v13/profiles.go | 59 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/lib/go-tc/v13/profiles.go b/lib/go-tc/v13/profiles.go
new file mode 100644
index 0000000..22003bf
--- /dev/null
+++ b/lib/go-tc/v13/profiles.go
@@ -0,0 +1,59 @@
+package v13
+
+import tc "github.com/apache/incubator-trafficcontrol/lib/go-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.
+ */
+
+// ProfilesResponse ...
+type ProfilesResponse struct {
+	Response []Profile `json:"response"`
+}
+
+// Profile ...
+type Profile struct {
+	ID int `json:"id" db:"id"`
+
+	// LastUpdated
+	//
+	LastUpdated tc.TimeNoMod `json:"lastUpdated" db:"last_updated"`
+
+	Name            string `json:"name"`
+	Description     string `json:"description"`
+	CDNName         string `json:"cdnName"`
+	CDNID           int    `json:"cdn"`
+	RoutingDisabled bool   `json:"routingDisabled"`
+	Type            string `json:"type"`
+}
+
+// ProfileNullable ...
+type ProfileNullable struct {
+	ID *int `json:"id" db:"id"`
+
+	// LastUpdated
+	//
+	LastUpdated *tc.TimeNoMod `json:"lastUpdated" db:"last_updated"`
+
+	Name            *string `json:"name" db:"name"`
+	Description     *string `json:"description" db:"description"`
+	CDNName         *string `json:"cdnName" db:"cdn_name"`
+	CDNID           *int    `json:"cdn" db:"cdn"`
+	RoutingDisabled *bool   `json:"routingDisabled" db:"routing_disabled"`
+	Type            *string `json:"type" db:"type"`
+}

-- 
To stop receiving notification emails like this one, please contact
dangogh@apache.org.

[incubator-trafficcontrol] 03/07: added swagger documentation for profiles

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dangogh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git

commit 638818bcad69cb878599ef573937faef7f8a6c7f
Author: Dewayne Richardson <de...@apache.org>
AuthorDate: Thu Apr 5 09:22:19 2018 -0600

    added swagger documentation for profiles
    
    tweaked the cdns comment
---
 lib/go-tc/v13/profiles.go                          |  40 ++++-
 .../traffic_ops_golang/swaggerdocs/v13/cdns.go     |   2 +-
 .../traffic_ops_golang/swaggerdocs/v13/profiles.go | 161 +++++++++++++++++++++
 3 files changed, 196 insertions(+), 7 deletions(-)

diff --git a/lib/go-tc/v13/profiles.go b/lib/go-tc/v13/profiles.go
index 22003bf..19899b4 100644
--- a/lib/go-tc/v13/profiles.go
+++ b/lib/go-tc/v13/profiles.go
@@ -26,6 +26,14 @@ type ProfilesResponse struct {
 	Response []Profile `json:"response"`
 }
 
+// A Single Profile Response for Update and Create to depict what changed
+// swagger:response ProfileResponse
+// in: body
+type ProfileResponse struct {
+	// in: body
+	Response Profile `json:"response"`
+}
+
 // Profile ...
 type Profile struct {
 	ID int `json:"id" db:"id"`
@@ -44,16 +52,36 @@ type Profile struct {
 
 // ProfileNullable ...
 type ProfileNullable struct {
+
+	// Unique identifier for the Profile
+	//
 	ID *int `json:"id" db:"id"`
 
 	// LastUpdated
 	//
 	LastUpdated *tc.TimeNoMod `json:"lastUpdated" db:"last_updated"`
 
-	Name            *string `json:"name" db:"name"`
-	Description     *string `json:"description" db:"description"`
-	CDNName         *string `json:"cdnName" db:"cdn_name"`
-	CDNID           *int    `json:"cdn" db:"cdn"`
-	RoutingDisabled *bool   `json:"routingDisabled" db:"routing_disabled"`
-	Type            *string `json:"type" db:"type"`
+	// The Profile name
+	//
+	Name *string `json:"name" db:"name"`
+
+	// The Profile Description
+	//
+	Description *string `json:"description" db:"description"`
+
+	// The CDN name associated with the Profile
+	//
+	CDNName *string `json:"cdnName" db:"cdn_name"`
+
+	// The CDN id associated with the Profile
+	//
+	CDNID *int `json:"cdn" db:"cdn"`
+
+	// Enables
+	//
+	RoutingDisabled *bool `json:"routingDisabled" db:"routing_disabled"`
+
+	// The Type name associated with the Profile
+	//
+	Type *string `json:"type" db:"type"`
 }
diff --git a/traffic_ops/traffic_ops_golang/swaggerdocs/v13/cdns.go b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/cdns.go
index 77968ef..ee7bcf1 100644
--- a/traffic_ops/traffic_ops_golang/swaggerdocs/v13/cdns.go
+++ b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/cdns.go
@@ -58,7 +58,7 @@ type CDNQueryParams struct {
 	//
 	ID string `json:"id"`
 
-	// The CDN name for the CDN
+	// The CDN name
 	//
 	Name string `json:"name"`
 
diff --git a/traffic_ops/traffic_ops_golang/swaggerdocs/v13/profiles.go b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/profiles.go
new file mode 100644
index 0000000..18d7063
--- /dev/null
+++ b/traffic_ops/traffic_ops_golang/swaggerdocs/v13/profiles.go
@@ -0,0 +1,161 @@
+package v13
+
+/*
+ * 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 v13 "github.com/apache/incubator-trafficcontrol/lib/go-tc/v13"
+
+// Profiles -  ProfilesResponse to get the "response" top level key
+// swagger:response Profiles
+// in: body
+type Profiles struct {
+	// Profile Response Body
+	// in: body
+	ProfilesResponse v13.ProfilesResponse `json:"response"`
+}
+
+// Profile -  ProfileResponse to get the "response" top level key
+// swagger:response Profile
+// in: body
+type Profile struct {
+	// Profile Response Body
+	// in: body
+	ProfileResponse v13.ProfileResponse
+}
+
+// ProfileQueryParams
+//
+// swagger:parameters GetProfiles
+type ProfileQueryParams struct {
+
+	// ProfilesQueryParams
+
+	// Enables Domain Name System Security Extensions (DNSSEC) for the Profile
+	//
+	DNSSecEnabled string `json:"dnssecEnabled"`
+
+	// The domain name for the Profile
+	//
+	DomainName string `json:"domainName"`
+
+	// Unique identifier for the Profile
+	//
+	ID string `json:"id"`
+
+	// The Profile name for the Profile
+	//
+	Name string `json:"name"`
+
+	//
+	//
+	Orderby string `json:"orderby"`
+}
+
+// swagger:parameters PostProfile
+type ProfilePostParam struct {
+	// Profile Request Body
+	//
+	// in: body
+	// required: true
+	Profile v13.Profile
+}
+
+// swagger:parameters GetProfileById DeleteProfile
+type ProfilePathParams struct {
+
+	// Id associated to the Profile
+	// in: path
+	ID int `json:"id"`
+}
+
+// PostProfile swagger:route POST /cdns Profile PostProfile
+//
+// Create a Profile
+//
+// A Profile is a collection of Delivery Services
+//
+// Responses:
+//          200: Alerts
+func PostProfile(entity ProfilePostParam) (Profile, Alerts) {
+	return Profile{}, Alerts{}
+}
+
+// GetProfiles swagger:route GET /cdns Profile GetProfiles
+//
+// Retrieve a list of Profiles
+//
+// List of Profiles
+//
+// Responses:
+//          200: Profiles
+//          400: Alerts
+func GetProfiles() (Profiles, Alerts) {
+	return Profiles{}, Alerts{}
+}
+
+// swagger:parameters PutProfile
+type ProfilePutParam struct {
+
+	// ID
+	// in: path
+	ID int `json:"id"`
+
+	// Profile Request Body
+	//
+	// in: body
+	// required: true
+	Profile v13.Profile
+}
+
+// PutProfile swagger:route PUT /cdns/{id} Profile PutProfile
+//
+// Update a Profile by Id
+//
+// Update a Profile
+//
+// Responses:
+//          200: Profile
+func PutProfile(entity ProfilePutParam) (Profile, Alerts) {
+	return Profile{}, Alerts{}
+}
+
+// GetProfileById swagger:route GET /cdns/{id} Profile GetProfileById
+//
+// Retrieve a specific Profile by Id
+//
+// Retrieve a specific Profile
+//
+// Responses:
+//          200: Profiles
+//          400: Alerts
+func GetProfileById() (Profiles, Alerts) {
+	return Profiles{}, Alerts{}
+}
+
+// DeleteProfile swagger:route DELETE /cdns/{id} Profile DeleteProfile
+//
+// Delete a Profile by Id
+//
+// Delete a Profile
+//
+// Responses:
+//          200: Alerts
+func DeleteProfile(entityId int) Alerts {
+	return Alerts{}
+}

-- 
To stop receiving notification emails like this one, please contact
dangogh@apache.org.