Skip to content

Commit 3bd9596

Browse files
committedOct 16, 2015
Initial pass at short circuiting Lobster when switching policies. The last te file should display in the code editor.
1 parent 77896c9 commit 3bd9596

34 files changed

+3214
-40
lines changed
 

‎api/handlers/ws_domains/raw.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import logging
2+
logger = logging.getLogger(__name__)
3+
4+
import restful
5+
import api.handlers.ws_domains as ws_domains
6+
import api
7+
8+
from subprocess import *
9+
10+
11+
12+
class RawDomain(object):
13+
14+
def __init__(self):
15+
print "Raw.__init__"
16+
17+
def translate_selinux(self, params):
18+
""" Given a set of parameters of the form, return the
19+
JSON for the raw module.
20+
21+
{
22+
"refpolicy": "minimal",
23+
"modules": [
24+
{ "name": "test",
25+
"if": " ... source of .if file ...",
26+
"te": " ... source of .te file ...",
27+
"fc": " ... source of .fc file ..."
28+
}
29+
]
30+
}
31+
"""
32+
33+
logger.info("Params: {0}".format(params))
34+
# output = self._make_request('POST', '/import/selinux',
35+
# params if isinstance(params, basestring) else api.db.json.dumps(params))
36+
37+
# exec_str = "./ide/tools/te2json.py"
38+
# exec_str += " -j -t -i"
39+
# #filename = "~/Documents/V3SPA/ide/tools/" + (params['filename'] if params['filename'] else "apache.te")
40+
# filename = params['module']['te_file']
41+
# exec_str += " " + filename
42+
# output = Popen([exec_str], stdout=PIPE, shell=True).communicate()[0]
43+
44+
with open(params['module']['te_file'], 'r') as myfile:
45+
data = myfile.read()
46+
47+
return data#api.db.json.loads(output)
48+
49+
50+
def __instantiate__():
51+
return RawDomain()
52+

‎api/handlers/ws_domains/refpolicy.py

+71-30
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import restful
1111
import api.handlers.ws_domains as ws_domains
1212
import api
13+
from pprint import pprint
1314

1415
def iter_lines(fil_or_str):
1516
if isinstance(fil_or_str, (basestring)):
@@ -94,39 +95,79 @@ def do_get(cls, refpol_id, response):
9495

9596
refpol = RefPolicy.Read(refpol_id)
9697

97-
if refpol.documents is None or 'dsl' not in refpol.documents:
98-
logger.info("Missing DSL. Making service request")
99-
dsl = ws_domains.call(
100-
'lobster',
101-
'translate_selinux',
102-
{
103-
'refpolicy': refpol.id,
104-
'modules': []
105-
}
106-
)
107-
108-
if len(dsl['errors']) > 0:
109-
raise Exception("Failed to translate DSL: {0}"
110-
.format("\n".join(
111-
("{0}".format(x) for x in dsl['errors']))))
112-
113-
if 'documents' not in refpol:
114-
refpol['documents'] = {}
115-
116-
refpol['documents']['dsl'] = {
117-
'text': dsl['result'],
118-
'mode': 'lobster',
119-
'digest': hashlib.md5(dsl['result']).hexdigest()
120-
}
98+
# For each module in modules, send module.te_file to te2json.py
99+
# Just get the last module for now, though
100+
for modname in refpol['modules']:
101+
print refpol['modules'][modname]['te_file']
102+
# Use ws_domains.call() to invoke raw.py and get the raw policy
103+
module = refpol['modules'][modname]
104+
raw = ws_domains.call(
105+
'raw',
106+
'translate_selinux',
107+
{
108+
'refpolicy': refpol.id,
109+
'module': module
110+
}
111+
)
112+
113+
result_pol = {
114+
'modules': refpol['modules'],
115+
'written': refpol['written'],
116+
'disk_location': refpol['disk_location'],
117+
'valid': refpol['valid'],
118+
'total': refpol['total'],
119+
'id': refpol['id'],
120+
'_id': refpol['_id'],
121+
'documents': {}
122+
}
121123

122-
refpol.Insert()
124+
result_pol['documents']['raw'] = {
125+
'text': raw,
126+
'mode': 'python',
127+
'digest': hashlib.md5(raw).hexdigest()
128+
}
123129

124-
elif 'digest' not in refpol.documents['dsl']:
125-
refpol.documents['dsl']['digest'] = hashlib.md5(
126-
refpol.documents['dsl']['text']).hexdigest()
127-
refpol.Insert()
128130

129-
response['payload'] = refpol
131+
# Concatinate all the module files together
132+
# refpol['documents']['raw'] = {
133+
# 'text': dsl['result'],
134+
# 'mode': 'lobster',
135+
# 'digest': hashlib.md5(dsl['result']).hexdigest()
136+
# }
137+
138+
# if refpol.documents is None or 'dsl' not in refpol.documents:
139+
# logger.info("Missing DSL. Making service request")
140+
# dsl = ws_domains.call(
141+
# 'lobster',
142+
# 'translate_selinux',
143+
# {
144+
# 'refpolicy': refpol.id,
145+
# 'modules': []
146+
# }
147+
# )
148+
149+
# if len(dsl['errors']) > 0:
150+
# raise Exception("Failed to translate DSL: {0}"
151+
# .format("\n".join(
152+
# ("{0}".format(x) for x in dsl['errors']))))
153+
154+
# if 'documents' not in refpol:
155+
# refpol['documents'] = {}
156+
157+
# refpol['documents']['dsl'] = {
158+
# 'text': dsl['result'],
159+
# 'mode': 'lobster',
160+
# 'digest': hashlib.md5(dsl['result']).hexdigest()
161+
# }
162+
163+
# refpol.Insert()
164+
165+
# elif 'digest' not in refpol.documents['dsl']:
166+
# refpol.documents['dsl']['digest'] = hashlib.md5(
167+
# refpol.documents['dsl']['text']).hexdigest()
168+
# refpol.Insert()
169+
170+
response['payload'] = result_pol
130171
response['payload'].get('parsed', {}).pop('full', None)
131172
return response
132173

‎external/assets.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@
1616
//= require angular-file-upload/angular-file-upload.min.js
1717
//= require bootstrap-contextmenu/bootstrap-contextmenu.js
1818
//= require queue/Queue.js
19+
//= require crossfilter/crossfilter.js

‎external/crossfilter/.npmignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test/
2+
lib/
3+
.DS_Store

‎external/crossfilter/.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: node_js
2+
node_js:
3+
- 0.8

‎external/crossfilter/CONTRIBUTING.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Contributing To Crossfilter
2+
3+
### Individual Contributor License Agreement
4+
5+
Want to add support for a new backend or visualization? We'd love for you to participate in the development of Crossfilter. Before we can accept your pull request, please sign our [Individual Contributor License Agreement][1]. It's a short form that covers our bases and makes sure you're eligible to contribute. Thank you!
6+
7+
[1]: https://spreadsheets.google.com/spreadsheet/viewform?formkey=dDViT2xzUHAwRkI3X3k5Z0lQM091OGc6MQ&ndplr=1
8+
9+
### Getting Help
10+
11+
Full API documentation is kept [in the wiki][2]. If you have a question or need help using Crossfilter, please ask on Stackoverflow using the [crossfilter tag][3]. Feel free to file bug reports and other suggestions in the [github issue tracker][4].
12+
13+
[2]: https://github.com/square/crossfilter/wiki
14+
[3]: http://stackoverflow.com/questions/tagged/crossfilter
15+
[4]: https://github.com/square/crossfilter/issues
16+
17+
### License
18+
19+
Crossfilter is available under the [Apache License][5].
20+
21+
[5]: https://github.com/square/crossfilter/blob/master/LICENSE
22+
23+

‎external/crossfilter/LICENSE

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Copyright 2012 Square, Inc.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4+
this file except in compliance with the License. You may obtain a copy of the
5+
License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software distributed
10+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
specific language governing permissions and limitations under the License.

‎external/crossfilter/Makefile

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.PHONY: test benchmark
2+
3+
all: crossfilter.min.js
4+
5+
crossfilter.js: \
6+
src/identity.js \
7+
src/permute.js \
8+
src/bisect.js \
9+
src/heap.js \
10+
src/heapselect.js \
11+
src/insertionsort.js \
12+
src/quicksort.js \
13+
src/array.js \
14+
src/filter.js \
15+
src/null.js \
16+
src/zero.js \
17+
src/reduce.js \
18+
src/crossfilter.js \
19+
package.json \
20+
Makefile
21+
22+
%.min.js: %.js Makefile
23+
@rm -f $@
24+
node_modules/.bin/uglifyjs $< -c unsafe=true -m -o $@
25+
26+
%.js:
27+
@rm -f $@
28+
@echo '(function(exports){' > $@
29+
@echo 'crossfilter.version = "'$(shell node -p 'require("./package.json").version')'";' >> $@
30+
cat $(filter %.js,$^) >> $@
31+
@echo '})(typeof exports !== '\'undefined\'' && exports || this);' >> $@
32+
@chmod a-w $@
33+
34+
clean:
35+
rm -f crossfilter.js crossfilter.min.js
36+
37+
test: all
38+
@npm test
39+
40+
benchmark: all
41+
@node test/benchmark.js

‎external/crossfilter/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Crossfilter
2+
3+
**Crossfilter** is a JavaScript library for exploring large multivariate datasets in the browser. Crossfilter supports extremely fast (<30ms) interaction with coordinated views, even with datasets containing a million or more records; we built it to power analytics for Square Register, allowing merchants to slice and dice their payment history fluidly.
4+
5+
Since most interactions only involve a single dimension, and then only small adjustments are made to the filter values, incremental filtering and reducing is significantly faster than starting from scratch. Crossfilter uses sorted indexes (and a few bit-twiddling hacks) to make this possible, dramatically increasing the perfor­mance of live histograms and top-K lists. Crossfilter is available under the [Apache License](/square/crossfilter/blob/master/LICENSE).
6+
7+
Want to learn more? [See the wiki.](https://github.com/square/crossfilter/wiki)

‎external/crossfilter/component.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "crossfilter",
3+
"repo": "square/crossfilter",
4+
"description": "Fast n-dimensional filtering and grouping of records.",
5+
"version": "1.3.11",
6+
"keywords": [],
7+
"main": "crossfilter.js",
8+
"scripts": [
9+
"crossfilter.js"
10+
],
11+
"dependencies": {},
12+
"development": {},
13+
"license": "Apache"
14+
}

0 commit comments

Comments
 (0)
Please sign in to comment.