better wild cards
This commit is contained in:
Vendored
+1
-1
@@ -73,7 +73,7 @@ Vagrant.configure("2") do |config|
|
||||
|
||||
if ! which berks >/dev/null; then
|
||||
gem install ruby-shadow berkshelf --no-document
|
||||
# ln -s /opt/chef/embedded/bin/berks /usr/local/bin/berks
|
||||
ln -s /opt/chef/embedded/bin/berks /usr/local/bin/berks
|
||||
fi
|
||||
|
||||
cd /vagrant
|
||||
|
||||
@@ -16,4 +16,77 @@ const Host = require('../utils/redis_model')({
|
||||
}
|
||||
});
|
||||
|
||||
Host.lookupDict = {};
|
||||
|
||||
Host.make_lookup = async function(){
|
||||
try{
|
||||
for(let host of await this.list()){
|
||||
let fragments = host.split('.');
|
||||
let place = this.lookupDict;
|
||||
|
||||
while(fragments.length !==0){
|
||||
let current = fragments.pop();
|
||||
if(!place[current]){
|
||||
place[current] = {};
|
||||
}
|
||||
|
||||
if(fragments.length === 0){
|
||||
place[current]['#record'] = await this.get(host)
|
||||
}
|
||||
place = place[current];
|
||||
}
|
||||
}
|
||||
|
||||
}catch(error){
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
Host.lookUp = async function(host){
|
||||
let place = this.lookupDict;
|
||||
let last_resort = {};
|
||||
|
||||
for(let fragment of host.split('.').slice().reverse()){
|
||||
// console.log('fragment', fragment, last_resort)
|
||||
|
||||
if(place['**']) last_resort = place['**'];
|
||||
|
||||
if({...place, ...last_resort}[fragment]){
|
||||
place = {...place, ...last_resort}[fragment];
|
||||
}else if(place['*']){
|
||||
place = place['*']
|
||||
}else if(last_resort){
|
||||
place = last_resort;
|
||||
}
|
||||
}
|
||||
|
||||
if(place && place['#record']) return place['#record'];
|
||||
|
||||
}
|
||||
|
||||
module.exports = {Host};
|
||||
|
||||
(async function(){
|
||||
await Host.make_lookup();
|
||||
// console.log(Host.lookupDict)
|
||||
|
||||
// console.log(Host.lookupDict['com']['vm42'])
|
||||
|
||||
// console.log('test-res', await Host.lookUp('payments.test.com'))
|
||||
|
||||
let count = 5
|
||||
console.log(count++, (await Host.lookUp('payments.test.com')).host === 'payments.**')
|
||||
console.log(count++, (await Host.lookUp('test.sample.other.exmaple.com')).host === '**.exmaple.com')
|
||||
console.log(count++, (await Host.lookUp('stan.test.vm42.com')).host === 'stan.test.vm42.com')
|
||||
console.log(count++, (await Host.lookUp('test.vm42.com')).host === 'test.vm42.com')
|
||||
console.log(count++, (await Host.lookUp('blah.test.vm42.com')).host === '*.test.vm42.com')
|
||||
console.log(count++, (await Host.lookUp('payments.example.com')).host === 'payments.**')
|
||||
console.log(count++, (await Host.lookUp('info.wma.users.718it.biz')).host === 'info.*.users.718it.biz')
|
||||
console.log(count++, (await Host.lookUp('info.users.718it.biz')) === undefined)
|
||||
console.log(count++, (await Host.lookUp('test.1.2.718it.net')).host === 'test.*.*.718it.net')
|
||||
console.log(count++, (await Host.lookUp('test1.exmaple.com')).host === 'test1.exmaple.com')
|
||||
console.log(count++, (await Host.lookUp('other.exmaple.com')).host === '*.exmaple.com')
|
||||
|
||||
|
||||
return ;
|
||||
})()
|
||||
|
||||
Generated
+1085
File diff suppressed because it is too large
Load Diff
+3
-2
@@ -13,10 +13,11 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"authenticate-pam": "github:WeiAnAn/node-authenticate-pam",
|
||||
"ldapts": "^2.2.1",
|
||||
"extend": "^3.0.2",
|
||||
"bcrypt": "^5.0.0",
|
||||
"ejs": "^3.0.1",
|
||||
"express": "~4.16.1",
|
||||
"extend": "^3.0.2",
|
||||
"ldapts": "^2.2.1",
|
||||
"linux-sys-user": "^1.1.0",
|
||||
"redis": "^2.8.0"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user