k2hr3-api 1.0.4 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ChangeLog CHANGED
@@ -1,3 +1,28 @@
1
+ k2hr3-api (1.0.8) unstable; urgency=low
2
+
3
+ * Added some host information for adding to Role member - #56
4
+
5
+ -- Takeshi Nakatani <ggtakec@gmail.com> Mon, 13 Jun 2022 09:52:47 +0900
6
+
7
+ k2hr3-api (1.0.7) unstable; urgency=low
8
+
9
+ * Bumpup version number for npm package
10
+
11
+ -- Takeshi Nakatani <ggtakec@gmail.com> Fri, 29 Oct 2021 14:32:17 +0900
12
+
13
+ k2hr3-api (1.0.6) unstable; urgency=low
14
+
15
+ * Uses OpenID Connect Discovery to set jwks_uri - #53
16
+ * Changed the workaround for the publish-please audit error - #52
17
+
18
+ -- Takeshi Nakatani <ggtakec@gmail.com> Fri, 29 Oct 2021 13:33:54 +0900
19
+
20
+ k2hr3-api (1.0.5) unstable; urgency=low
21
+
22
+ * Updated dependencies - #49
23
+
24
+ -- Takeshi Nakatani <ggtakec@gmail.com> Mon, 27 Sep 2021 15:42:39 +0900
25
+
1
26
  k2hr3-api (1.0.4) unstable; urgency=low
2
27
 
3
28
  * Enhanced the automatic registration for containers on Kubernetes - #47
@@ -34,13 +34,15 @@ var r3logger = require('./dbglogging');
34
34
  //---------------------------------------------------------
35
35
  // ipdata: IP address information
36
36
  // {
37
- // ip: ip, -> ip address string
38
- // cuk: cuk, -> cuk string (not use)
39
- // port: port, -> port number or * (not use)
40
- // extra: string -> 'openstack-auto-v1' or etc (not use)
41
- // tag: string -> null or string (not use)
42
- // key: string -> this ip address yrn full path(not use)
43
- // alive: boolean -> true or false
37
+ // ip: ip, -> ip address string
38
+ // cuk: cuk, -> cuk string (not use)
39
+ // port: port, -> port number or * (not use)
40
+ // extra: string -> 'openstack-auto-v1' or etc (not use)
41
+ // tag: string -> null or string (not use)
42
+ // inboundip: ip, -> inbound ip address (not use)
43
+ // outboundip: ip, -> outbound ip address (not use)
44
+ // key: string -> this ip address yrn full path(not use)
45
+ // alive: boolean -> true or false
44
46
  // }
45
47
  //
46
48
  function checkAddressAliveByPing(ipdata, chkipconfig, callback)
@@ -103,13 +105,15 @@ function checkAddressAliveByPing(ipdata, chkipconfig, callback)
103
105
  //---------------------------------------------------------
104
106
  // ipdata: IP address information
105
107
  // {
106
- // ip: ip, -> ip address string
107
- // cuk: cuk, -> cuk string (not use)
108
- // port: port, -> port number or * (not use)
109
- // extra: string -> 'openstack-auto-v1' or etc (not use)
110
- // tag: string -> null or string (not use)
111
- // key: string -> this ip address yrn full path(not use)
112
- // alive: boolean -> true or false
108
+ // ip: ip, -> ip address string
109
+ // cuk: cuk, -> cuk string (not use)
110
+ // port: port, -> port number or * (not use)
111
+ // extra: string -> 'openstack-auto-v1' or etc (not use)
112
+ // tag: string -> null or string (not use)
113
+ // inboundip: ip, -> inbound ip address (not use)
114
+ // outboundip: ip, -> outbound ip address (not use)
115
+ // key: string -> this ip address yrn full path(not use)
116
+ // alive: boolean -> true or false
113
117
  // }
114
118
  //
115
119
  function checkAddressAlive(ipdata, chkipconfig, callback)
@@ -199,6 +203,8 @@ function checkAddressAlive(ipdata, chkipconfig, callback)
199
203
  // cuk: <string>, -> cuk string (not use)
200
204
  // port: <number or *>, -> port number or * (not use)
201
205
  // extra: <string>, -> 'openstack-auto-v1' or etc (not use)
206
+ // inboundip: <string>, -> inbound ip address (not use)
207
+ // outboundip: <string>, -> outbound ip address (not use)
202
208
  // tag: <string>, -> null or string (not use)
203
209
  // key: <string>, -> this ip address yrn full path (not use)
204
210
  // alive: <boolean> -> true or false
@@ -286,6 +292,8 @@ function checkAddressesAliveParallel(ipdatas, start, chkipconfig, callback)
286
292
  // port: <number or *>, -> port number or * (not use)
287
293
  // extra: <string>, -> 'openstack-auto-v1' or etc (not use)
288
294
  // tag: <string>, -> null or string (not use)
295
+ // inboundip: <string>, -> inbound ip address (not use)
296
+ // outboundip: <string>, -> outbound ip address (not use)
289
297
  // key: <string>, -> this ip address yrn full path (not use)
290
298
  // alive: <boolean> -> true or false
291
299
  // }, ...]
package/lib/k2hr3dkc.js CHANGED
@@ -99,6 +99,8 @@ var is_allow_dummy_tenant = !(apiConf.isConfirmTenantForService());
99
99
  // cuk: container unique key(or null/undefined)
100
100
  // extra: string(or null/undefined)
101
101
  // tag: string(or null/undefined)
102
+ // inboundip: ip address string(or null/undefined)
103
+ // outboundip: ip address string(or null/undefined)
102
104
  // }
103
105
  // (3) array = [ object, object, ...]
104
106
  //
@@ -111,6 +113,8 @@ var is_allow_dummy_tenant = !(apiConf.isConfirmTenantForService());
111
113
  // cuk: "any string" (if not specify, the value is null or undefined)
112
114
  // extra: "explain, etc" (if not specify, the value is null or undefined)
113
115
  // tag: "tag string" (if not specify, the value is null or undefined)
116
+ // inboundip: "192.168.1.1" (if not specify, the value is null or undefined)
117
+ // outboundip: "192.168.1.1" (if not specify, the value is null or undefined)
114
118
  // },
115
119
  // ....
116
120
  // ]
@@ -143,6 +147,8 @@ function getSafeHosts(input_info)
143
147
  result = result.concat(tmp);
144
148
  }
145
149
  }else{
150
+ var host_info;
151
+
146
152
  // A case of object
147
153
  if(apiutil.isSafeString(input_info.ip) && apiutil.isIpAddressString(input_info.ip)){
148
154
  ipaddr = input_info.ip;
@@ -162,13 +168,24 @@ function getSafeHosts(input_info)
162
168
  if(apiutil.isSafeString(input_info.tag)){
163
169
  tag = input_info.tag;
164
170
  }
171
+
165
172
  // add to array(if hostname and ip address is existed, push two array)
166
173
  if(apiutil.isSafeString(ipaddr)){
167
- result.push({ip: ipaddr, hostname: null, port: portnum, cuk: cuk, extra: extra, tag: tag});
174
+ host_info = {ip: ipaddr, hostname: null, port: portnum, cuk: cuk, extra: extra, tag: tag};
168
175
  }
169
176
  if(apiutil.isSafeString(hostname)){
170
- result.push({ip: null, hostname: hostname, port: portnum, cuk: cuk, extra: extra, tag: tag});
177
+ host_info = {ip: null, hostname: hostname, port: portnum, cuk: cuk, extra: extra, tag: tag};
178
+ }
179
+
180
+ // optional keys
181
+ if(apiutil.isSafeString(input_info.inboundip) && apiutil.isIpAddressString(input_info.inboundip)){
182
+ host_info.inboundip = input_info.inboundip;
183
+ }
184
+ if(apiutil.isSafeString(input_info.outboundip) && apiutil.isIpAddressString(input_info.outboundip)){
185
+ host_info.outboundip = input_info.outboundip;
171
186
  }
187
+
188
+ result.push(host_info);
172
189
  }
173
190
  }else{
174
191
  // A case of one host name(or ip address)
@@ -2900,6 +2917,8 @@ function rawRemoveComprehensionByNewTenants(user, tenant_list)
2900
2917
  // cuk: "any string" (if not specify, the value is null or undefined)
2901
2918
  // extra: "explain, etc" (if not specify, the value is null or undefined)
2902
2919
  // tag: "tag string" (if not specify, the value is null or undefined)
2920
+ // inboundip: "192.168.1.1" (if not specify, the value is null or undefined)
2921
+ // outboundip: "192.168.1.1" (if not specify, the value is null or undefined)
2903
2922
  // }
2904
2923
  //
2905
2924
  // [NOTE] : if parent role key does not have this role key, set role key
@@ -3667,11 +3686,11 @@ function rawRemoveRoleSubkeyParentKey(dkcobj_permanent, current_key, role_top_ke
3667
3686
  // aliases: array <--- only not expand
3668
3687
  // hosts: { <--- only not expand
3669
3688
  // 'hostnames': [ hostname array or empty array
3670
- // <hostname> <port> <cuk> <extra> <tag>, (if any port, port is *)
3689
+ // <hostname> <port> <cuk> <extra> <tag> <inboundip> <outboundip>, (if any port, port is *)
3671
3690
  // ...
3672
3691
  // ],
3673
3692
  // 'ips': [ ip address array or empty array
3674
- // <ip address> <port> <cuk> <extra> <tag>,(if any port, port is *)
3693
+ // <ip address> <port> <cuk> <extra> <tag> <inboundip> <outboundip>, (if any port, port is *)
3675
3694
  // ...
3676
3695
  // ]
3677
3696
  // }
@@ -3732,11 +3751,11 @@ function rawGetRole(role, is_expand)
3732
3751
  // aliases: array <--- only not expand
3733
3752
  // hosts: { <--- only not expand
3734
3753
  // 'hostnames': [ hostname array or empty array
3735
- // <hostname> <port> <cuk> <extra> <tag>, (if any port, port is *)
3754
+ // <hostname> <port> <cuk> <extra> <tag> <inboundip> <outboundip>, (if any port, port is *)
3736
3755
  // ...
3737
3756
  // ],
3738
3757
  // 'ips': [ ip address array or empty array
3739
- // <ip address> <port> <cuk> <extra> <tag>,(if any port, port is *)
3758
+ // <ip address> <port> <cuk> <extra> <tag> <inboundip> <outboundip>, (if any port, port is *)
3740
3759
  // ...
3741
3760
  // ]
3742
3761
  // }
@@ -3870,6 +3889,8 @@ function rawGetRoles(dkcobj_permanent, role, roledata, is_expand, checked_roles,
3870
3889
  // cuk : container unique key(undefined, null means any)
3871
3890
  // extra : extra data
3872
3891
  // tag : tag data
3892
+ // inboundip : inbound ip address(optional)
3893
+ // outboundip : outbound ip address(optional)
3873
3894
  //
3874
3895
  // [NOTE]
3875
3896
  // Please specify either hostname or ip.
@@ -3879,7 +3900,7 @@ function rawGetRoles(dkcobj_permanent, role, roledata, is_expand, checked_roles,
3879
3900
  // the host is added to tenant role under service.
3880
3901
  // The service name can be allowed undefined and null.
3881
3902
  //
3882
- function rawAddHost(tenant, role, service, hostname, ip, port, cuk, extra, tag)
3903
+ function rawAddHost(tenant, role, service, hostname, ip, port, cuk, extra, tag, inboundip, outboundip)
3883
3904
  {
3884
3905
  var resobj = {result: true, message: null};
3885
3906
 
@@ -3917,6 +3938,26 @@ function rawAddHost(tenant, role, service, hostname, ip, port, cuk, extra, tag)
3917
3938
  }else{
3918
3939
  service = null;
3919
3940
  }
3941
+ if(apiutil.isSafeString(inboundip)){
3942
+ if(!apiutil.isIpAddressString(inboundip)){
3943
+ resobj.result = false;
3944
+ resobj.message = 'inbound ip address is not ignore ip address string: ' + inboundip;
3945
+ r3logger.elog(resobj.message);
3946
+ return resobj;
3947
+ }
3948
+ }else{
3949
+ inboundip = null;
3950
+ }
3951
+ if(apiutil.isSafeString(outboundip)){
3952
+ if(!apiutil.isIpAddressString(outboundip)){
3953
+ resobj.result = false;
3954
+ resobj.message = 'outbound ip address is not ignore ip address string: ' + outboundip;
3955
+ r3logger.elog(resobj.message);
3956
+ return resobj;
3957
+ }
3958
+ }else{
3959
+ outboundip = null;
3960
+ }
3920
3961
 
3921
3962
  // check role name is only name or full yrn path
3922
3963
  var keys = r3keys(null, tenant, service);
@@ -4011,6 +4052,14 @@ function rawAddHost(tenant, role, service, hostname, ip, port, cuk, extra, tag)
4011
4052
  tag: apiutil.getSafeString(tag)
4012
4053
  };
4013
4054
  /* eslint-enable indent, no-mixed-spaces-and-tabs */
4055
+
4056
+ // add optional keys
4057
+ if(apiutil.isSafeString(inboundip)){
4058
+ onehost.inboundip = inboundip;
4059
+ }
4060
+ if(apiutil.isSafeString(outboundip)){
4061
+ onehost.outboundip = outboundip;
4062
+ }
4014
4063
  hostarr.push(onehost);
4015
4064
  }
4016
4065
  }
@@ -4026,6 +4075,14 @@ function rawAddHost(tenant, role, service, hostname, ip, port, cuk, extra, tag)
4026
4075
  tag: apiutil.getSafeString(tag)
4027
4076
  };
4028
4077
  /* eslint-enable indent, no-mixed-spaces-and-tabs */
4078
+
4079
+ // add optional keys
4080
+ if(apiutil.isSafeString(inboundip)){
4081
+ onehost.inboundip = inboundip;
4082
+ }
4083
+ if(apiutil.isSafeString(outboundip)){
4084
+ onehost.outboundip = outboundip;
4085
+ }
4029
4086
  hostarr.push(onehost);
4030
4087
  }
4031
4088
  }
@@ -4064,6 +4121,8 @@ function rawAddHost(tenant, role, service, hostname, ip, port, cuk, extra, tag)
4064
4121
  // cuk: "any string" (if not specify, the value is null or undefined)
4065
4122
  // extra: "explain, etc" (if not specify, the value is null or undefined)
4066
4123
  // tag: "tag string" (if not specify, the value is null or undefined)
4124
+ // inboundip: "192.168.1.1" (if not specify, the value is null or undefined)
4125
+ // outboundip: "192.168.1.1" (if not specify, the value is null or undefined)
4067
4126
  // }
4068
4127
  //
4069
4128
  // [NOTE]
@@ -5300,13 +5359,15 @@ function rawRemoveIpsByCuk(cuk, host, remove_under_role)
5300
5359
  // error: -> null or Error object(if error)
5301
5360
  // data: [ -> data array includes ip address etc
5302
5361
  // {
5303
- // ip: ip, -> ip address string
5304
- // port: port, -> port number or *
5305
- // cuk: cuk, -> cuk string
5306
- // extra: string -> 'openstack-auto-v1' or 'k8s-auto-v1'
5307
- // tag: string -> tag string
5308
- // key: string -> this ip address yrn full path
5309
- // alive: true -> always true
5362
+ // ip: ip, -> ip address string
5363
+ // port: port, -> port number or *
5364
+ // cuk: cuk, -> cuk string
5365
+ // extra: string, -> 'openstack-auto-v1' or 'k8s-auto-v1'
5366
+ // tag: string, -> tag string
5367
+ // inboundip: ip, -> inbound ip address
5368
+ // outboundip: ip, -> outbound ip address
5369
+ // key: string, -> this ip address yrn full path
5370
+ // alive: true -> always true
5310
5371
  // },
5311
5372
  // .
5312
5373
  // .
@@ -5412,6 +5473,14 @@ function rawGetAllIpDatasByCuk(extra)
5412
5473
  host_info.key = cuk_subkeys[cnt2];
5413
5474
  host_info.alive = true;
5414
5475
 
5476
+ // Add optional keys
5477
+ if(!apiutil.isSafeString(ipvalue.inboundip) && apiutil.isIpAddressString(ipvalue.inboundip)){
5478
+ host_info.inboundip = apiutil.getSafeString(ipvalue.inboundip);
5479
+ }
5480
+ if(!apiutil.isSafeString(ipvalue.outboundip) && apiutil.isIpAddressString(ipvalue.outboundip)){
5481
+ host_info.outboundip = apiutil.getSafeString(ipvalue.outboundip);
5482
+ }
5483
+
5415
5484
  if(!is_openstack){
5416
5485
  host_info[keys.K8S_NAMESPACE_INCUK_KEY] = apiutil.getSafeString(ipvalue[keys.K8S_NAMESPACE_INCUK_KEY]);
5417
5486
  host_info[keys.K8S_SA_INCUK_KEY] = apiutil.getSafeString(ipvalue[keys.K8S_SA_INCUK_KEY]);
@@ -5608,13 +5677,16 @@ function rawRemoveIpAddressWithCuk(ipdatas, pendingsec, logger)
5608
5677
  // [
5609
5678
  // {
5610
5679
  // 'host_normal': '<hostname(ip)>{:<port>}' if any port, port value is empty
5611
- // 'host_all': '<hostname(ip)> <port> <cuk> <extra> <tag>' if any port, port is *
5680
+ // 'host_all': '<hostname(ip)> <port> <cuk> <extra> <tag> <inboundip> <outboundip>'
5681
+ // if any port, port is *
5612
5682
  // 'detail_key': '<hostname(ip)>,<port>,<cuk>' if any port, port is 0
5613
5683
  // 'detail': {
5614
5684
  // 'host': <string> hostanme or IP address string
5615
5685
  // 'port': <number> port number(if any, set 0)
5616
5686
  // 'extra': <string> 'k8s-auto-v1' or 'openstack-auto-v1' or undefined(if it does not exist)
5617
5687
  // 'tag': <string> tag string (or undefined if it does not exist)
5688
+ // 'inboundip': <string> inbound ip address (or undefined if it does not exist)
5689
+ // 'outboundip': <string> outbound ip address (or undefined if it does not exist)
5618
5690
  // 'cuk': <string> cuk string (or undefined if it does not exist)
5619
5691
  // 'k8s_namespace': <string> namespace on k8s (or undefined unless registering from k8s)
5620
5692
  // 'k8s_service_account': <string> service account on k8s(or undefined unless registering from k8s)
@@ -5681,12 +5753,14 @@ function rawGetRoleHostListsEx(dkcobj_permanent, keylist, is_hostname)
5681
5753
  r3logger.wlog('could not get key(' + JSON.stringify(keylist[cnt]) + ') value, so skip this.');
5682
5754
  continue;
5683
5755
  }
5684
- detailval = JSON.parse(detailval);
5685
- var detail_host = (is_hostname ? (apiutil.isSafeString(detailval.hostname) ? detailval.hostname : null) : (apiutil.isSafeString(detailval.ip) ? detailval.ip : null));
5686
- var detail_port = (rawIsPortAny(detailval.port) ? 0 : parseInt(detailval.port));
5687
- var detail_cuk = (apiutil.isSafeString(detailval.cuk) ? detailval.cuk : null);
5688
- var detail_extra = (apiutil.isSafeString(detailval.extra) ? detailval.extra : null);
5689
- var detail_tag = (apiutil.isSafeString(detailval.tag) ? detailval.tag : null);
5756
+ detailval = JSON.parse(detailval);
5757
+ var detail_host = (is_hostname ? (apiutil.isSafeString(detailval.hostname) ? detailval.hostname : null) : (apiutil.isSafeString(detailval.ip) ? detailval.ip : null));
5758
+ var detail_port = (rawIsPortAny(detailval.port) ? 0 : parseInt(detailval.port));
5759
+ var detail_cuk = (apiutil.isSafeString(detailval.cuk) ? detailval.cuk : null);
5760
+ var detail_extra = (apiutil.isSafeString(detailval.extra) ? detailval.extra : null);
5761
+ var detail_tag = (apiutil.isSafeString(detailval.tag) ? detailval.tag : null);
5762
+ var detail_inboundip = (apiutil.isSafeString(detailval.inboundip) && apiutil.isIpAddressString(detailval.inboundip) ? detailval.inboundip : null);
5763
+ var detail_outboundip = (apiutil.isSafeString(detailval.outboundip) && apiutil.isIpAddressString(detailval.outboundip) ? detailval.outboundip : null);
5690
5764
 
5691
5765
  // check the consistency of both values
5692
5766
  if(host !== detail_host || port !== detail_port || cuk !== detail_cuk){
@@ -5711,10 +5785,17 @@ function rawGetRoleHostListsEx(dkcobj_permanent, keylist, is_hostname)
5711
5785
  if(apiutil.isSafeString(detailval[keys.K8S_CONTAINERID_INCUK_KEY])){k8s_details[keys.K8S_CONTAINERID_INCUK_KEY] = detailval[keys.K8S_CONTAINERID_INCUK_KEY];}
5712
5786
  }
5713
5787
 
5788
+ // make parts of host_all
5789
+ var host_all_ext = (null === detail_outboundip ? '' : detail_outboundip);
5790
+ host_all_ext = (null === detail_inboundip ? '' : detail_inboundip) + keys.VALUE_HOST_SEP + host_all_ext;
5791
+ host_all_ext = (null === detail_tag ? '' : detail_tag) + keys.VALUE_HOST_SEP + host_all_ext.trimEnd();
5792
+ host_all_ext = (null === extra ? '' : extra) + keys.VALUE_HOST_SEP + host_all_ext.trimEnd();
5793
+ host_all_ext = host_all_ext.trim();
5794
+
5714
5795
  // make one result object
5715
5796
  var onehost = {};
5716
5797
  onehost.host_normal = host + (is_any_port ? '' : (keys.VALUE_HOST_REGSEP + String(port)));
5717
- onehost.host_all = host + keys.VALUE_HOST_SEP + (is_any_port ? keys.VALUE_ANY_PORT : String(port)) + keys.VALUE_HOST_SEP + (null === cuk ? '' : cuk) + (null === extra ? (null === detail_tag ? '' : keys.VALUE_HOST_SEP) : (keys.VALUE_HOST_SEP + extra)) + (null === detail_tag ? '' : (keys.VALUE_HOST_SEP + detail_tag));
5798
+ onehost.host_all = host + keys.VALUE_HOST_SEP + (is_any_port ? keys.VALUE_ANY_PORT : String(port)) + keys.VALUE_HOST_SEP + (null === cuk ? '' : cuk) + (apiutil.isSafeString(host_all_ext) ? (keys.VALUE_HOST_SEP + host_all_ext) : '');
5718
5799
  onehost.detail_key = host + keys.VALUE_HOST_DETAILSEP + (is_any_port ? '0' : String(port)) + keys.VALUE_HOST_DETAILSEP + (null === cuk ? '' : cuk);
5719
5800
  onehost.detail = k8s_details;
5720
5801
  onehost.detail.host = host;
@@ -5723,6 +5804,13 @@ function rawGetRoleHostListsEx(dkcobj_permanent, keylist, is_hostname)
5723
5804
  onehost.detail.tag = detail_tag;
5724
5805
  onehost.detail.cuk = cuk;
5725
5806
 
5807
+ if(apiutil.isSafeString(detail_inboundip)){
5808
+ onehost.detail.inboundip = detail_inboundip;
5809
+ }
5810
+ if(apiutil.isSafeString(detail_outboundip)){
5811
+ onehost.detail.outboundip = detail_outboundip;
5812
+ }
5813
+
5726
5814
  // add result
5727
5815
  resultarr.push(onehost);
5728
5816
  }
@@ -5755,11 +5843,11 @@ function rawGetRoleHostListsEx(dkcobj_permanent, keylist, is_hostname)
5755
5843
  // },
5756
5844
  // 'all': { all information
5757
5845
  // 'hostnames': [ hostname array or empty array
5758
- // '<hostname> <port> <cuk> <extra>', (if any port, port is *)
5846
+ // '<hostname> <port> <cuk> <extra> <tag> <inboundip> <outboundip>', (if any port, port is *)
5759
5847
  // ...
5760
5848
  // ],
5761
5849
  // 'ips': [ ip address array or empty array
5762
- // '<ip address> <port> <cuk> <extra>', (if any port, port is *)
5850
+ // '<ip address> <port> <cuk> <extra> <tag> <inboundip> <outboundip>', (if any port, port is *)
5763
5851
  // ...
5764
5852
  // ]
5765
5853
  // },
@@ -5771,6 +5859,8 @@ function rawGetRoleHostListsEx(dkcobj_permanent, keylist, is_hostname)
5771
5859
  // 'extra': <string> 'k8s-auto-v1' or 'openstack-auto-v1' or undefined(if it does not exist)
5772
5860
  // 'tag': <string> tag string (or undefined if it does not exist)
5773
5861
  // 'cuk': <string> cuk string (or undefined if it does not exist)
5862
+ // 'inboundip': <string> inbound ip address (or undefined if it does not exist)
5863
+ // 'outboundip': <string> outbound ip address (or undefined if it does not exist)
5774
5864
  // 'k8s_namespace': <string> namespace on k8s (or undefined unless registering from k8s)
5775
5865
  // 'k8s_service_account': <string> service account on k8s(or undefined unless registering from k8s)
5776
5866
  // 'k8s_node_name': <string> node name on k8s (or undefined unless registering from k8s)
@@ -5972,6 +6062,8 @@ function rawGetRoleHostLists(dkcobj_permanent, role_key, is_expand, base_role_to
5972
6062
  // port: port
5973
6063
  // cuk: cuk
5974
6064
  // extra: extra
6065
+ // inboundip: inbound ip address
6066
+ // outboundip: outbound ip address
5975
6067
  // tag: tag
5976
6068
  // },
5977
6069
  // ...
@@ -6091,6 +6183,8 @@ function rawFindHost(tenant, service, role, hostname, ip, port, cuk, is_strict)
6091
6183
  // cuk: container unique key
6092
6184
  // extra: extra
6093
6185
  // tag: tag
6186
+ // inboundip: inbound ip address
6187
+ // outboundip: outbound ip address
6094
6188
  // },
6095
6189
  // ...
6096
6190
  // ]
@@ -6232,6 +6326,8 @@ function rawFindRoleHost(dkcobj_permanent, role_key, hostname, ip, port, cuk, is
6232
6326
  // cuk: container unique key
6233
6327
  // extra: extra
6234
6328
  // tag: tag
6329
+ // inboundip: inbound ip address
6330
+ // outboundip: outbound ip address
6235
6331
  // },
6236
6332
  // ...
6237
6333
  // ]
@@ -6319,6 +6415,14 @@ function rawMatchHost(dkcobj_permanent, key_array, target, port, cuk, is_strict)
6319
6415
  hostobj.tag = apiutil.isSafeString(host_value.tag) ? host_value.tag : null;
6320
6416
  hostobj.hostname = apiutil.isSafeString(host_value.hostname) ? host_value.hostname : null;
6321
6417
  hostobj.ip = apiutil.isSafeString(host_value.ip) ? host_value.ip : null;
6418
+
6419
+ if(apiutil.isSafeString(host_value.inboundip) && apiutil.isIpAddressString(host_value.inboundip)){
6420
+ hostobj.inboundip = host_value.inboundip;
6421
+ }
6422
+ if(apiutil.isSafeString(host_value.outboundip) && apiutil.isIpAddressString(host_value.outboundip)){
6423
+ hostobj.outboundip = host_value.outboundip;
6424
+ }
6425
+
6322
6426
  var host_or_ip = apiutil.isSafeString(matches[4]) ? matches[4] : null;
6323
6427
 
6324
6428
  // check in target
@@ -10982,11 +11086,11 @@ exports.clearRoleAlias = function(user, tenant, role)
10982
11086
  // aliases: array <--- only not expand
10983
11087
  // hosts: { <--- only not expand
10984
11088
  // 'hostnames': [ hostname array or empty array
10985
- // <hostname> <port> <cuk> <extra> <tag>, (if any port, port is *)
11089
+ // <hostname> <port> <cuk> <extra> <tag> <inboundip> <outboundip>, (if any port, port is *)
10986
11090
  // ...
10987
11091
  // ],
10988
11092
  // 'ips': [ ip address array or empty array
10989
- // <ip address> <port> <cuk> <extra> <tag>,(if any port, port is *)
11093
+ // <ip address> <port> <cuk> <extra> <tag> <inboundip> <outboundip>, (if any port, port is *)
10990
11094
  // ...
10991
11095
  // ]
10992
11096
  // }
@@ -11002,13 +11106,13 @@ exports.getRole = function(role, is_expand)
11002
11106
  return rawGetRole(role, is_expand);
11003
11107
  };
11004
11108
 
11005
- exports.addHost = function(tenant, role, hostname, ip, port, cuk, extra, tag)
11109
+ exports.addHost = function(tenant, role, hostname, ip, port, cuk, extra, tag, inboundip, outboundip)
11006
11110
  {
11007
11111
  // [NOTE]
11008
11112
  // Now do not set hosts to role under service.
11009
11113
  // But if need to set hosts to it, you can set role as full yrn role path.
11010
11114
  //
11011
- return rawAddHost(tenant, role, null, hostname, ip, port, cuk, extra, tag);
11115
+ return rawAddHost(tenant, role, null, hostname, ip, port, cuk, extra, tag, inboundip, outboundip);
11012
11116
  };
11013
11117
 
11014
11118
  exports.removeHost = function(tenant, role, target, tg_port, tg_cuk, req_ip, req_port, req_cuk)
package/lib/k8soidc.js CHANGED
@@ -39,7 +39,6 @@
39
39
  // 'k8soidc': {
40
40
  // 'audience': '<client id for open id connect>',
41
41
  // 'issuer': '<issue url for open id connect>',
42
- // 'jwks_uri': '<jwks url for open id connect>',
43
42
  // 'usernamekey': '<user name key name in token>',
44
43
  // 'k8sapi_url': '<kubernetes api url>',
45
44
  // 'k8s_ca_path': '<CA cert file path for kubernetes api url>',
@@ -56,10 +55,6 @@
56
55
  // [issuer]
57
56
  // Set the issuer URL of Open id connect. This key and value are
58
57
  // required.
59
- // [jwks_uri]
60
- // Set the JWKS URL for Open id connect. This value is usually the
61
- // issuer URL plus '/keys'(ex. '<issuer>/keys'). This key and value
62
- // are required.
63
58
  // [usernamekey]
64
59
  // Specify the key name that is the Username set in the Token of
65
60
  // Open id connect. If there is no key representing Username in
@@ -95,16 +90,19 @@ var r3logger = require('../lib/dbglogging');
95
90
  // decode oidc token libraries
96
91
  var { decode } = require('jose/util/base64url');
97
92
  var { jwtVerify } = require('jose/jwt/verify');
98
- var { decodeProtectedHeader } = require('jose/util/decode_protected_header');
99
93
  var { createRemoteJWKSet } = require('jose/jwks/remote');
100
94
 
101
95
  // kubernetes client api
102
96
  var k8sclientapi = require('@kubernetes/client-node');
103
97
  var fs = require('fs');
104
98
 
99
+ // https library
100
+ var https = require('https');
101
+
105
102
  // const variables
106
103
  var K8S_PUBLISHER_NAME = 'K8SOIDC';
107
104
  var K8S_REGION_NAME = 'K8sCluster';
105
+ var OIDC_JWKS_URI_KEYNAME = 'jwks_uri';
108
106
 
109
107
  //
110
108
  // Global variables from configuration file
@@ -127,7 +125,6 @@ var k2hr3_k8s_sa_token = null;
127
125
  if(apiutil.isSafeEntity(oidc_config)){
128
126
  oidc_audience = oidc_config.audience;
129
127
  oidc_issuer = oidc_config.issuer;
130
- oidc_jwks_uri = oidc_config.jwks_uri;
131
128
  oidc_username = oidc_config.usernamekey;
132
129
  k8s_api_url = oidc_config.k8sapi_url;
133
130
  k8s_ca_cert = oidc_config.k8s_ca_path;
@@ -651,27 +648,70 @@ async function rawVerifyTokenAndGetUsername(token)
651
648
  issuer: oidc_issuer,
652
649
  audience: oidc_audience
653
650
  };
654
- var protectedHeader = decodeProtectedHeader(token);
655
- var JWKS = createRemoteJWKSet(new URL(oidc_jwks_uri));
656
- var { payload, protectedHeader } = await jwtVerify(token, JWKS, jwtParam).catch(function(err){ // eslint-disable-line no-unused-vars, no-redeclare
657
- r3logger.elog(err.message);
658
- throw err;
659
- });
660
651
 
661
- var userName = null;
662
- if(apiutil.isSafeString(oidc_username)){
663
- userName = payload[oidc_username];
664
- }else{
665
- if(apiutil.isSafeString(payload.sub)){
666
- userName = payload.sub;
652
+ var myPromise = function(issuer_url, conf_key){
653
+ return new Promise(function(resolve, reject){
654
+ https.get(oidc_issuer + '/.well-known/openid-configuration', function(res){
655
+ if(res.statusCode !== 200){
656
+ res.resume();
657
+ reject('statusCode should be 200, not ', res.statusCode);
658
+ }
659
+ res.setEncoding('utf8');
660
+ let rawData = '';
661
+ res.on('data', function(chunk){ rawData += chunk; });
662
+ res.on('end', function(){
663
+ var parsedData = apiutil.parseJSON(rawData);
664
+ if(apiutil.isSafeEntity(parsedData[conf_key])){
665
+ resolve(parsedData[conf_key]);
666
+ }else{
667
+ var errorMsg = ('the ' + conf_key + ' key should exist, but no such a key');
668
+ r3logger.elog(errorMsg);
669
+ reject(errorMsg);
670
+ }
671
+ });
672
+ }).on('error', function(err){
673
+ r3logger.elog(err.message);
674
+ reject(err.message);
675
+ });
676
+ });
677
+ };
678
+
679
+ // 1. Calls async here.
680
+ async function asyncFunction(){
681
+ // 2. Calls await() here.
682
+ try{
683
+ oidc_jwks_uri = await myPromise(oidc_issuer, OIDC_JWKS_URI_KEYNAME);
684
+ if(!apiutil.isSafeString(oidc_jwks_uri)){
685
+ var error = new Error('oidc_jwks_uri should be defined, but no oidc_jwks_uri.');
686
+ r3logger.elog(error.message);
687
+ throw error;
688
+ }
689
+ }catch(err){
690
+ r3logger.elog(err.message);
691
+ throw err;
667
692
  }
693
+ var JWKS = createRemoteJWKSet(new URL(oidc_jwks_uri));
694
+ var { payload, protectedHeader } = await jwtVerify(token, JWKS, jwtParam).catch(function(err){ // eslint-disable-line no-unused-vars
695
+ r3logger.elog(err.message);
696
+ throw err;
697
+ });
698
+
699
+ var userName = null;
700
+ if(apiutil.isSafeString(oidc_username)){
701
+ userName = payload[oidc_username];
702
+ }else{
703
+ if(apiutil.isSafeString(payload.sub)){
704
+ userName = payload.sub;
705
+ }
706
+ }
707
+ if(!apiutil.isSafeString(userName)){
708
+ error = new Error('failed to verify token for getting user name.');
709
+ r3logger.elog(error.message);
710
+ throw error;
711
+ }
712
+ return userName;
668
713
  }
669
- if(!apiutil.isSafeString(userName)){
670
- var error = new Error('failed to verify token for getting user name.');
671
- r3logger.elog(error.message);
672
- throw error;
673
- }
674
- return userName;
714
+ return asyncFunction();
675
715
  }
676
716
 
677
717
  function rawGetUserUnscopedTokenK8s(token, callback)
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "k2hr3-api",
3
- "version": "1.0.4",
3
+ "version": "1.0.8",
4
4
  "dependencies": {
5
- "@kubernetes/client-node": "^0.15.0",
6
- "body-parser": "^1.19.0",
7
- "config": "^3.3.6",
8
- "cookie-parser": "~1.4.5",
9
- "dateformat": "^4.5.1",
10
- "debug": "~4.3.2",
11
- "express": "^4.17.1",
12
- "jose": "^3.14.0",
5
+ "@kubernetes/client-node": "^0.16.3",
6
+ "body-parser": "^1.20.0",
7
+ "config": "^3.3.7",
8
+ "cookie-parser": "~1.4.6",
9
+ "dateformat": "^4.6.3",
10
+ "debug": "~4.3.4",
11
+ "express": "^4.18.1",
12
+ "jose": "^4.8.1",
13
13
  "k2hdkc": "^1.0.2",
14
14
  "morgan": "~1.10.0",
15
- "rotating-file-stream": "^2.1.5"
15
+ "rotating-file-stream": "^2.1.6"
16
16
  },
17
17
  "bin": {
18
18
  "k2hr3-api": "./bin/www",
@@ -28,10 +28,10 @@
28
28
  "test": "test"
29
29
  },
30
30
  "devDependencies": {
31
- "chai": "^4.3.4",
31
+ "chai": "^4.3.6",
32
32
  "chai-http": "^4.3.0",
33
- "eslint": "^7.32.0",
34
- "mocha": "^9.1.0",
33
+ "eslint": "^8.17.0",
34
+ "mocha": "^10.0.0",
35
35
  "nyc": "^15.1.0",
36
36
  "publish-please": "^5.5.2"
37
37
  },
@@ -68,30 +68,30 @@
68
68
  "test:lint": "eslint lib/*.js app.js bin/www bin/watcher routes/*.js test/*.js",
69
69
  "test:cover": "echo 'Test with coverage' && nyc --reporter=lcov --reporter=text npm run test:auto:all",
70
70
  "test:auto": "echo 'Auto test : npm run test:auto:*\n test:auto:all{:dbg}\n test:auto:version{:dbg}\n test:auto:usertokens{:dbg}\n test:auto:list{:dbg}\n test:auto:resource{:dbg}\n test:auto:policy{:dbg}\n test:auto:role{:dbg}\n test:auto:service{:dbg}\n test:auto:acr{:dbg}\n test:auto:userdata{:dbg}\n test:auto:extdata{:dbg}\n test:auto:watcher{:dbg}\n test:auto:templengine\n test:auto:templengine:async\n'",
71
- "test:auto:all": "echo 'All test' && npm run test:lint && test/auto_test.sh -t 4000 all && npm run test:auto:templengine && npm run test:auto:templengine:async && echo 'Succeed test' && echo ''",
72
- "test:auto:all:dbg": "echo 'All test with debugging' && npm run test:lint && test/auto_test.sh -t 4000 -d dbg all && echo 'Succeed test' && echo ''",
73
- "test:auto:version": "echo 'Test Version' && test/auto_test.sh -t 4000 version && echo 'Succeed test' && echo ''",
74
- "test:auto:version:dbg": "echo 'Test Version with debugging' && test/auto_test.sh -t 4000 -d dbg version && echo 'Succeed test' && echo ''",
75
- "test:auto:usertokens": "echo 'Test UserTokens' && test/auto_test.sh -t 4000 usertokens && echo 'Succeed test' && echo ''",
76
- "test:auto:usertokens:dbg": "echo 'Test UserTokens with debugging' && test/auto_test.sh -t 4000 -d dbg usertokens && echo 'Succeed test' && echo ''",
77
- "test:auto:list": "echo 'Test List' && test/auto_test.sh -t 4000 list && echo 'Succeed test' && echo ''",
78
- "test:auto:list:dbg": "echo 'Test List with debugging' && test/auto_test.sh -t 4000 -d dbg list && echo 'Succeed test' && echo ''",
79
- "test:auto:resource": "echo 'Test Resource' && test/auto_test.sh -t 4000 resource && echo 'Succeed test' && echo ''",
80
- "test:auto:resource:dbg": "echo 'Test Resource with debugging' && test/auto_test.sh -t 4000 -d dbg resource && echo 'Succeed test' && echo ''",
81
- "test:auto:policy": "echo 'Test Policy' && test/auto_test.sh -t 4000 policy && echo 'Succeed test' && echo ''",
82
- "test:auto:policy:dbg": "echo 'Test Policy with debugging' && test/auto_test.sh -t 4000 -d dbg policy && echo 'Succeed test' && echo ''",
83
- "test:auto:role": "echo 'Test Role' && test/auto_test.sh -t 4000 role && echo 'Succeed test' && echo ''",
84
- "test:auto:role:dbg": "echo 'Test Role with debugging' && test/auto_test.sh -t 4000 -d dbg role && echo 'Succeed test' && echo ''",
85
- "test:auto:service": "echo 'Test Service' && test/auto_test.sh -t 4000 service && echo 'Succeed test' && echo ''",
86
- "test:auto:service:dbg": "echo 'Test Service with debugging' && test/auto_test.sh -t 4000 -d dbg service && echo 'Succeed test' && echo ''",
87
- "test:auto:acr": "echo 'Test ACR' && test/auto_test.sh -t 4000 acr && echo 'Succeed test' && echo ''",
88
- "test:auto:acr:dbg": "echo 'Test ACR with debugging' && test/auto_test.sh -t 4000 -d dbg acr && echo 'Succeed test' && echo ''",
89
- "test:auto:userdata": "echo 'Test Userdata' && test/auto_test.sh -t 4000 userdata && echo 'Succeed test' && echo ''",
90
- "test:auto:userdata:dbg": "echo 'Test Userdata with debugging' && test/auto_test.sh -t 4000 -d dbg userdata && echo 'Succeed test' && echo ''",
91
- "test:auto:extdata": "echo 'Test Extdata' && test/auto_test.sh -t 4000 extdata && echo 'Succeed test' && echo ''",
92
- "test:auto:extdata:dbg": "echo 'Test Extdata with debugging' && test/auto_test.sh -t 4000 -d dbg extdata && echo 'Succeed test' && echo ''",
93
- "test:auto:watcher": "echo 'Test Watcher Process' && test/auto_test.sh -t 4000 watcher && echo 'Succeed test' && echo ''",
94
- "test:auto:watcher:dbg": "echo 'Test Watcher Process with debugging' && test/auto_test.sh -t 4000 -d dbg watcher && echo 'Succeed test' && echo ''",
71
+ "test:auto:all": "echo 'All test' && npm run test:lint && test/auto_test.sh -t 8000 all && npm run test:auto:templengine && npm run test:auto:templengine:async && echo 'Succeed test' && echo ''",
72
+ "test:auto:all:dbg": "echo 'All test with debugging' && npm run test:lint && test/auto_test.sh -t 8000 -d dbg all && echo 'Succeed test' && echo ''",
73
+ "test:auto:version": "echo 'Test Version' && test/auto_test.sh -t 8000 version && echo 'Succeed test' && echo ''",
74
+ "test:auto:version:dbg": "echo 'Test Version with debugging' && test/auto_test.sh -t 8000 -d dbg version && echo 'Succeed test' && echo ''",
75
+ "test:auto:usertokens": "echo 'Test UserTokens' && test/auto_test.sh -t 8000 usertokens && echo 'Succeed test' && echo ''",
76
+ "test:auto:usertokens:dbg": "echo 'Test UserTokens with debugging' && test/auto_test.sh -t 8000 -d dbg usertokens && echo 'Succeed test' && echo ''",
77
+ "test:auto:list": "echo 'Test List' && test/auto_test.sh -t 8000 list && echo 'Succeed test' && echo ''",
78
+ "test:auto:list:dbg": "echo 'Test List with debugging' && test/auto_test.sh -t 8000 -d dbg list && echo 'Succeed test' && echo ''",
79
+ "test:auto:resource": "echo 'Test Resource' && test/auto_test.sh -t 8000 resource && echo 'Succeed test' && echo ''",
80
+ "test:auto:resource:dbg": "echo 'Test Resource with debugging' && test/auto_test.sh -t 8000 -d dbg resource && echo 'Succeed test' && echo ''",
81
+ "test:auto:policy": "echo 'Test Policy' && test/auto_test.sh -t 8000 policy && echo 'Succeed test' && echo ''",
82
+ "test:auto:policy:dbg": "echo 'Test Policy with debugging' && test/auto_test.sh -t 8000 -d dbg policy && echo 'Succeed test' && echo ''",
83
+ "test:auto:role": "echo 'Test Role' && test/auto_test.sh -t 8000 role && echo 'Succeed test' && echo ''",
84
+ "test:auto:role:dbg": "echo 'Test Role with debugging' && test/auto_test.sh -t 8000 -d dbg role && echo 'Succeed test' && echo ''",
85
+ "test:auto:service": "echo 'Test Service' && test/auto_test.sh -t 8000 service && echo 'Succeed test' && echo ''",
86
+ "test:auto:service:dbg": "echo 'Test Service with debugging' && test/auto_test.sh -t 8000 -d dbg service && echo 'Succeed test' && echo ''",
87
+ "test:auto:acr": "echo 'Test ACR' && test/auto_test.sh -t 8000 acr && echo 'Succeed test' && echo ''",
88
+ "test:auto:acr:dbg": "echo 'Test ACR with debugging' && test/auto_test.sh -t 8000 -d dbg acr && echo 'Succeed test' && echo ''",
89
+ "test:auto:userdata": "echo 'Test Userdata' && test/auto_test.sh -t 8000 userdata && echo 'Succeed test' && echo ''",
90
+ "test:auto:userdata:dbg": "echo 'Test Userdata with debugging' && test/auto_test.sh -t 8000 -d dbg userdata && echo 'Succeed test' && echo ''",
91
+ "test:auto:extdata": "echo 'Test Extdata' && test/auto_test.sh -t 8000 extdata && echo 'Succeed test' && echo ''",
92
+ "test:auto:extdata:dbg": "echo 'Test Extdata with debugging' && test/auto_test.sh -t 8000 -d dbg extdata && echo 'Succeed test' && echo ''",
93
+ "test:auto:watcher": "echo 'Test Watcher Process' && test/auto_test.sh -t 8000 watcher && echo 'Succeed test' && echo ''",
94
+ "test:auto:watcher:dbg": "echo 'Test Watcher Process with debugging' && test/auto_test.sh -t 8000 -d dbg watcher && echo 'Succeed test' && echo ''",
95
95
  "test:auto:templengine": "echo 'Test template engine' && test/auto_template.sh && echo 'Succeed test' && echo ''",
96
96
  "test:auto:templengine:async": "echo 'Test asynchronous template engine' && test/auto_template.sh -a && echo 'Succeed test' && echo ''",
97
97
  "test:manual": "echo 'Manual test : npm run test:manual:*\n test:manual:apis:version_get\n test:manual:apis:usertoken_postput\n test:manual:apis:usertoken_gethead\n test:manual:apis:policy_postput\n test:manual:apis:policy_gethead\n test:manual:apis:policy_delete\n test:manual:apis:resource_postput\n test:manual:apis:resource_gethead\n test:manual:apis:resource_delete\n test:manual:apis:role_postput\n test:manual:apis:role_gethead\n test:manual:apis:role_delete\n test:manual:apis:service_postput\n test:manual:apis:service_gethead\n test:manual:apis:service_delete\n test:manual:apis:acr_postput\n test:manual:apis:acr_get\n test:manual:apis:acr_delete\n test:manual:apis:list_gethead\n test:manual:apis:userdata_get\n test:manual:apis:extdata_get\n test:manual:apis:allusertenant_get\n test:manual:apis:k2hr3keys_get\n test:manual:load:k2hdkcdata:auto\n test:manual:load:k2hdkcdata:local\n test:manual:templengine\n test:manual:templengine:async\n'",
package/routes/role.js CHANGED
@@ -560,6 +560,10 @@ function putRole(req, res, next) // eslint-disable-line no-unused-vars
560
560
  // extra is any string including Control code, allowed null and '' for this value.
561
561
  // "tag": <string data> => key is "yrn:yahoo:<service>::<tenant>:role:<role>/hosts/..."
562
562
  // tag is any string including Control code, allowed null and '' for this value.
563
+ // "inboundip": <ip address> => key is "yrn:yahoo:<service>::<tenant>:role:<role>/hosts/..."
564
+ // inboundip is set ip address string. if you do not use proxy/gateway/bridge/etc, you do not need to set this key.
565
+ // "outboundip": <ip address> => key is "yrn:yahoo:<service>::<tenant>:role:<role>/hosts/..."
566
+ // outboundip is set ip address string. if you do not use proxy/gateway/bridge/etc, you do not need to set this key.
563
567
  // }
564
568
  // "clear_hostname": <true/false>
565
569
  // "clear_ips": <true/false>
@@ -568,11 +572,13 @@ function putRole(req, res, next) // eslint-disable-line no-unused-vars
568
572
  // {
569
573
  // "host": [ => specified host as Array(only POST request has this type)
570
574
  // {
571
- // "host": <hostname / ip address>
572
- // "port": <port number>
573
- // "cuk": <container unique key>
574
- // "extra": <extra string data>
575
- // "tag": <string data>
575
+ // "host": <hostname / ip address>
576
+ // "port": <port number>
577
+ // "cuk": <container unique key>
578
+ // "extra": <extra string data>
579
+ // "tag": <string data>
580
+ // "inboundip": <ip address>
581
+ // "outboundip": <ip address>
576
582
  // }
577
583
  // ...
578
584
  // ]
@@ -592,6 +598,10 @@ function putRole(req, res, next) // eslint-disable-line no-unused-vars
592
598
  // extra is any string including Control code, allowed null and '' for this value.
593
599
  // "tag": <string data> => key is "yrn:yahoo:<service>::<tenant>:role:<role>/hosts/..."
594
600
  // tag is any string including Control code, allowed null and '' for this value.
601
+ // "inboundip": <ip address> => key is "yrn:yahoo:<service>::<tenant>:role:<role>/hosts/..."
602
+ // inboundip is set ip address string. if you do not use proxy/gateway/bridge/etc, you do not need to set this key.
603
+ // "outboundip": <ip address> => key is "yrn:yahoo:<service>::<tenant>:role:<role>/hosts/..."
604
+ // outboundip is set ip address string. if you do not use proxy/gateway/bridge/etc, you do not need to set this key.
595
605
  // }
596
606
  // }
597
607
  //
@@ -671,6 +681,7 @@ function postRoleHost(role, req, res, next) // eslint-disable-line no-unu
671
681
  var cuk;
672
682
  var extra;
673
683
  var tag;
684
+ var host_info;
674
685
  if(!is_host_req){
675
686
  //
676
687
  // request from user token
@@ -745,25 +756,63 @@ function postRoleHost(role, req, res, next) // eslint-disable-line no-unu
745
756
  tag = apiutil.getSafeString(hostArray[cnt].tag);
746
757
  }
747
758
 
748
- // set to array
759
+ // set base host information
749
760
  if(null !== tg_host){
750
- hostnameArray.push({
761
+ host_info = {
751
762
  ip: null,
752
763
  hostname: tg_host,
753
764
  port: port,
754
765
  cuk: cuk,
755
766
  extra: extra,
756
767
  tag: tag
757
- });
768
+ };
758
769
  }else{ // null !== tg_ip
759
- ipArray.push({
770
+ host_info = {
760
771
  ip: tg_ip,
761
772
  hostname: null,
762
773
  port: port,
763
774
  cuk: cuk,
764
775
  extra: extra,
765
776
  tag: tag
766
- });
777
+ };
778
+ }
779
+
780
+ // set optional keys
781
+ if(apiutil.isSafeString(hostArray[cnt].inboundip)){
782
+ if(!apiutil.isIpAddressString(hostArray[cnt].inboundip)){
783
+ /* eslint-disable indent, no-mixed-spaces-and-tabs */
784
+ result = {
785
+ result: false,
786
+ message: 'POST request has inbound ip address which is not ignore ip address string: ' + JSON.stringify(hostArray[cnt].inboundip)
787
+ };
788
+ /* eslint-enable indent, no-mixed-spaces-and-tabs */
789
+ r3logger.elog(result.message);
790
+ resutil.errResponse(req, res, 400, result); // 400: Bad Request
791
+ return;
792
+ }
793
+ host_info.inboundip = apiutil.getSafeString(hostArray[cnt].inboundip);
794
+ }
795
+
796
+ if(apiutil.isSafeString(hostArray[cnt].outboundip)){
797
+ if(!apiutil.isIpAddressString(hostArray[cnt].outboundip)){
798
+ /* eslint-disable indent, no-mixed-spaces-and-tabs */
799
+ result = {
800
+ result: false,
801
+ message: 'POST request has outbound ip address which is not ignore ip address string: ' + JSON.stringify(hostArray[cnt].outboundip)
802
+ };
803
+ /* eslint-enable indent, no-mixed-spaces-and-tabs */
804
+ r3logger.elog(result.message);
805
+ resutil.errResponse(req, res, 400, result); // 400: Bad Request
806
+ return;
807
+ }
808
+ host_info.outboundip = apiutil.getSafeString(hostArray[cnt].outboundip);
809
+ }
810
+
811
+ // push array
812
+ if(null !== tg_host){
813
+ hostnameArray.push(host_info);
814
+ }else{ // null !== tg_ip
815
+ ipArray.push(host_info);
767
816
  }
768
817
  }
769
818
  if(apiutil.isEmptyArray(hostnameArray)){
@@ -849,10 +898,44 @@ function postRoleHost(role, req, res, next) // eslint-disable-line no-unu
849
898
  }
850
899
  }
851
900
 
901
+ // inboundip(optional)
902
+ var inboundip = null;
903
+ if(apiutil.isSafeString(req.body.host.inboundip)){
904
+ if(!apiutil.isIpAddressString(req.body.host.inboundip)){
905
+ /* eslint-disable indent, no-mixed-spaces-and-tabs */
906
+ result = {
907
+ result: false,
908
+ message: 'POST request has inbound ip address which is not ignore ip address string: ' + JSON.stringify(req.body.host.inboundip)
909
+ };
910
+ /* eslint-enable indent, no-mixed-spaces-and-tabs */
911
+ r3logger.elog(result.message);
912
+ resutil.errResponse(req, res, 400, result); // 400: Bad Request
913
+ return;
914
+ }
915
+ inboundip = apiutil.getSafeString(req.body.host.inboundip);
916
+ }
917
+
918
+ // outboundip(optional)
919
+ var outboundip = null;
920
+ if(apiutil.isSafeString(req.body.host.outboundip)){
921
+ if(!apiutil.isIpAddressString(req.body.host.outboundip)){
922
+ /* eslint-disable indent, no-mixed-spaces-and-tabs */
923
+ result = {
924
+ result: false,
925
+ message: 'POST request has outbound ip address which is not ignore ip address string: ' + JSON.stringify(req.body.host.outboundip)
926
+ };
927
+ /* eslint-enable indent, no-mixed-spaces-and-tabs */
928
+ r3logger.elog(result.message);
929
+ resutil.errResponse(req, res, 400, result); // 400: Bad Request
930
+ return;
931
+ }
932
+ outboundip = apiutil.getSafeString(req.body.host.outboundip);
933
+ }
934
+
852
935
  //
853
936
  // Add ip address ---> Role Token or User Token
854
937
  //
855
- result = k2hr3.addHost(token_info.tenant, name, null, ip, port, cuk, extra, tag);
938
+ result = k2hr3.addHost(token_info.tenant, name, null, ip, port, cuk, extra, tag, inboundip, outboundip);
856
939
  }
857
940
 
858
941
  //------------------------------
@@ -905,6 +988,10 @@ function postRoleHost(role, req, res, next) // eslint-disable-line no-unu
905
988
  // "tag": <string data> => key is "yrn:yahoo:<service>::<tenant>:role:<role>/hosts/..."
906
989
  // This value must be encoded by JSON.
907
990
  // tag is any string including Control code, allowed null and '' for this value.
991
+ // "inboundip": <ip address> => key is "yrn:yahoo:<service>::<tenant>:role:<role>/hosts/..."
992
+ // inboundip is set ip address string. if you do not use proxy/gateway/bridge/etc, you do not need to set this key.
993
+ // "outboundip": <ip address> => key is "yrn:yahoo:<service>::<tenant>:role:<role>/hosts/..."
994
+ // outboundip is set ip address string. if you do not use proxy/gateway/bridge/etc, you do not need to set this key.
908
995
  //
909
996
  // [RoleToken] url argument
910
997
  // "port": <port number> => key is "yrn:yahoo:<service>::<tenant>:role:<role>/hosts/ip/<ip port cuk>"
@@ -918,6 +1005,10 @@ function postRoleHost(role, req, res, next) // eslint-disable-line no-unu
918
1005
  // "tag": <string data> => key is "yrn:yahoo:<service>::<tenant>:role:<role>/hosts/..."
919
1006
  // This value must be encoded by JSON.
920
1007
  // tag is any string including Control code, allowed null and '' for this value.
1008
+ // "inboundip": <ip address> => key is "yrn:yahoo:<service>::<tenant>:role:<role>/hosts/..."
1009
+ // inboundip is set ip address string. if you do not use proxy/gateway/bridge/etc, you do not need to set this key.
1010
+ // "outboundip": <ip address> => key is "yrn:yahoo:<service>::<tenant>:role:<role>/hosts/..."
1011
+ // outboundip is set ip address string. if you do not use proxy/gateway/bridge/etc, you do not need to set this key.
921
1012
  //
922
1013
  // [NOTE]
923
1014
  // This API only set(add/create) host into role. Ether hostname or ip address must be specified.
@@ -1079,9 +1170,45 @@ function putRoleHost(role, req, res, next) // eslint-disable-line no-unus
1079
1170
  tag = null;
1080
1171
  }
1081
1172
 
1082
- // make host information
1173
+ // make base host information
1083
1174
  var host_info = { ip: ip, hostname: hostname, port: port, cuk: cuk, extra: extra, tag: tag };
1084
1175
 
1176
+ // set inboundip(optional)
1177
+ var inboundip = null;
1178
+ if(apiutil.isSafeString(req.query.inboundip)){
1179
+ if(!apiutil.isIpAddressString(req.query.inboundip)){
1180
+ /* eslint-disable indent, no-mixed-spaces-and-tabs */
1181
+ result = {
1182
+ result: false,
1183
+ message: 'PUT request has inbound ip address which is not ignore ip address string: ' + JSON.stringify(req.query.inboundip)
1184
+ };
1185
+ /* eslint-enable indent, no-mixed-spaces-and-tabs */
1186
+ r3logger.elog(result.message);
1187
+ resutil.errResponse(req, res, 400, result); // 400: Bad Request
1188
+ return;
1189
+ }
1190
+ inboundip = apiutil.getSafeString(req.query.inboundip);
1191
+ host_info.inboundip = inboundip;
1192
+ }
1193
+
1194
+ // set outboundip(optional)
1195
+ var outboundip = null;
1196
+ if(apiutil.isSafeString(req.query.outboundip)){
1197
+ if(!apiutil.isIpAddressString(req.query.outboundip)){
1198
+ /* eslint-disable indent, no-mixed-spaces-and-tabs */
1199
+ result = {
1200
+ result: false,
1201
+ message: 'PUT request has outbound ip address which is not ignore ip address string: ' + JSON.stringify(req.query.outboundip)
1202
+ };
1203
+ /* eslint-enable indent, no-mixed-spaces-and-tabs */
1204
+ r3logger.elog(result.message);
1205
+ resutil.errResponse(req, res, 400, result); // 400: Bad Request
1206
+ return;
1207
+ }
1208
+ outboundip = apiutil.getSafeString(req.query.outboundip);
1209
+ host_info.outboundip= outboundip;
1210
+ }
1211
+
1085
1212
  //------------------------------
1086
1213
  // add host to role
1087
1214
  //------------------------------
@@ -1094,7 +1221,7 @@ function putRoleHost(role, req, res, next) // eslint-disable-line no-unus
1094
1221
  }
1095
1222
  }else{
1096
1223
  // Add ip address ---> Role Token or User Token
1097
- result = k2hr3.addHost(token_info.tenant, name, null, ip, port, cuk, extra, tag);
1224
+ result = k2hr3.addHost(token_info.tenant, name, null, ip, port, cuk, extra, tag, inboundip, outboundip);
1098
1225
  }
1099
1226
  if(!apiutil.isSafeEntity(result) || !apiutil.isSafeEntity(result.result) || false === result.result){
1100
1227
  if(!apiutil.isSafeEntity(result)){
@@ -40,19 +40,19 @@ exports.start = function(parentobj)
40
40
  //
41
41
  // Run chmpx for server node
42
42
  //
43
- var result = execSync('test/auto_control_subprocess.sh -start -key server -int 1 chmpx -conf test/auto_k2hdkc_server.ini -ctlport 18021 -d msg');
43
+ var result = execSync('test/auto_control_subprocess.sh -start -key server -int 3 chmpx -conf test/auto_k2hdkc_server.ini -ctlport 18021 -d msg');
44
44
  console.log(' - run chmpx for server node: ' + String(result).replace(/\r?\n$/g, ''));
45
45
 
46
46
  //
47
47
  // Run k2hdkc
48
48
  //
49
- result = execSync('test/auto_control_subprocess.sh -start -key server -int 1 k2hdkc -conf test/auto_k2hdkc_server.ini -ctlport 18021 -d msg');
49
+ result = execSync('test/auto_control_subprocess.sh -start -key server -int 3 k2hdkc -conf test/auto_k2hdkc_server.ini -ctlport 18021 -d msg');
50
50
  console.log(' - run k2hdkc: ' + String(result).replace(/\r?\n$/g, ''));
51
51
 
52
52
  //
53
53
  // Run chmpx for slave node
54
54
  //
55
- result = execSync('test/auto_control_subprocess.sh -start -key slave -int 1 chmpx -conf test/auto_k2hdkc_slave.ini -ctlport 18031 -d msg');
55
+ result = execSync('test/auto_control_subprocess.sh -start -key slave -int 3 chmpx -conf test/auto_k2hdkc_slave.ini -ctlport 18031 -d msg');
56
56
  console.log(' - run chmpx for slave node: ' + String(result).replace(/\r?\n$/g, ''));
57
57
 
58
58
  //
@@ -83,19 +83,19 @@ exports.stop = function(parentobj)
83
83
  //
84
84
  // Stop chmpx for slave node
85
85
  //
86
- var result = execSync('test/auto_control_subprocess.sh -stop -key slave -int 1 chmpx');
86
+ var result = execSync('test/auto_control_subprocess.sh -stop -key slave -int 3 chmpx');
87
87
  console.log(' - stop chmpx for slave node: ' + String(result).replace(/\r?\n$/g, ''));
88
88
 
89
89
  //
90
90
  // Stop k2hdkc
91
91
  //
92
- result = execSync('test/auto_control_subprocess.sh -stop -key server -int 1 k2hdkc');
92
+ result = execSync('test/auto_control_subprocess.sh -stop -key server -int 3 k2hdkc');
93
93
  console.log(' - stop k2hdkc: ' + String(result).replace(/\r?\n$/g, ''));
94
94
 
95
95
  //
96
96
  // Stop chmpx for slave node
97
97
  //
98
- result = execSync('test/auto_control_subprocess.sh -stop -key server -int 1 chmpx');
98
+ result = execSync('test/auto_control_subprocess.sh -stop -key server -int 3 chmpx');
99
99
  console.log(' - stop chmpx for server node: ' + String(result).replace(/\r?\n$/g, ''));
100
100
 
101
101
  //
@@ -146,7 +146,7 @@ function postV1Role(method, token, name, policies, alias)
146
146
  req.end();
147
147
  }
148
148
 
149
- function postV1RoleHost(method, is_user_token, token, name, target_host, port, cuk, extra, tag)
149
+ function postV1RoleHost(method, is_user_token, token, name, target_host, port, cuk, extra, tag, inboundip, outboundip)
150
150
  {
151
151
  /* eslint-disable indent, no-mixed-spaces-and-tabs */
152
152
  var strbody = '';
@@ -172,6 +172,13 @@ function postV1RoleHost(method, is_user_token, token, name, target_host, port, c
172
172
  host_info.extra = extra;
173
173
  host_info.tag = tag;
174
174
 
175
+ if(apiutil.isSafeString(inboundip)){ // not need to check ip address
176
+ host_info.inboundip = inboundip;
177
+ }
178
+ if(apiutil.isSafeString(outboundip)){ // not need to check ip address
179
+ host_info.outboundip = outboundip;
180
+ }
181
+
175
182
  var body = { 'host': host_info };
176
183
 
177
184
  strbody = JSON.stringify(body);
@@ -208,6 +215,17 @@ function postV1RoleHost(method, is_user_token, token, name, target_host, port, c
208
215
  urlarg += JSON.stringify(tag); // if tag is existing, it includes control codes, so it is converted to JSON.
209
216
  already_set = true;
210
217
  }
218
+ if(apiutil.isSafeString(inboundip)){ // not need to check ip address
219
+ urlarg += already_set ? '&inboundip=' : '?inboundip=';
220
+ urlarg += inboundip;
221
+ already_set = true;
222
+ }
223
+ if(apiutil.isSafeString(outboundip)){ // not need to check ip address
224
+ urlarg += already_set ? '&outboundip=' : '?outboundip=';
225
+ urlarg += outboundip;
226
+ already_set = true;
227
+ }
228
+
211
229
  headers['Content-Length'] = 0;
212
230
  options.headers = headers;
213
231
  options.path = '/v1/role/' + name + encodeURI(urlarg);
@@ -425,25 +443,51 @@ function inputHostType(method)
425
443
  _tag = tag;
426
444
  }
427
445
 
428
- if(!_is_user_token){
429
- // run
430
- postV1RoleHost(_method, _is_user_token, _token, _name, null, _port, _cuk, _extra, _tag);
431
- }else{
432
-
433
- cliutil.getConsoleInput(' Host(specify hostname or ip address) : ', true, false, function(isbreak, target_host)
446
+ cliutil.getConsoleInput(' Inbound IP address - null or string : ', true, false, function(isbreak, inbound)
447
+ {
448
+ if(isbreak){
449
+ process.exit(0);
450
+ }
451
+ var _inbound;
452
+ if('' === apiutil.getSafeString(inbound) || apiutil.compareCaseString('null', apiutil.getSafeString(inbound))){
453
+ _inbound = null;
454
+ }else{
455
+ _inbound = inbound;
456
+ }
457
+
458
+ cliutil.getConsoleInput(' Outbound IP address - null or string : ', true, false, function(isbreak, outbound)
434
459
  {
435
460
  if(isbreak){
436
461
  process.exit(0);
437
462
  }
438
- if(!apiutil.isSafeString(target_host)){
439
- process.exit(0);
463
+ var _outbound;
464
+ if('' === apiutil.getSafeString(outbound) || apiutil.compareCaseString('null', apiutil.getSafeString(outbound))){
465
+ _outbound = null;
466
+ }else{
467
+ _outbound = outbound;
440
468
  }
441
- var _target_host = target_host;
442
469
 
443
- // run
444
- postV1RoleHost(_method, _is_user_token, _token, _name, _target_host, _port, _cuk, _extra, _tag);
470
+ if(!_is_user_token){
471
+ // run
472
+ postV1RoleHost(_method, _is_user_token, _token, _name, null, _port, _cuk, _extra, _tag, _inbound, _outbound);
473
+ }else{
474
+
475
+ cliutil.getConsoleInput(' Host(specify hostname or ip address) : ', true, false, function(isbreak, target_host)
476
+ {
477
+ if(isbreak){
478
+ process.exit(0);
479
+ }
480
+ if(!apiutil.isSafeString(target_host)){
481
+ process.exit(0);
482
+ }
483
+ var _target_host = target_host;
484
+
485
+ // run
486
+ postV1RoleHost(_method, _is_user_token, _token, _name, _target_host, _port, _cuk, _extra, _tag, _inbound, _outbound);
487
+ });
488
+ }
445
489
  });
446
- }
490
+ });
447
491
  });
448
492
  });
449
493
  });
@@ -84,7 +84,7 @@ if [ ${IS_SCRIPT_MODE} -eq 1 ]; then
84
84
  #
85
85
  echo "*** Start : chmpx server node for k2hdkc"
86
86
  echo -n " "
87
- ${SRCTOP}/test/auto_control_subprocess.sh -start -key server${KEYWORD} -int 1 chmpx -conf ${SRCTOP}/test/auto_k2hdkc_server.ini -ctlport 18021 -d msg
87
+ ${SRCTOP}/test/auto_control_subprocess.sh -start -key server${KEYWORD} -int 3 chmpx -conf ${SRCTOP}/test/auto_k2hdkc_server.ini -ctlport 18021 -d msg
88
88
  if [ $? -ne 0 ]; then
89
89
  echo "ERROR: could not run chmpx server node for k2hdkc"
90
90
  exit 1
@@ -92,7 +92,7 @@ if [ ${IS_SCRIPT_MODE} -eq 1 ]; then
92
92
 
93
93
  echo "*** Start : one k2hdkc process"
94
94
  echo -n " "
95
- ${SRCTOP}/test/auto_control_subprocess.sh -start -key server${KEYWORD} -int 1 k2hdkc -conf ${SRCTOP}/test/auto_k2hdkc_server.ini -ctlport 18021 -d msg
95
+ ${SRCTOP}/test/auto_control_subprocess.sh -start -key server${KEYWORD} -int 3 k2hdkc -conf ${SRCTOP}/test/auto_k2hdkc_server.ini -ctlport 18021 -d msg
96
96
  if [ $? -ne 0 ]; then
97
97
  echo "ERROR: one k2hdkc process"
98
98
  exit 1
@@ -100,7 +100,7 @@ if [ ${IS_SCRIPT_MODE} -eq 1 ]; then
100
100
 
101
101
  echo "*** Start : chmpx slave node for k2hdkc"
102
102
  echo -n " "
103
- ${SRCTOP}/test/auto_control_subprocess.sh -start -key slave${KEYWORD} -int 1 chmpx -conf ${SRCTOP}/test/auto_k2hdkc_slave.ini -ctlport 18031 -d msg
103
+ ${SRCTOP}/test/auto_control_subprocess.sh -start -key slave${KEYWORD} -int 3 chmpx -conf ${SRCTOP}/test/auto_k2hdkc_slave.ini -ctlport 18031 -d msg
104
104
  if [ $? -ne 0 ]; then
105
105
  echo "ERROR: chmpx slave node for k2hdkc"
106
106
  exit 1
@@ -120,7 +120,7 @@ else
120
120
  #
121
121
  echo "*** Stop : chmpx slave node for k2hdkc"
122
122
  echo -n " "
123
- ${SRCTOP}/test/auto_control_subprocess.sh -stop -key slave${KEYWORD} -int 1 chmpx
123
+ ${SRCTOP}/test/auto_control_subprocess.sh -stop -key slave${KEYWORD} -int 3 chmpx
124
124
  if [ $? -ne 0 ]; then
125
125
  echo "ERROR: chmpx slave node for k2hdkc"
126
126
  exit 1
@@ -128,7 +128,7 @@ else
128
128
 
129
129
  echo "*** Stop : one k2hdkc process"
130
130
  echo -n " "
131
- ${SRCTOP}/test/auto_control_subprocess.sh -stop -key server${KEYWORD} -int 1 k2hdkc
131
+ ${SRCTOP}/test/auto_control_subprocess.sh -stop -key server${KEYWORD} -int 3 k2hdkc
132
132
  if [ $? -ne 0 ]; then
133
133
  echo "ERROR: one k2hdkc process"
134
134
  exit 1
@@ -136,7 +136,7 @@ else
136
136
 
137
137
  echo "*** Stop : chmpx server node for k2hdkc"
138
138
  echo -n " "
139
- ${SRCTOP}/test/auto_control_subprocess.sh -stop -key server${KEYWORD} -int 1 chmpx
139
+ ${SRCTOP}/test/auto_control_subprocess.sh -stop -key server${KEYWORD} -int 3 chmpx
140
140
  if [ $? -ne 0 ]; then
141
141
  echo "ERROR: could not run chmpx server node for k2hdkc"
142
142
  exit 1
package/.auditignore DELETED
@@ -1 +0,0 @@
1
- https://npmjs.com/advisories/1673