You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ne...@apache.org on 2016/11/04 14:30:44 UTC

[1/6] incubator-trafficcontrol git commit: add client `CreateDeliveryService` method

Repository: incubator-trafficcontrol
Updated Branches:
  refs/heads/master fe5b5738c -> 20a9d2970


add client `CreateDeliveryService` method


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/0b9cb5a1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/0b9cb5a1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/0b9cb5a1

Branch: refs/heads/master
Commit: 0b9cb5a18f5dec671e5a409e5de1b02eed869f03
Parents: 0cc170f
Author: Mike Ball <mi...@gmail.com>
Authored: Wed Nov 2 15:09:06 2016 -0400
Committer: Dave Neuman <ne...@apache.org>
Committed: Fri Nov 4 08:29:54 2016 -0600

----------------------------------------------------------------------
 traffic_ops/client/delivery_service.go          | 206 +++----------------
 .../client/delivery_service_resources.go        | 206 +++++++++++++++++++
 traffic_ops/client/fixtures/delivery_service.go |  13 ++
 .../client/tests/delivery_service_test.go       |  48 +++++
 4 files changed, 293 insertions(+), 180 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/0b9cb5a1/traffic_ops/client/delivery_service.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/delivery_service.go b/traffic_ops/client/delivery_service.go
index 8318098..03817b5 100644
--- a/traffic_ops/client/delivery_service.go
+++ b/traffic_ops/client/delivery_service.go
@@ -17,179 +17,10 @@ package client
 
 import "encoding/json"
 
-// DeliveryServiceResponse ...
-type DeliveryServiceResponse struct {
-	Version  string            `json:"version"`
-	Response []DeliveryService `json:"response"`
-}
-
-// DeliveryService ...
-type DeliveryService struct {
-	ID                   string `json:"id"`
-	XMLID                string `json:"xmlId"`
-	Active               bool   `json:"active"`
-	DSCP                 string `json:"dscp"`
-	Signed               bool   `json:"signed"`
-	QStringIgnore        string `json:"qstringIgnore"`
-	GeoLimit             string `json:"geoLimit"`
-	GeoProvider          string `json:"geoProvider"`
-	HTTPBypassFQDN       string `json:"httpBypassFqdn"`
-	DNSBypassIP          string `json:"dnsBypassIp"`
-	DNSBypassIP6         string `json:"dnsBypassIp6"`
-	DNSBypassCname       string `json:"dnsBypassCname"`
-	DNSBypassTTL         string `json:"dnsBypassTtl"`
-	OrgServerFQDN        string `json:"orgServerFqdn"`
-	Type                 string `json:"type"`
-	ProfileName          string `json:"profileName"`
-	ProfileDesc          string `json:"profileDescription"`
-	CDNName              string `json:"cdnName"`
-	CCRDNSTTL            string `json:"ccrDnsTtl"`
-	GlobalMaxMBPS        string `json:"globalMaxMbps"`
-	GlobalMaxTPS         string `json:"globalMaxTps"`
-	LongDesc             string `json:"longDesc"`
-	LongDesc1            string `json:"longDesc1"`
-	LongDesc2            string `json:"longDesc2"`
-	MaxDNSAnswers        string `json:"maxDnsAnswers"`
-	InfoURL              string `json:"infoUrl"`
-	MissLat              string `json:"missLat"`
-	MissLong             string `json:"missLong"`
-	CheckPath            string `json:"checkPath"`
-	LastUpdated          string `json:"lastUpdated"`
-	Protocol             string `json:"protocol"`
-	IPV6RoutingEnabled   bool   `json:"ipv6RoutingEnabled"`
-	RangeRequestHandling string `json:"rangeRequestHandling"`
-	HeaderRewrite        string `json:"headerRewrite"`
-	EdgeHeaderRewrite    string `json:"edgeHeaderRewrite"`
-	MidHeaderRewrite     string `json:"midHeaderRewrite"`
-	TRResponseHeaders    string `json:"trResponseHeaders"`
-	RegexRemap           string `json:"regexRemap"`
-	CacheURL             string `json:"cacheurl"`
-	RemapText            string `json:"remapText"`
-	MultiSiteOrigin      string `json:"multiSiteOrigin"`
-	DisplayName          string `json:"displayName"`
-	InitialDispersion    string `json:"initialDispersion"`
-}
-
-// DeliveryServiceStateResponse ...
-type DeliveryServiceStateResponse struct {
-	Response DeliveryServiceState `json:"response"`
-}
-
-// DeliveryServiceState ...
-type DeliveryServiceState struct {
-	Enabled  bool                    `json:"enabled"`
-	Failover DeliveryServiceFailover `json:"failover"`
-}
-
-// DeliveryServiceFailover ...
-type DeliveryServiceFailover struct {
-	Locations   []string                   `json:"locations"`
-	Destination DeliveryServiceDestination `json:"destination"`
-	Configured  bool                       `json:"configured"`
-	Enabled     bool                       `json:"enabled"`
-}
-
-// DeliveryServiceDestination ...
-type DeliveryServiceDestination struct {
-	Location string `json:"location"`
-	Type     string `json:"type"`
-}
-
-// DeliveryServiceHealthResponse ...
-type DeliveryServiceHealthResponse struct {
-	Response DeliveryServiceHealth `json:"response"`
-}
-
-// DeliveryServiceHealth ...
-type DeliveryServiceHealth struct {
-	TotalOnline  int                         `json:"totalOnline"`
-	TotalOffline int                         `json:"totalOffline"`
-	CacheGroups  []DeliveryServiceCacheGroup `json:"cacheGroups"`
-}
-
-// DeliveryServiceCacheGroup ...
-type DeliveryServiceCacheGroup struct {
-	Online  int    `json:"online"`
-	Offline int    `json:"offline"`
-	Name    string `json:"name"`
-}
-
-// DeliveryServiceCapacityResponse ...
-type DeliveryServiceCapacityResponse struct {
-	Response DeliveryServiceCapacity `json:"response"`
-}
-
-// DeliveryServiceCapacity ...
-type DeliveryServiceCapacity struct {
-	AvailablePercent   float64 `json:"availablePercent"`
-	UnavailablePercent float64 `json:"unavailablePercent"`
-	UtilizedPercent    float64 `json:"utilizedPercent"`
-	MaintenancePercent float64 `json:"maintenancePercent"`
-}
-
-// DeliveryServiceRoutingResponse ...
-type DeliveryServiceRoutingResponse struct {
-	Response DeliveryServiceRouting `json:"response"`
-}
-
-// DeliveryServiceRouting ...
-type DeliveryServiceRouting struct {
-	StaticRoute       int     `json:"staticRoute"`
-	Miss              int     `json:"miss"`
-	Geo               float64 `json:"geo"`
-	Err               int     `json:"err"`
-	CZ                float64 `json:"cz"`
-	DSR               float64 `json:"dsr"`
-	Fed               int     `json:"fed"`
-	RegionalAlternate int     `json:"regionalAlternate"`
-	RegionalDenied    int     `json:"regionalDenied"`
-}
-
-// DeliveryServiceServerResponse ...
-type DeliveryServiceServerResponse struct {
-	Response []DeliveryServiceServer `json:"response"`
-	Page     int                     `json:"page"`
-	OrderBy  string                  `json:"orderby"`
-	Limit    int                     `json:"limit"`
-}
-
-// DeliveryServiceServer ...
-type DeliveryServiceServer struct {
-	LastUpdated     string `json:"lastUpdated"`
-	Server          string `json:"server"`
-	DeliveryService string `json:"deliveryService"`
-}
-
-// DeliveryServiceSSLKeysResponse ...
-type DeliveryServiceSSLKeysResponse struct {
-	Response DeliveryServiceSSLKeys `json:"response"`
-}
-
-// DeliveryServiceSSLKeys ...
-type DeliveryServiceSSLKeys struct {
-	CDN             string                            `json:"cdn"`
-	DeliveryService string                            `json:"DeliveryService"`
-	BusinessUnit    string                            `json:"businessUnit"`
-	City            string                            `json:"city"`
-	Organization    string                            `json:"organization"`
-	Hostname        string                            `json:"hostname"`
-	Country         string                            `json:"country"`
-	State           string                            `json:"state"`
-	Version         string                            `json:"version"`
-	Certificate     DeliveryServiceSSLKeysCertificate `json:"certificate"`
-}
-
-// DeliveryServiceSSLKeysCertificate ...
-type DeliveryServiceSSLKeysCertificate struct {
-	Crt string `json:"crt"`
-	Key string `json:"key"`
-	CSR string `json:"csr"`
-}
-
 // DeliveryServices gets an array of DeliveryServices
 func (to *Session) DeliveryServices() ([]DeliveryService, error) {
 	var data DeliveryServiceResponse
-	err := get(to, deliveryServicesEp(), &data)
+	err := makeReq(to, deliveryServicesEp(), nil, &data)
 	if err != nil {
 		return nil, err
 	}
@@ -200,7 +31,7 @@ func (to *Session) DeliveryServices() ([]DeliveryService, error) {
 // DeliveryService gets the DeliveryService for the ID it's passed
 func (to *Session) DeliveryService(id string) (*DeliveryService, error) {
 	var data DeliveryServiceResponse
-	err := get(to, deliveryServiceEp(id), &data)
+	err := makeReq(to, deliveryServiceEp(id), nil, &data)
 	if err != nil {
 		return nil, err
 	}
@@ -208,10 +39,25 @@ func (to *Session) DeliveryService(id string) (*DeliveryService, error) {
 	return &data.Response[0], nil
 }
 
+// CreateDeliveryService creates the DeliveryService it's passed
+func (to *Session) CreateDeliveryService(ds *DeliveryService) (*CreateDeliveryServiceResponse, error) {
+	var data CreateDeliveryServiceResponse
+	jsonReq, err := json.Marshal(ds)
+	if err != nil {
+		return nil, err
+	}
+	err = makeReq(to, deliveryServicesEp(), jsonReq, &data)
+	if err != nil {
+		return nil, err
+	}
+
+	return &data, nil
+}
+
 // DeliveryServiceState gets the DeliveryServiceState for the ID it's passed
 func (to *Session) DeliveryServiceState(id string) (*DeliveryServiceState, error) {
 	var data DeliveryServiceStateResponse
-	err := get(to, deliveryServiceStateEp(id), &data)
+	err := makeReq(to, deliveryServiceStateEp(id), nil, &data)
 	if err != nil {
 		return nil, err
 	}
@@ -222,7 +68,7 @@ func (to *Session) DeliveryServiceState(id string) (*DeliveryServiceState, error
 // DeliveryServiceHealth gets the DeliveryServiceHealth for the ID it's passed
 func (to *Session) DeliveryServiceHealth(id string) (*DeliveryServiceHealth, error) {
 	var data DeliveryServiceHealthResponse
-	err := get(to, deliveryServiceHealthEp(id), &data)
+	err := makeReq(to, deliveryServiceHealthEp(id), nil, &data)
 	if err != nil {
 		return nil, err
 	}
@@ -233,7 +79,7 @@ func (to *Session) DeliveryServiceHealth(id string) (*DeliveryServiceHealth, err
 // DeliveryServiceCapacity gets the DeliveryServiceCapacity for the ID it's passed
 func (to *Session) DeliveryServiceCapacity(id string) (*DeliveryServiceCapacity, error) {
 	var data DeliveryServiceCapacityResponse
-	err := get(to, deliveryServiceCapacityEp(id), &data)
+	err := makeReq(to, deliveryServiceCapacityEp(id), nil, &data)
 	if err != nil {
 		return nil, err
 	}
@@ -244,7 +90,7 @@ func (to *Session) DeliveryServiceCapacity(id string) (*DeliveryServiceCapacity,
 // DeliveryServiceRouting gets the DeliveryServiceRouting for the ID it's passed
 func (to *Session) DeliveryServiceRouting(id string) (*DeliveryServiceRouting, error) {
 	var data DeliveryServiceRoutingResponse
-	err := get(to, deliveryServiceRoutingEp(id), &data)
+	err := makeReq(to, deliveryServiceRoutingEp(id), nil, &data)
 	if err != nil {
 		return nil, err
 	}
@@ -255,7 +101,7 @@ func (to *Session) DeliveryServiceRouting(id string) (*DeliveryServiceRouting, e
 // DeliveryServiceServer gets the DeliveryServiceServer
 func (to *Session) DeliveryServiceServer(page, limit string) ([]DeliveryServiceServer, error) {
 	var data DeliveryServiceServerResponse
-	err := get(to, deliveryServiceServerEp(page, limit), &data)
+	err := makeReq(to, deliveryServiceServerEp(page, limit), nil, &data)
 	if err != nil {
 		return nil, err
 	}
@@ -266,7 +112,7 @@ func (to *Session) DeliveryServiceServer(page, limit string) ([]DeliveryServiceS
 // DeliveryServiceSSLKeysByID gets the DeliveryServiceSSLKeys by ID
 func (to *Session) DeliveryServiceSSLKeysByID(id string) (*DeliveryServiceSSLKeys, error) {
 	var data DeliveryServiceSSLKeysResponse
-	err := get(to, deliveryServiceSSLKeysByIDEp(id), &data)
+	err := makeReq(to, deliveryServiceSSLKeysByIDEp(id), nil, &data)
 	if err != nil {
 		return nil, err
 	}
@@ -277,7 +123,7 @@ func (to *Session) DeliveryServiceSSLKeysByID(id string) (*DeliveryServiceSSLKey
 // DeliveryServiceSSLKeysByHostname gets the DeliveryServiceSSLKeys by Hostname
 func (to *Session) DeliveryServiceSSLKeysByHostname(hostname string) (*DeliveryServiceSSLKeys, error) {
 	var data DeliveryServiceSSLKeysResponse
-	err := get(to, deliveryServiceSSLKeysByHostnameEp(hostname), &data)
+	err := makeReq(to, deliveryServiceSSLKeysByHostnameEp(hostname), nil, &data)
 	if err != nil {
 		return nil, err
 	}
@@ -285,8 +131,8 @@ func (to *Session) DeliveryServiceSSLKeysByHostname(hostname string) (*DeliveryS
 	return &data.Response, nil
 }
 
-func get(to *Session, endpoint string, respStruct interface{}) error {
-	resp, err := to.request(endpoint, nil)
+func makeReq(to *Session, endpoint string, body []byte, respStruct interface{}) error {
+	resp, err := to.request(endpoint, body)
 	if err != nil {
 		return err
 	}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/0b9cb5a1/traffic_ops/client/delivery_service_resources.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/delivery_service_resources.go b/traffic_ops/client/delivery_service_resources.go
new file mode 100644
index 0000000..9bccd2e
--- /dev/null
+++ b/traffic_ops/client/delivery_service_resources.go
@@ -0,0 +1,206 @@
+/*
+   Copyright 2015 Comcast Cable Communications Management, LLC
+
+   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
+
+// DeliveryServiceResponse ...
+type DeliveryServiceResponse struct {
+	Version  string            `json:"version"`
+	Response []DeliveryService `json:"response"`
+}
+
+// CreateDeliveryServiceResponse ...
+type CreateDeliveryServiceResponse struct {
+	Response DeliveryService        `json:"response"`
+	Alerts   []DeliveryServiceAlert `json:"alerts"`
+}
+
+// DeliveryService ...
+type DeliveryService struct {
+	ID                   string                 `json:"id"`
+	XMLID                string                 `json:"xmlId"`
+	Active               bool                   `json:"active"`
+	DSCP                 string                 `json:"dscp"`
+	Signed               bool                   `json:"signed"`
+	QStringIgnore        string                 `json:"qstringIgnore"`
+	GeoLimit             string                 `json:"geoLimit"`
+	GeoProvider          string                 `json:"geoProvider"`
+	HTTPBypassFQDN       string                 `json:"httpBypassFqdn"`
+	DNSBypassIP          string                 `json:"dnsBypassIp"`
+	DNSBypassIP6         string                 `json:"dnsBypassIp6"`
+	DNSBypassCname       string                 `json:"dnsBypassCname"`
+	DNSBypassTTL         string                 `json:"dnsBypassTtl"`
+	OrgServerFQDN        string                 `json:"orgServerFqdn"`
+	Type                 string                 `json:"type"`
+	ProfileName          string                 `json:"profileName"`
+	ProfileDesc          string                 `json:"profileDescription"`
+	CDNName              string                 `json:"cdnName"`
+	CCRDNSTTL            string                 `json:"ccrDnsTtl"`
+	GlobalMaxMBPS        string                 `json:"globalMaxMbps"`
+	GlobalMaxTPS         string                 `json:"globalMaxTps"`
+	LongDesc             string                 `json:"longDesc"`
+	LongDesc1            string                 `json:"longDesc1"`
+	LongDesc2            string                 `json:"longDesc2"`
+	MaxDNSAnswers        string                 `json:"maxDnsAnswers"`
+	InfoURL              string                 `json:"infoUrl"`
+	MissLat              string                 `json:"missLat"`
+	MissLong             string                 `json:"missLong"`
+	CheckPath            string                 `json:"checkPath"`
+	LastUpdated          string                 `json:"lastUpdated"`
+	Protocol             string                 `json:"protocol"`
+	IPV6RoutingEnabled   bool                   `json:"ipv6RoutingEnabled"`
+	RangeRequestHandling string                 `json:"rangeRequestHandling"`
+	HeaderRewrite        string                 `json:"headerRewrite"`
+	EdgeHeaderRewrite    string                 `json:"edgeHeaderRewrite"`
+	MidHeaderRewrite     string                 `json:"midHeaderRewrite"`
+	TRResponseHeaders    string                 `json:"trResponseHeaders"`
+	RegexRemap           string                 `json:"regexRemap"`
+	CacheURL             string                 `json:"cacheurl"`
+	RemapText            string                 `json:"remapText"`
+	MultiSiteOrigin      string                 `json:"multiSiteOrigin"`
+	DisplayName          string                 `json:"displayName"`
+	InitialDispersion    string                 `json:"initialDispersion"`
+	MatchList            []DeliveryServiceMatch `json:"matchList,omitempty"`
+}
+
+// DeliveryServiceMatch ...
+type DeliveryServiceMatch struct {
+	Type      string `json:"type"`
+	SetNumber string `json:"setNumber"`
+	Pattern   string `json:"pattern"`
+}
+
+// DeliveryServiceAlert ...
+type DeliveryServiceAlert struct {
+	Level string `json:"level"`
+	Text  string `json:"text"`
+}
+
+// DeliveryServiceStateResponse ...
+type DeliveryServiceStateResponse struct {
+	Response DeliveryServiceState `json:"response"`
+}
+
+// DeliveryServiceState ...
+type DeliveryServiceState struct {
+	Enabled  bool                    `json:"enabled"`
+	Failover DeliveryServiceFailover `json:"failover"`
+}
+
+// DeliveryServiceFailover ...
+type DeliveryServiceFailover struct {
+	Locations   []string                   `json:"locations"`
+	Destination DeliveryServiceDestination `json:"destination"`
+	Configured  bool                       `json:"configured"`
+	Enabled     bool                       `json:"enabled"`
+}
+
+// DeliveryServiceDestination ...
+type DeliveryServiceDestination struct {
+	Location string `json:"location"`
+	Type     string `json:"type"`
+}
+
+// DeliveryServiceHealthResponse ...
+type DeliveryServiceHealthResponse struct {
+	Response DeliveryServiceHealth `json:"response"`
+}
+
+// DeliveryServiceHealth ...
+type DeliveryServiceHealth struct {
+	TotalOnline  int                         `json:"totalOnline"`
+	TotalOffline int                         `json:"totalOffline"`
+	CacheGroups  []DeliveryServiceCacheGroup `json:"cacheGroups"`
+}
+
+// DeliveryServiceCacheGroup ...
+type DeliveryServiceCacheGroup struct {
+	Online  int    `json:"online"`
+	Offline int    `json:"offline"`
+	Name    string `json:"name"`
+}
+
+// DeliveryServiceCapacityResponse ...
+type DeliveryServiceCapacityResponse struct {
+	Response DeliveryServiceCapacity `json:"response"`
+}
+
+// DeliveryServiceCapacity ...
+type DeliveryServiceCapacity struct {
+	AvailablePercent   float64 `json:"availablePercent"`
+	UnavailablePercent float64 `json:"unavailablePercent"`
+	UtilizedPercent    float64 `json:"utilizedPercent"`
+	MaintenancePercent float64 `json:"maintenancePercent"`
+}
+
+// DeliveryServiceRoutingResponse ...
+type DeliveryServiceRoutingResponse struct {
+	Response DeliveryServiceRouting `json:"response"`
+}
+
+// DeliveryServiceRouting ...
+type DeliveryServiceRouting struct {
+	StaticRoute       int     `json:"staticRoute"`
+	Miss              int     `json:"miss"`
+	Geo               float64 `json:"geo"`
+	Err               int     `json:"err"`
+	CZ                float64 `json:"cz"`
+	DSR               float64 `json:"dsr"`
+	Fed               int     `json:"fed"`
+	RegionalAlternate int     `json:"regionalAlternate"`
+	RegionalDenied    int     `json:"regionalDenied"`
+}
+
+// DeliveryServiceServerResponse ...
+type DeliveryServiceServerResponse struct {
+	Response []DeliveryServiceServer `json:"response"`
+	Page     int                     `json:"page"`
+	OrderBy  string                  `json:"orderby"`
+	Limit    int                     `json:"limit"`
+}
+
+// DeliveryServiceServer ...
+type DeliveryServiceServer struct {
+	LastUpdated     string `json:"lastUpdated"`
+	Server          string `json:"server"`
+	DeliveryService string `json:"deliveryService"`
+}
+
+// DeliveryServiceSSLKeysResponse ...
+type DeliveryServiceSSLKeysResponse struct {
+	Response DeliveryServiceSSLKeys `json:"response"`
+}
+
+// DeliveryServiceSSLKeys ...
+type DeliveryServiceSSLKeys struct {
+	CDN             string                            `json:"cdn"`
+	DeliveryService string                            `json:"DeliveryService"`
+	BusinessUnit    string                            `json:"businessUnit"`
+	City            string                            `json:"city"`
+	Organization    string                            `json:"organization"`
+	Hostname        string                            `json:"hostname"`
+	Country         string                            `json:"country"`
+	State           string                            `json:"state"`
+	Version         string                            `json:"version"`
+	Certificate     DeliveryServiceSSLKeysCertificate `json:"certificate"`
+}
+
+// DeliveryServiceSSLKeysCertificate ...
+type DeliveryServiceSSLKeysCertificate struct {
+	Crt string `json:"crt"`
+	Key string `json:"key"`
+	CSR string `json:"csr"`
+}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/0b9cb5a1/traffic_ops/client/fixtures/delivery_service.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/fixtures/delivery_service.go b/traffic_ops/client/fixtures/delivery_service.go
index 9a6e66f..c7be07c 100644
--- a/traffic_ops/client/fixtures/delivery_service.go
+++ b/traffic_ops/client/fixtures/delivery_service.go
@@ -51,6 +51,19 @@ func DeliveryServices() *client.DeliveryServiceResponse {
 	}
 }
 
+// CreateDeliveryService returns a default CreateDeliveryServiceResponse to be used for testing.
+func CreateDeliveryService() *client.CreateDeliveryServiceResponse {
+	return &client.CreateDeliveryServiceResponse{
+		Response: DeliveryServices().Response[0],
+		Alerts: []client.DeliveryServiceAlert{
+			client.DeliveryServiceAlert{
+				Level: "level",
+				Text:  "text",
+			},
+		},
+	}
+}
+
 // DeliveryServiceState returns a default DeliveryServiceStateResponse to be used for testing.
 func DeliveryServiceState() *client.DeliveryServiceStateResponse {
 	dest := client.DeliveryServiceDestination{

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/0b9cb5a1/traffic_ops/client/tests/delivery_service_test.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/tests/delivery_service_test.go b/traffic_ops/client/tests/delivery_service_test.go
index e5eefef..45336b1 100644
--- a/traffic_ops/client/tests/delivery_service_test.go
+++ b/traffic_ops/client/tests/delivery_service_test.go
@@ -138,6 +138,54 @@ func TestDeliveryServiceUnauthorized(t *testing.T) {
 	}
 }
 
+func TestCreateDeliveryService(t *testing.T) {
+	resp := fixtures.CreateDeliveryService()
+	server := testHelper.ValidHTTPServer(resp)
+	defer server.Close()
+
+	var httpClient http.Client
+	to := client.Session{
+		URL:       server.URL,
+		UserAgent: &httpClient,
+	}
+
+	testHelper.Context(t, "Given the need to test a successful Traffic Ops request to create a DeliveryService")
+
+	ds, err := to.CreateDeliveryService(&client.DeliveryService{})
+	if err != nil {
+		testHelper.Error(t, "Should be able to make a request to Traffic Ops")
+	} else {
+		testHelper.Success(t, "Should be able to make a request to Traffic Ops")
+	}
+
+	actual := ds.Response.ID
+	if actual != "001" {
+		testHelper.Error(t, "Should get back \"001\" for \"Response.ID\", got: %s", actual)
+	} else {
+		testHelper.Success(t, "Should get back \"0001\" for \"Response.ID\"")
+	}
+}
+
+func TestCreateDeliveryServiceUnauthorized(t *testing.T) {
+	server := testHelper.InvalidHTTPServer(http.StatusUnauthorized)
+	defer server.Close()
+
+	var httpClient http.Client
+	to := client.Session{
+		URL:       server.URL,
+		UserAgent: &httpClient,
+	}
+
+	testHelper.Context(t, "Given the need to test a failed Traffic Ops request to create a DeliveryService")
+
+	_, err := to.CreateDeliveryService(&client.DeliveryService{})
+	if err == nil {
+		testHelper.Error(t, "Should not be able to make a request to Traffic Ops")
+	} else {
+		testHelper.Success(t, "Should not be able to make a request to Traffic Ops")
+	}
+}
+
 func TestDeliveryServiceState(t *testing.T) {
 	resp := fixtures.DeliveryServiceState()
 	server := testHelper.ValidHTTPServer(resp)


[6/6] incubator-trafficcontrol git commit: This closes #38

Posted by ne...@apache.org.
This closes #38


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/20a9d297
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/20a9d297
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/20a9d297

Branch: refs/heads/master
Commit: 20a9d29709daf1d8540b658a175f94ec66dff7ca
Parents: 0b9cb5a
Author: Dave Neuman <ne...@apache.org>
Authored: Fri Nov 4 08:30:15 2016 -0600
Committer: Dave Neuman <ne...@apache.org>
Committed: Fri Nov 4 08:30:15 2016 -0600

----------------------------------------------------------------------

----------------------------------------------------------------------



[5/6] incubator-trafficcontrol git commit: update documentation with missing fields

Posted by ne...@apache.org.
update documentation with missing fields

According to @dneuman64, these fields are present on delivery service
ssl keys responses.


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/0ca69262
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/0ca69262
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/0ca69262

Branch: refs/heads/master
Commit: 0ca69262e6f8551036e1af2e2cde3778edacfb19
Parents: 8d6067b
Author: Mike Ball <mi...@gmail.com>
Authored: Tue Nov 1 06:30:27 2016 -0400
Committer: Dave Neuman <ne...@apache.org>
Committed: Fri Nov 4 08:29:54 2016 -0600

----------------------------------------------------------------------
 .../traffic_ops_api/v12/deliveryservice.rst     | 104 +++++++++++--------
 1 file changed, 58 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/0ca69262/docs/source/development/traffic_ops_api/v12/deliveryservice.rst
----------------------------------------------------------------------
diff --git a/docs/source/development/traffic_ops_api/v12/deliveryservice.rst b/docs/source/development/traffic_ops_api/v12/deliveryservice.rst
index 379ea37..97de3c5 100644
--- a/docs/source/development/traffic_ops_api/v12/deliveryservice.rst
+++ b/docs/source/development/traffic_ops_api/v12/deliveryservice.rst
@@ -769,29 +769,33 @@ SSL Keys
 
   **Response Properties**
 
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  |    Parameter     |  Type  |                                                               Description                                                               |
-  +==================+========+=========================================================================================================================================+
-  | ``crt``          | string | base64 encoded crt file for delivery service                                                                                            |
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``csr``          | string | base64 encoded csr file for delivery service                                                                                            |
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``key``          | string | base64 encoded private key file for delivery service                                                                                    |
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``businessUnit`` | string | The business unit entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response |
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``city``         | string | The city entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response          |
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``organization`` | string | The organization entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response  |
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``hostname``     | string | The hostname entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response      |
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``country``      | string | The country entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response       |
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``state``        | string | The state entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response         |
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``version``      | string | The version of the certificate record in Riak                                                                                           |
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  |    Parameter        |  Type  |                                                               Description                                                               |
+  +=====================+========+=========================================================================================================================================+
+  | ``crt``             | string | base64 encoded crt file for delivery service                                                                                            |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``csr``             | string | base64 encoded csr file for delivery service                                                                                            |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``key``             | string | base64 encoded private key file for delivery service                                                                                    |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``cdn``             | string | The CDN entered by the user when generating certs.                                                                                      |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``deliveryservice`` | string | The delivery service entered by the user when generating certs.                                                                         |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``businessUnit``    | string | The business unit entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``city``            | string | The city entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response          |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``organization``    | string | The organization entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response  |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``hostname``        | string | The hostname entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response      |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``country``         | string | The country entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response       |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``state``           | string | The state entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response         |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``version``         | string | The version of the certificate record in Riak                                                                                           |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
 
   **Response Example** ::
 
@@ -802,6 +806,8 @@ SSL Keys
           "key": "key",
           "csr": "csr"
         },
+        "deliveryservice": "my-ds",
+        "cdn": "qa",
         "businessUnit": "CDN_Eng",
         "city": "Denver",
         "organization": "KableTown",
@@ -839,29 +845,33 @@ SSL Keys
 
   **Response Properties**
 
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  |    Parameter     |  Type  |                                                               Description                                                               |
-  +==================+========+=========================================================================================================================================+
-  | ``crt``          | string | base64 encoded crt file for delivery service                                                                                            |
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``csr``          | string | base64 encoded csr file for delivery service                                                                                            |
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``key``          | string | base64 encoded private key file for delivery service                                                                                    |
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``businessUnit`` | string | The business unit entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response |
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``city``         | string | The city entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response          |
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``organization`` | string | The organization entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response  |
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``hostname``     | string | The hostname entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response      |
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``country``      | string | The country entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response       |
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``state``        | string | The state entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response         |
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``version``      | string | The version of the certificate record in Riak                                                                                           |
-  +------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  |    Parameter        |  Type  |                                                               Description                                                               |
+  +=====================+========+=========================================================================================================================================+
+  | ``crt``             | string | base64 encoded crt file for delivery service                                                                                            |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``csr``             | string | base64 encoded csr file for delivery service                                                                                            |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``key``             | string | base64 encoded private key file for delivery service                                                                                    |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``cdn``             | string | The CDN entered by the user when generating certs.                                                                                      |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``deliveryservice`` | string | The delivery service entered by the user when generating certs.                                                                         |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``businessUnit``    | string | The business unit entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``city``            | string | The city entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response          |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``organization``    | string | The organization entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response  |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``hostname``        | string | The hostname entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response      |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``country``         | string | The country entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response       |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``state``           | string | The state entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response         |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
+  | ``version``         | string | The version of the certificate record in Riak                                                                                           |
+  +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
 
   **Response Example** ::
 
@@ -872,6 +882,8 @@ SSL Keys
           "key": "key",
           "csr": "csr"
         },
+        "deliveryservice": "my-ds",
+        "cdn": "qa",
         "businessUnit": "CDN_Eng",
         "city": "Denver",
         "organization": "KableTown",


[2/6] incubator-trafficcontrol git commit: correct documentation

Posted by ne...@apache.org.
correct documentation

Per feedback from @dneuman64


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/0cc170f0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/0cc170f0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/0cc170f0

Branch: refs/heads/master
Commit: 0cc170f08af4706540b1c5884be8779db30f37d6
Parents: 0ca6926
Author: Mike Ball <mi...@gmail.com>
Authored: Thu Nov 3 09:30:19 2016 -0400
Committer: Dave Neuman <ne...@apache.org>
Committed: Fri Nov 4 08:29:54 2016 -0600

----------------------------------------------------------------------
 .../traffic_ops_api/v12/deliveryservice.rst           | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/0cc170f0/docs/source/development/traffic_ops_api/v12/deliveryservice.rst
----------------------------------------------------------------------
diff --git a/docs/source/development/traffic_ops_api/v12/deliveryservice.rst b/docs/source/development/traffic_ops_api/v12/deliveryservice.rst
index 97de3c5..9d86ffd 100644
--- a/docs/source/development/traffic_ops_api/v12/deliveryservice.rst
+++ b/docs/source/development/traffic_ops_api/v12/deliveryservice.rst
@@ -778,9 +778,9 @@ SSL Keys
   +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
   | ``key``             | string | base64 encoded private key file for delivery service                                                                                    |
   +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``cdn``             | string | The CDN entered by the user when generating certs.                                                                                      |
+  | ``cdn``             | string | The CDN of the delivery service for which the certs were generated.                                                                     |
   +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``deliveryservice`` | string | The delivery service entered by the user when generating certs.                                                                         |
+  | ``deliveryservice`` | string | The XML ID of the delivery service for which the cert was generated.                                                                    |
   +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
   | ``businessUnit``    | string | The business unit entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response |
   +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
@@ -788,7 +788,8 @@ SSL Keys
   +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
   | ``organization``    | string | The organization entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response  |
   +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``hostname``        | string | The hostname entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response      |
+  | ``hostname``        | string | The hostname generated by Traffic Ops that is used as the common name when generating the certificate.                                  |
+  |                     |        | This will be a FQDN for DNS delivery services and a wildcard URL for HTTP delivery services.                                            |
   +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
   | ``country``         | string | The country entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response       |
   +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
@@ -854,9 +855,9 @@ SSL Keys
   +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
   | ``key``             | string | base64 encoded private key file for delivery service                                                                                    |
   +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``cdn``             | string | The CDN entered by the user when generating certs.                                                                                      |
+  | ``cdn``             | string | The CDN of the delivery service for which the certs were generated.                                                                     |
   +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``deliveryservice`` | string | The delivery service entered by the user when generating certs.                                                                         |
+  | ``deliveryservice`` | string | The XML ID of the delivery service for which the cert was generated.                                                                    |
   +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
   | ``businessUnit``    | string | The business unit entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response |
   +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
@@ -864,7 +865,8 @@ SSL Keys
   +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
   | ``organization``    | string | The organization entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response  |
   +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
-  | ``hostname``        | string | The hostname entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response      |
+  | ``hostname``        | string | The hostname generated by Traffic Ops that is used as the common name when generating the certificate.                                  |
+  |                     |        | This will be a FQDN for DNS delivery services and a wildcard URL for HTTP delivery services.                                            |
   +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+
   | ``country``         | string | The country entered by the user when generating certs.  Field is optional and if not provided by the user will not be in response       |
   +---------------------+--------+-----------------------------------------------------------------------------------------------------------------------------------------+


[3/6] incubator-trafficcontrol git commit: add client methods for fetching SSL keys

Posted by ne...@apache.org.
add client methods for fetching SSL keys

This adds two methods for fetching SSL keys via
the `traffic_ops` delivery service client:

- `DeliveryServiceSSLKeysByID`
- `DeliveryServiceSSLKeysByHostname`


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/a731bbfd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/a731bbfd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/a731bbfd

Branch: refs/heads/master
Commit: a731bbfd29b290b2b597a231b3643ae15226d718
Parents: fe5b573
Author: Mike Ball <mi...@gmail.com>
Authored: Sun Oct 30 08:20:53 2016 -0400
Committer: Dave Neuman <ne...@apache.org>
Committed: Fri Nov 4 08:29:54 2016 -0600

----------------------------------------------------------------------
 traffic_ops/client/delivery_service.go          |  46 ++++++++
 .../client/delivery_service_endpoints.go        |   8 ++
 .../client/delivery_service_endpoints_test.go   |  24 +++++
 traffic_ops/client/fixtures/delivery_service.go |  24 +++++
 .../client/tests/delivery_service_test.go       | 106 +++++++++++++++++++
 5 files changed, 208 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/a731bbfd/traffic_ops/client/delivery_service.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/delivery_service.go b/traffic_ops/client/delivery_service.go
index 7e716c3..8afb0ff 100644
--- a/traffic_ops/client/delivery_service.go
+++ b/traffic_ops/client/delivery_service.go
@@ -160,6 +160,30 @@ type DeliveryServiceServer struct {
 	DeliveryService string `json:"deliveryService"`
 }
 
+// DeliveryServiceSSLKeysResponse ...
+type DeliveryServiceSSLKeysResponse struct {
+	Response DeliveryServiceSSLKeys `json:"response"`
+}
+
+// DeliveryServiceSSLKeys ...
+type DeliveryServiceSSLKeys struct {
+	BusinessUnit string                            `json:"businessUnit"`
+	City         string                            `json:"city"`
+	Organization string                            `json:"organization"`
+	Hostname     string                            `json:"hostname"`
+	Country      string                            `json:"country"`
+	State        string                            `json:"state"`
+	Version      string                            `json:"version"`
+	Certificate  DeliveryServiceSSLKeysCertificate `json:"certificate"`
+}
+
+// DeliveryServiceSSLKeysCertificate ...
+type DeliveryServiceSSLKeysCertificate struct {
+	Crt string `json:"crt"`
+	Key string `json:"key"`
+	CSR string `json:"csr"`
+}
+
 // DeliveryServices gets an array of DeliveryServices
 func (to *Session) DeliveryServices() ([]DeliveryService, error) {
 	var data DeliveryServiceResponse
@@ -237,6 +261,28 @@ func (to *Session) DeliveryServiceServer(page, limit string) ([]DeliveryServiceS
 	return data.Response, nil
 }
 
+// DeliveryServiceSSLKeysByID gets the DeliveryServiceSSLKeys by ID
+func (to *Session) DeliveryServiceSSLKeysByID(id string) (*DeliveryServiceSSLKeys, error) {
+	var data DeliveryServiceSSLKeysResponse
+	err := get(to, deliveryServiceSSLKeysByIDEp(id), &data)
+	if err != nil {
+		return nil, err
+	}
+
+	return &data.Response, nil
+}
+
+// DeliveryServiceSSLKeysByHostname gets the DeliveryServiceSSLKeys by Hostname
+func (to *Session) DeliveryServiceSSLKeysByHostname(hostname string) (*DeliveryServiceSSLKeys, error) {
+	var data DeliveryServiceSSLKeysResponse
+	err := get(to, deliveryServiceSSLKeysByHostnameEp(hostname), &data)
+	if err != nil {
+		return nil, err
+	}
+
+	return &data.Response, nil
+}
+
 func get(to *Session, endpoint string, respStruct interface{}) error {
 	resp, err := to.request(endpoint, nil)
 	if err != nil {

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/a731bbfd/traffic_ops/client/delivery_service_endpoints.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/delivery_service_endpoints.go b/traffic_ops/client/delivery_service_endpoints.go
index 862a727..d07171f 100644
--- a/traffic_ops/client/delivery_service_endpoints.go
+++ b/traffic_ops/client/delivery_service_endpoints.go
@@ -49,3 +49,11 @@ func deliveryServiceRoutingEp(id string) string {
 func deliveryServiceServerEp(page, limit string) string {
 	return apiBase + "/deliveryserviceserver.json?page=" + page + "&limit=" + limit
 }
+
+func deliveryServiceSSLKeysByIDEp(id string) string {
+	return apiBase + dsPath + "/xmlId/" + id + "/sslkeys.json"
+}
+
+func deliveryServiceSSLKeysByHostnameEp(hostname string) string {
+	return apiBase + dsPath + "/hostname/" + hostname + "/sslkeys.json"
+}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/a731bbfd/traffic_ops/client/delivery_service_endpoints_test.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/delivery_service_endpoints_test.go b/traffic_ops/client/delivery_service_endpoints_test.go
index 93163af..f698b72 100644
--- a/traffic_ops/client/delivery_service_endpoints_test.go
+++ b/traffic_ops/client/delivery_service_endpoints_test.go
@@ -104,3 +104,27 @@ func TestDeliveryServiceServerEp(t *testing.T) {
 		testHelper.Success(t, "Should be able to get the correct delivery service server endpoint")
 	}
 }
+
+func TestDeliveryServiceSSLKeysByIDEp(t *testing.T) {
+	testHelper.Context(t, "Given the need to test that DeliveryServiceSSLKeysByID uses the correct URL")
+
+	ep := deliveryServiceSSLKeysByIDEp("123")
+	expected := "/api/1.2/deliveryservices/xmlId/123/sslkeys.json"
+	if ep != expected {
+		testHelper.Error(t, "Should get back %s for \"deliveryServiceSSLKeysByIDEp\", got: %s", expected, ep)
+	} else {
+		testHelper.Success(t, "Should be able to get the correct delivery service SSL Keys by ID endpoint")
+	}
+}
+
+func TestDeliveryServiceSSLKeysByHostnameEp(t *testing.T) {
+	testHelper.Context(t, "Given the need to test that DeliveryServiceSSLKeysByHostname uses the correct URL")
+
+	ep := deliveryServiceSSLKeysByHostnameEp("some-host")
+	expected := "/api/1.2/deliveryservices/hostname/some-host/sslkeys.json"
+	if ep != expected {
+		testHelper.Error(t, "Should get back %s for \"deliveryServiceSSLKeysByHostnameEp\", got: %s", expected, ep)
+	} else {
+		testHelper.Success(t, "Should be able to get the correct delivery service SSL Keys by hostname endpoint")
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/a731bbfd/traffic_ops/client/fixtures/delivery_service.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/fixtures/delivery_service.go b/traffic_ops/client/fixtures/delivery_service.go
index 98580d0..43f6f8c 100644
--- a/traffic_ops/client/fixtures/delivery_service.go
+++ b/traffic_ops/client/fixtures/delivery_service.go
@@ -142,3 +142,27 @@ func DeliveryServiceServer() *client.DeliveryServiceServerResponse {
 		Limit:    1,
 	}
 }
+
+// DeliveryServiceSSLKeys returns a default DeliveryServiceSSLKeysResponse to be used for testing.
+func DeliveryServiceSSLKeys() *client.DeliveryServiceSSLKeysResponse {
+	crt := client.DeliveryServiceSSLKeysCertificate{
+		Crt: "crt",
+		Key: "key",
+		CSR: "someService",
+	}
+
+	sslKeys := client.DeliveryServiceSSLKeys{
+		Certificate:  crt,
+		BusinessUnit: "businessUnit",
+		City:         "city",
+		Organization: "Kabletown",
+		Hostname:     "hostname",
+		Country:      "country",
+		State:        "state",
+		Version:      "version",
+	}
+
+	return &client.DeliveryServiceSSLKeysResponse{
+		Response: sslKeys,
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/a731bbfd/traffic_ops/client/tests/delivery_service_test.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/tests/delivery_service_test.go b/traffic_ops/client/tests/delivery_service_test.go
index 03273fe..e5eefef 100644
--- a/traffic_ops/client/tests/delivery_service_test.go
+++ b/traffic_ops/client/tests/delivery_service_test.go
@@ -414,3 +414,109 @@ func TestDeliveryServiceServerUnauthorized(t *testing.T) {
 		testHelper.Success(t, "Should not be able to make a request to Traffic Ops")
 	}
 }
+
+func TestDeliveryServiceSSLKeysByID(t *testing.T) {
+	resp := fixtures.DeliveryServiceSSLKeys()
+	server := testHelper.ValidHTTPServer(resp)
+	defer server.Close()
+
+	var httpClient http.Client
+	to := client.Session{
+		URL:       server.URL,
+		UserAgent: &httpClient,
+	}
+
+	testHelper.Context(t, "Given the need to test a successful Traffic Ops request for a DeliveryServiceSSLKeysByID")
+
+	ssl, err := to.DeliveryServiceSSLKeysByID("123")
+	if err != nil {
+		testHelper.Error(t, "Should be able to make a request to Traffic Ops")
+	} else {
+		testHelper.Success(t, "Should be able to make a request to Traffic Ops")
+	}
+
+	if ssl.Certificate.Crt != "crt" {
+		testHelper.Error(t, "Should get back \"crt\" for \"Certificte.Crt\", got: %s", ssl.Certificate.Crt)
+	} else {
+		testHelper.Success(t, "Should get back \"crt\" for \"Certificate.Crt\"")
+	}
+
+	if ssl.Organization != "Kabletown" {
+		testHelper.Error(t, "Should get back \"Kabletown\" for \"Organization\", got: %s", ssl.Organization)
+	} else {
+		testHelper.Success(t, "Should get back \"Kabletown\" for \"Organization\"")
+	}
+}
+
+func TestDeliveryServiceSSLKeysByIDUnauthorized(t *testing.T) {
+	server := testHelper.InvalidHTTPServer(http.StatusUnauthorized)
+	defer server.Close()
+
+	var httpClient http.Client
+	to := client.Session{
+		URL:       server.URL,
+		UserAgent: &httpClient,
+	}
+
+	testHelper.Context(t, "Given the need to test a failed Traffic Ops request for a DeliveryServiceSSLKeysByID")
+
+	_, err := to.DeliveryServiceSSLKeysByID("123")
+	if err == nil {
+		testHelper.Error(t, "Should not be able to make a request to Traffic Ops")
+	} else {
+		testHelper.Success(t, "Should not be able to make a request to Traffic Ops")
+	}
+}
+
+func TestDeliveryServiceSSLKeysByHostname(t *testing.T) {
+	resp := fixtures.DeliveryServiceSSLKeys()
+	server := testHelper.ValidHTTPServer(resp)
+	defer server.Close()
+
+	var httpClient http.Client
+	to := client.Session{
+		URL:       server.URL,
+		UserAgent: &httpClient,
+	}
+
+	testHelper.Context(t, "Given the need to test a successful Traffic Ops request for a DeliveryServiceSSLKeysByHostname")
+
+	ssl, err := to.DeliveryServiceSSLKeysByHostname("hostname")
+	if err != nil {
+		testHelper.Error(t, "Should be able to make a request to Traffic Ops")
+	} else {
+		testHelper.Success(t, "Should be able to make a request to Traffic Ops")
+	}
+
+	if ssl.Certificate.Crt != "crt" {
+		testHelper.Error(t, "Should get back \"crt\" for \"Certificte.Crt\", got: %s", ssl.Certificate.Crt)
+	} else {
+		testHelper.Success(t, "Should get back \"crt\" for \"Certificate.Crt\"")
+	}
+
+	if ssl.Organization != "Kabletown" {
+		testHelper.Error(t, "Should get back \"Kabletown\" for \"Organization\", got: %s", ssl.Organization)
+	} else {
+		testHelper.Success(t, "Should get back \"Kabletown\" for \"Organization\"")
+	}
+}
+
+func TestDeliveryServiceSSLKeysByHostnameUnauthorized(t *testing.T) {
+	server := testHelper.InvalidHTTPServer(http.StatusUnauthorized)
+	defer server.Close()
+
+	var httpClient http.Client
+	to := client.Session{
+		URL:       server.URL,
+		UserAgent: &httpClient,
+	}
+
+	testHelper.Context(t, "Given the need to test a failed Traffic Ops request for a DeliveryServiceSSLKeysByHostname")
+
+	_, err := to.DeliveryServiceSSLKeysByHostname("hostname")
+	if err == nil {
+		testHelper.Error(t, "Should not be able to make a request to Traffic Ops")
+	} else {
+		testHelper.Success(t, "Should not be able to make a request to Traffic Ops")
+	}
+}


[4/6] incubator-trafficcontrol git commit: add missing fields to `DeliveryServiceSSLKeys`

Posted by ne...@apache.org.
add missing fields to `DeliveryServiceSSLKeys`

This adds `CDN` and `DeliveryService` fields.


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/8d6067b2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/8d6067b2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/8d6067b2

Branch: refs/heads/master
Commit: 8d6067b2bba8d4387a52ca449f60713fda8f287d
Parents: a731bbf
Author: Mike Ball <mi...@gmail.com>
Authored: Tue Nov 1 06:22:34 2016 -0400
Committer: Dave Neuman <ne...@apache.org>
Committed: Fri Nov 4 08:29:54 2016 -0600

----------------------------------------------------------------------
 traffic_ops/client/delivery_service.go          | 18 ++++++++++--------
 traffic_ops/client/fixtures/delivery_service.go | 18 ++++++++++--------
 2 files changed, 20 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/8d6067b2/traffic_ops/client/delivery_service.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/delivery_service.go b/traffic_ops/client/delivery_service.go
index 8afb0ff..8318098 100644
--- a/traffic_ops/client/delivery_service.go
+++ b/traffic_ops/client/delivery_service.go
@@ -167,14 +167,16 @@ type DeliveryServiceSSLKeysResponse struct {
 
 // DeliveryServiceSSLKeys ...
 type DeliveryServiceSSLKeys struct {
-	BusinessUnit string                            `json:"businessUnit"`
-	City         string                            `json:"city"`
-	Organization string                            `json:"organization"`
-	Hostname     string                            `json:"hostname"`
-	Country      string                            `json:"country"`
-	State        string                            `json:"state"`
-	Version      string                            `json:"version"`
-	Certificate  DeliveryServiceSSLKeysCertificate `json:"certificate"`
+	CDN             string                            `json:"cdn"`
+	DeliveryService string                            `json:"DeliveryService"`
+	BusinessUnit    string                            `json:"businessUnit"`
+	City            string                            `json:"city"`
+	Organization    string                            `json:"organization"`
+	Hostname        string                            `json:"hostname"`
+	Country         string                            `json:"country"`
+	State           string                            `json:"state"`
+	Version         string                            `json:"version"`
+	Certificate     DeliveryServiceSSLKeysCertificate `json:"certificate"`
 }
 
 // DeliveryServiceSSLKeysCertificate ...

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/8d6067b2/traffic_ops/client/fixtures/delivery_service.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/fixtures/delivery_service.go b/traffic_ops/client/fixtures/delivery_service.go
index 43f6f8c..9a6e66f 100644
--- a/traffic_ops/client/fixtures/delivery_service.go
+++ b/traffic_ops/client/fixtures/delivery_service.go
@@ -152,14 +152,16 @@ func DeliveryServiceSSLKeys() *client.DeliveryServiceSSLKeysResponse {
 	}
 
 	sslKeys := client.DeliveryServiceSSLKeys{
-		Certificate:  crt,
-		BusinessUnit: "businessUnit",
-		City:         "city",
-		Organization: "Kabletown",
-		Hostname:     "hostname",
-		Country:      "country",
-		State:        "state",
-		Version:      "version",
+		CDN:             "cdn",
+		DeliveryService: "deliveryService",
+		Certificate:     crt,
+		BusinessUnit:    "businessUnit",
+		City:            "city",
+		Organization:    "Kabletown",
+		Hostname:        "hostname",
+		Country:         "country",
+		State:           "state",
+		Version:         "version",
 	}
 
 	return &client.DeliveryServiceSSLKeysResponse{