k2hr3-api 1.0.7 → 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,9 @@
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
+
1
7
  k2hr3-api (1.0.7) unstable; urgency=low
2
8
 
3
9
  * Bumpup version number for npm package
@@ -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/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "k2hr3-api",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "dependencies": {
5
- "@kubernetes/client-node": "^0.15.1",
6
- "body-parser": "^1.19.0",
7
- "config": "^3.3.6",
8
- "cookie-parser": "~1.4.5",
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
9
  "dateformat": "^4.6.3",
10
- "debug": "~4.3.2",
11
- "express": "^4.17.1",
12
- "jose": "^3.19.0",
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
15
  "rotating-file-stream": "^2.1.6"
@@ -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.3",
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
  },
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)){
@@ -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
  });