mayu 0.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +69 -0
- data/LICENSE.txt +21 -0
- data/README.md +206 -0
- data/Rakefile +6 -0
- data/bin/mayu-association-collector +84 -0
- data/config.ru +41 -0
- data/lib/mayu.rb +8 -0
- data/lib/mayu/ap.rb +43 -0
- data/lib/mayu/app.rb +246 -0
- data/lib/mayu/association.rb +34 -0
- data/lib/mayu/cisco_wlc_collector.rb +102 -0
- data/lib/mayu/device.rb +23 -0
- data/lib/mayu/loader.rb +168 -0
- data/lib/mayu/map.rb +42 -0
- data/lib/mayu/periodic_loader.rb +55 -0
- data/lib/mayu/relation.rb +50 -0
- data/lib/mayu/renderer.rb +43 -0
- data/lib/mayu/stores/base.rb +44 -0
- data/lib/mayu/stores/concat.rb +41 -0
- data/lib/mayu/stores/file.rb +25 -0
- data/lib/mayu/stores/memory.rb +21 -0
- data/lib/mayu/stores/s3.rb +40 -0
- data/lib/mayu/user.rb +41 -0
- data/lib/mayu/user_completer.rb +30 -0
- data/lib/mayu/version.rb +3 -0
- data/mayu.gemspec +34 -0
- data/script/console +14 -0
- data/script/setup +8 -0
- metadata +176 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'mayu/stores/base'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Mayu
|
5
|
+
module Stores
|
6
|
+
class File < Base
|
7
|
+
def initialize(path:)
|
8
|
+
@path = path
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :path
|
12
|
+
|
13
|
+
def put(obj)
|
14
|
+
::File.write path, "#{for_json(obj).to_json}\n"
|
15
|
+
end
|
16
|
+
|
17
|
+
def get
|
18
|
+
from_json JSON.parse(::File.read(path), symbolize_names: true)
|
19
|
+
rescue Errno::ENOENT
|
20
|
+
return nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'mayu/stores/s3'
|
2
|
+
require 'aws-sdk-s3'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Mayu
|
6
|
+
module Stores
|
7
|
+
class S3 < Base
|
8
|
+
def initialize(region:, bucket:, key:)
|
9
|
+
@region = region
|
10
|
+
@bucket = bucket
|
11
|
+
@key = key
|
12
|
+
end
|
13
|
+
|
14
|
+
def put(obj)
|
15
|
+
s3.put_object(
|
16
|
+
bucket: @bucket,
|
17
|
+
key: @key,
|
18
|
+
content_type: 'application/json',
|
19
|
+
body: "#{for_json(obj).to_json}\n",
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def get
|
24
|
+
json = s3.get_object(
|
25
|
+
bucket: @bucket,
|
26
|
+
key: @key,
|
27
|
+
).body.read
|
28
|
+
from_json JSON.parse(json, symbolize_names: true)
|
29
|
+
rescue Aws::S3::Errors::NoSuchKey, Aws::S3::Errors::AccessDenied
|
30
|
+
return nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def s3
|
34
|
+
@s3 ||= Aws::S3::Client.new(
|
35
|
+
region: @region,
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/mayu/user.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
|
3
|
+
require 'mayu/relation'
|
4
|
+
|
5
|
+
module Mayu
|
6
|
+
User = Struct.new(:key, :name, :aliases, :gravatar_email, keyword_init: true) do
|
7
|
+
include Mayu::Relation
|
8
|
+
|
9
|
+
def self.load(obj)
|
10
|
+
new(**obj)
|
11
|
+
end
|
12
|
+
|
13
|
+
def associations
|
14
|
+
devices.map(&:association).compact
|
15
|
+
end
|
16
|
+
|
17
|
+
def associated_device_kinds
|
18
|
+
associations.map(&:device).compact.map(&:kind).uniq
|
19
|
+
end
|
20
|
+
|
21
|
+
def devices_key
|
22
|
+
key
|
23
|
+
end
|
24
|
+
|
25
|
+
def gravatar_hash
|
26
|
+
return nil unless gravatar_email
|
27
|
+
@gravatar_hash ||= Digest::MD5.hexdigest gravatar_email.strip.downcase
|
28
|
+
end
|
29
|
+
|
30
|
+
relates :devices
|
31
|
+
|
32
|
+
def as_json
|
33
|
+
{
|
34
|
+
key: key,
|
35
|
+
name: name,
|
36
|
+
aliases: aliases || [],
|
37
|
+
gravatar_hash: gravatar_hash,
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'graphed_fuzzy_search'
|
2
|
+
|
3
|
+
module Mayu
|
4
|
+
class UserCompleter
|
5
|
+
def initialize(users)
|
6
|
+
@cache_key = cache_key_for(users)
|
7
|
+
@collection = GraphedFuzzySearch.new(users, attributes: %i(name aliases))
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :collection
|
11
|
+
|
12
|
+
def query(str)
|
13
|
+
collection.query(str)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update(users)
|
17
|
+
if @cache_key == cache_key_for(users)
|
18
|
+
self
|
19
|
+
else
|
20
|
+
self.class.new(users)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def cache_key_for(users)
|
27
|
+
users.map{ |_| [_.name, _.aliases, _.key] }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/mayu/version.rb
ADDED
data/mayu.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "mayu/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mayu"
|
8
|
+
spec.version = Mayu::VERSION
|
9
|
+
spec.authors = ["Sorah Fukumori"]
|
10
|
+
spec.email = ["sorah@cookpad.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Rack app to locate employees in an office by Wi-Fi MAC address and WLC association data}
|
13
|
+
spec.homepage = "https://github.com/sorah/mayu"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end + Dir['app/public/dist/**/*']
|
19
|
+
spec.bindir = "bin"
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.required_ruby_version = '>= 2.5.0'
|
24
|
+
|
25
|
+
spec.add_dependency 'wlc_snmp'
|
26
|
+
spec.add_dependency 'sinatra'
|
27
|
+
spec.add_dependency 'aws-sdk-s3'
|
28
|
+
|
29
|
+
spec.add_dependency 'graphed_fuzzy_search'
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler"
|
32
|
+
spec.add_development_dependency "rake"
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mayu"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/script/setup
ADDED
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mayu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.beta1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sorah Fukumori
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: wlc_snmp
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sinatra
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: aws-sdk-s3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: graphed_fuzzy_search
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- sorah@cookpad.com
|
114
|
+
executables:
|
115
|
+
- mayu-association-collector
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/mayu-association-collector
|
128
|
+
- config.ru
|
129
|
+
- lib/mayu.rb
|
130
|
+
- lib/mayu/ap.rb
|
131
|
+
- lib/mayu/app.rb
|
132
|
+
- lib/mayu/association.rb
|
133
|
+
- lib/mayu/cisco_wlc_collector.rb
|
134
|
+
- lib/mayu/device.rb
|
135
|
+
- lib/mayu/loader.rb
|
136
|
+
- lib/mayu/map.rb
|
137
|
+
- lib/mayu/periodic_loader.rb
|
138
|
+
- lib/mayu/relation.rb
|
139
|
+
- lib/mayu/renderer.rb
|
140
|
+
- lib/mayu/stores/base.rb
|
141
|
+
- lib/mayu/stores/concat.rb
|
142
|
+
- lib/mayu/stores/file.rb
|
143
|
+
- lib/mayu/stores/memory.rb
|
144
|
+
- lib/mayu/stores/s3.rb
|
145
|
+
- lib/mayu/user.rb
|
146
|
+
- lib/mayu/user_completer.rb
|
147
|
+
- lib/mayu/version.rb
|
148
|
+
- mayu.gemspec
|
149
|
+
- script/console
|
150
|
+
- script/setup
|
151
|
+
homepage: https://github.com/sorah/mayu
|
152
|
+
licenses:
|
153
|
+
- MIT
|
154
|
+
metadata: {}
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: 2.5.0
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">"
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: 1.3.1
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 2.7.3
|
172
|
+
signing_key:
|
173
|
+
specification_version: 4
|
174
|
+
summary: Rack app to locate employees in an office by Wi-Fi MAC address and WLC association
|
175
|
+
data
|
176
|
+
test_files: []
|