Browse Source

parse and inject the scheme e.g https when constructing the node address

Mark deVilliers 2 years ago
parent
commit
be1c93c746

+ 1 - 1
client/metadata/README.md

@@ -6,7 +6,7 @@ This API client was generated by the [swagger-codegen](https://github.com/swagge
6 6
 
7 7
 - API version: 
8 8
 - Package version: 1.0.0
9
-- Build date: 2017-07-13T17:00:20.181+01:00
9
+- Build date: 2017-08-14T09:58:05.106+01:00
10 10
 - Build package: class io.swagger.codegen.languages.GoClientCodegen
11 11
 
12 12
 ## Installation

+ 2 - 0
client/metadata/api_location.go

@@ -26,6 +26,8 @@ type ApiLocation struct {
26 26
 	// public port of the node
27 27
 	Port int32 `json:"port,omitempty"`
28 28
 
29
+	Scheme string `json:"scheme,omitempty"`
30
+
29 31
 	// unique identifier for a node
30 32
 	Uid string `json:"uid,omitempty"`
31 33
 }

+ 2 - 0
client/metadata/api_location_request.go

@@ -25,4 +25,6 @@ type ApiLocationRequest struct {
25 25
 
26 26
 	// public port of the node
27 27
 	Port int32 `json:"port,omitempty"`
28
+
29
+	Scheme string `json:"scheme,omitempty"`
28 30
 }

+ 1 - 0
client/metadata/docs/ApiLocation.md

@@ -5,6 +5,7 @@ Name | Type | Description | Notes
5 5
 ------------ | ------------- | ------------- | -------------
6 6
 **IpAddress** | **string** | public IP address of the node | [default to null]
7 7
 **Port** | **int32** | public port of the node | [default to null]
8
+**Scheme** | **string** |  | [default to null]
8 9
 **Uid** | **string** | unique identifier for a node | [default to null]
9 10
 
10 11
 [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

+ 1 - 0
client/metadata/docs/ApiLocationRequest.md

@@ -5,6 +5,7 @@ Name | Type | Description | Notes
5 5
 ------------ | ------------- | ------------- | -------------
6 6
 **IpAddress** | **string** | public IP address of the node | [default to null]
7 7
 **Port** | **int32** | public port of the node | [default to null]
8
+**Scheme** | **string** |  | [default to null]
8 9
 
9 10
 [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
10 11
 

+ 1 - 0
metadata/api/catalog.go

@@ -51,6 +51,7 @@ type ItemWithLocation struct {
51 51
 type LocationRequest struct {
52 52
 	IPAddress string `json:"ip-address" description:"public IP address of the node" validate:"nonzero"`
53 53
 	Port      int    `json:"port" description:"public port of the node" validate:"nonzero"`
54
+	Scheme    string `json:"scheme" description:protocol to use e.g. http or https`
54 55
 }
55 56
 
56 57
 // Location contains the original request and a UID to use when interacting with the service e.g. adding Items to the catalog.

+ 3 - 2
node/server.go

@@ -85,8 +85,8 @@ func Serve(options Options) error {
85 85
 // registerWithMetadataService returns the 'announce' token from the metadata service
86 86
 func registerWithMetadataService(client *metadataclient.MetadataApi, nodePublicAddress string) (string, error) {
87 87
 
88
-	// parse the nods public address into its component parts
89
-	ok, host, port := utils.HostAndIpToBits(nodePublicAddress)
88
+	// parse the node's public address into its component parts
89
+	ok, scheme, host, port := utils.HostAndIpToBits(nodePublicAddress)
90 90
 
91 91
 	if !ok {
92 92
 		return "", errors.New("unable to parse WEBSERVICES_URL or flag -u. Expected value : http[s]://host:port")
@@ -101,6 +101,7 @@ func registerWithMetadataService(client *metadataclient.MetadataApi, nodePublicA
101 101
 		response, _, err := client.RegisterLocation(metadataclient.ApiLocationRequest{
102 102
 			IpAddress: host,
103 103
 			Port:      int32(port),
104
+			Scheme:    scheme,
104 105
 		})
105 106
 
106 107
 		if err != nil {

+ 6 - 5
ui/node.js

@@ -14214,9 +14214,9 @@ var _user$project$Decoders$Item = F5(
14214 14214
 	function (a, b, c, d, e) {
14215 14215
 		return {key: a, location: b, sample: c, tags: d, uid: e};
14216 14216
 	});
14217
-var _user$project$Decoders$Location = F4(
14218
-	function (a, b, c, d) {
14219
-		return {ipAddress: a, ipPort: b, uid: c, right: d};
14217
+var _user$project$Decoders$Location = F5(
14218
+	function (a, b, c, d, e) {
14219
+		return {ipAddress: a, ipPort: b, scheme: c, uid: d, right: e};
14220 14220
 	});
14221 14221
 var _user$project$Decoders$DataResponse = function (a) {
14222 14222
 	return {data: a};
@@ -14256,11 +14256,12 @@ var _user$project$Decoders$decodeDevices = _elm_lang$core$Json_Decode$list(_user
14256 14256
 var _user$project$Decoders$Requesting = {ctor: 'Requesting'};
14257 14257
 var _user$project$Decoders$RequestAccess = {ctor: 'RequestAccess'};
14258 14258
 var _user$project$Decoders$Unknown = {ctor: 'Unknown'};
14259
-var _user$project$Decoders$decodeLocation = A5(
14260
-	_elm_lang$core$Json_Decode$map4,
14259
+var _user$project$Decoders$decodeLocation = A6(
14260
+	_elm_lang$core$Json_Decode$map5,
14261 14261
 	_user$project$Decoders$Location,
14262 14262
 	A2(_elm_lang$core$Json_Decode$field, 'ip-address', _elm_lang$core$Json_Decode$string),
14263 14263
 	A2(_elm_lang$core$Json_Decode$field, 'port', _elm_lang$core$Json_Decode$int),
14264
+	A2(_elm_lang$core$Json_Decode$field, 'scheme', _elm_lang$core$Json_Decode$string),
14264 14265
 	A2(_elm_lang$core$Json_Decode$field, 'uid', _elm_lang$core$Json_Decode$string),
14265 14266
 	_elm_lang$core$Json_Decode$succeed(_user$project$Decoders$Unknown));
14266 14267
 var _user$project$Decoders$decodeItem = A6(

+ 13 - 9
ui/search.js

@@ -10442,9 +10442,9 @@ var _user$project$Decoders$Item = F5(
10442 10442
 	function (a, b, c, d, e) {
10443 10443
 		return {key: a, location: b, sample: c, tags: d, uid: e};
10444 10444
 	});
10445
-var _user$project$Decoders$Location = F4(
10446
-	function (a, b, c, d) {
10447
-		return {ipAddress: a, ipPort: b, uid: c, right: d};
10445
+var _user$project$Decoders$Location = F5(
10446
+	function (a, b, c, d, e) {
10447
+		return {ipAddress: a, ipPort: b, scheme: c, uid: d, right: e};
10448 10448
 	});
10449 10449
 var _user$project$Decoders$DataResponse = function (a) {
10450 10450
 	return {data: a};
@@ -10484,11 +10484,12 @@ var _user$project$Decoders$decodeDevices = _elm_lang$core$Json_Decode$list(_user
10484 10484
 var _user$project$Decoders$Requesting = {ctor: 'Requesting'};
10485 10485
 var _user$project$Decoders$RequestAccess = {ctor: 'RequestAccess'};
10486 10486
 var _user$project$Decoders$Unknown = {ctor: 'Unknown'};
10487
-var _user$project$Decoders$decodeLocation = A5(
10488
-	_elm_lang$core$Json_Decode$map4,
10487
+var _user$project$Decoders$decodeLocation = A6(
10488
+	_elm_lang$core$Json_Decode$map5,
10489 10489
 	_user$project$Decoders$Location,
10490 10490
 	A2(_elm_lang$core$Json_Decode$field, 'ip-address', _elm_lang$core$Json_Decode$string),
10491 10491
 	A2(_elm_lang$core$Json_Decode$field, 'port', _elm_lang$core$Json_Decode$int),
10492
+	A2(_elm_lang$core$Json_Decode$field, 'scheme', _elm_lang$core$Json_Decode$string),
10492 10493
 	A2(_elm_lang$core$Json_Decode$field, 'uid', _elm_lang$core$Json_Decode$string),
10493 10494
 	_elm_lang$core$Json_Decode$succeed(_user$project$Decoders$Unknown));
10494 10495
 var _user$project$Decoders$decodeItem = A6(
@@ -10690,14 +10691,17 @@ var _user$project$Search$metadataURL = 'http://localhost:8081';
10690 10691
 var _user$project$Search$nodeURLFromLocation = function (location) {
10691 10692
 	return A2(
10692 10693
 		_elm_lang$core$Basics_ops['++'],
10693
-		'http://',
10694
+		location.scheme,
10694 10695
 		A2(
10695 10696
 			_elm_lang$core$Basics_ops['++'],
10696
-			location.ipAddress,
10697
+			'://',
10697 10698
 			A2(
10698 10699
 				_elm_lang$core$Basics_ops['++'],
10699
-				':',
10700
-				_elm_lang$core$Basics$toString(location.ipPort))));
10700
+				location.ipAddress,
10701
+				A2(
10702
+					_elm_lang$core$Basics_ops['++'],
10703
+					':',
10704
+					_elm_lang$core$Basics$toString(location.ipPort)))));
10701 10705
 };
10702 10706
 var _user$project$Search$initialModel = {all: _elm_lang$core$Maybe$Nothing, filter: _elm_lang$core$Maybe$Nothing};
10703 10707
 var _user$project$Search$unsafeDrawGraph = _elm_lang$core$Native_Platform.outgoingPort(

+ 3 - 1
ui/src/Decoders.elm

@@ -35,6 +35,7 @@ decodeItem =
35 35
 type alias Location =
36 36
     { ipAddress : String
37 37
     , ipPort : Int
38
+    , scheme : String
38 39
     , uid : String
39 40
     , right : Right
40 41
     }
@@ -48,9 +49,10 @@ type Right
48 49
 
49 50
 decodeLocation : Json.Decode.Decoder Location
50 51
 decodeLocation =
51
-    Json.Decode.map4 Location
52
+    Json.Decode.map5 Location
52 53
         (Json.Decode.field "ip-address" Json.Decode.string)
53 54
         (Json.Decode.field "port" Json.Decode.int)
55
+        (Json.Decode.field "scheme" Json.Decode.string)
54 56
         (Json.Decode.field "uid" Json.Decode.string)
55 57
         (Json.Decode.succeed Unknown)
56 58
 

+ 1 - 1
ui/src/Search.elm

@@ -149,7 +149,7 @@ prepareGraphData items =
149 149
 
150 150
 nodeURLFromLocation : Decoders.Location -> String
151 151
 nodeURLFromLocation location =
152
-    "http://" ++ location.ipAddress ++ ":" ++ toString (location.ipPort)
152
+    location.scheme ++ "://" ++ location.ipAddress ++ ":" ++ toString (location.ipPort)
153 153
 
154 154
 
155 155
 metadataURL : String

+ 6 - 6
utils/address.go

@@ -7,26 +7,26 @@ import (
7 7
 )
8 8
 
9 9
 // HostAndIpToBits parses an address parsing out the host and port
10
-// Example input - http://abc.com:1234 returns { true, abc.com, 1234 }
11
-func HostAndIpToBits(address string) (bool, string, int) {
10
+// Example input - http://abc.com:1234 returns { true, http, abc.com, 1234 }
11
+func HostAndIpToBits(address string) (bool, string, string, int) {
12 12
 
13 13
 	url, err := url.Parse(address)
14 14
 
15 15
 	if err != nil {
16
-		return false, "", 0
16
+		return false, "", "", 0
17 17
 	}
18 18
 
19 19
 	bits := strings.Split(url.Host, ":")
20 20
 
21 21
 	if len(bits) != 2 {
22
-		return false, "", 0
22
+		return false, "", "", 0
23 23
 	}
24 24
 
25 25
 	port, err := strconv.Atoi(bits[1])
26 26
 
27 27
 	if err != nil {
28
-		return false, "", 0
28
+		return false, "", "", 0
29 29
 	}
30 30
 
31
-	return true, bits[0], port
31
+	return true, url.Scheme, bits[0], port
32 32
 }