Skip to content

Commit 615f908

Browse files
author
Brett Hazen
committed
Include security into regular buildbot build; update config options
1 parent 22cb998 commit 615f908

File tree

3 files changed

+94
-44
lines changed

3 files changed

+94
-44
lines changed

buildbot/Makefile

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ RIAK_ADMIN = ${RIAK_DIR}/bin/riak-admin
55
# CERTS_DIR = $(shell pwd)/../src/test/resources
66

77
preconfigure:
8-
echo "storage_backend = leveldb" >> ${RIAK_CONF}
9-
echo "search = on" >> ${RIAK_CONF}
10-
echo "listener.protobuf.internal = 127.0.0.1:8087" >> ${RIAK_CONF}
11-
echo "listener.http.internal = 127.0.0.1:8098" >> ${RIAK_CONF}
8+
@../setup.py preconfigure --riak-conf=${RIAK_CONF}
129

1310
configure:
14-
@../setup.py create_bucket_types --riak-admin=${RIAK_ADMIN}
11+
@../setup.py configure --riak-admin=${RIAK_ADMIN}
1512

1613
compile:
1714
-@yes y | pip uninstall riak-pb protobuf pyOpenSSL
@@ -22,14 +19,14 @@ lint:
2219
@cd ..; pep8 riak *.py
2320
@cd ..; pyflakes riak *.py
2421

25-
test:
26-
@RUN_YZ=1 SKIP_INDEXES=0 ../setup.py test
27-
28-
preconfigure_security:
29-
@../setup.py preconfig_security --riak-conf=${RIAK_CONF}
22+
test: test_normal test_security
3023

31-
configure_security:
32-
@../setup.py setup_tests --riak-admin=${RIAK_ADMIN}
24+
test_normal:
25+
@echo "Testing Riak Python Client (without security)"
26+
@../setup.py disable_security --riak-admin=${RIAK_ADMIN}
27+
@RUN_YZ=1 SKIP_INDEXES=0 ../setup.py test
3328

3429
test_security:
35-
(cd ..; RUN_YZ=1 SKIP_INDEXES=0 RUN_SECURITY=1 RIAK_TEST_HTTP_PORT=8099 ./setup.py test)
30+
@echo "Testing Riak Python Client (with security)"
31+
@../setup.py enable_security --riak-admin=${RIAK_ADMIN}
32+
(cd ..; RUN_YZ=1 SKIP_INDEXES=0 RUN_SECURITY=1 SKIP_POOL=1 SKIP_RESOLVE=1 RIAK_TEST_HTTP_PORT=8099 ./setup.py test)

commands.py

Lines changed: 78 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
distutils commands for riak-python-client
33
"""
44

5-
__all__ = ['create_bucket_types', 'setup_security', 'preconfig_security',
6-
'setup_tests']
5+
__all__ = ['create_bucket_types', 'setup_security', 'enable_security',
6+
'disable_security', 'preconfigure', 'configure']
77

88
from distutils import log
99
from distutils.core import Command
@@ -153,7 +153,32 @@ def _btype_command(self, *args):
153153
return cmd
154154

155155

156-
class setup_security(Command):
156+
class security_commands:
157+
def check_security_command(self, *args):
158+
cmd = self._security_command(*args)
159+
return self.check_output(cmd)
160+
161+
def run_security_command(self, *args):
162+
self.spawn(self._security_command(*args))
163+
164+
def _security_command(self, *args):
165+
cmd = [self.riak_admin, "security"]
166+
if isinstance(args, tuple):
167+
for elem in args:
168+
cmd.extend(elem)
169+
else:
170+
cmd.extend(args)
171+
return cmd
172+
173+
def check_output(self, *args, **kwargs):
174+
if self.dry_run:
175+
log.info(' '.join(args))
176+
return bytearray()
177+
else:
178+
return check_output(*args, **kwargs)
179+
180+
181+
class setup_security(Command, security_commands):
157182
"""
158183
Sets up security for testing. By default this will create:
159184
@@ -187,7 +212,6 @@ class setup_security(Command):
187212
]
188213

189214
_commands = [
190-
"enable",
191215
"add-user $USERNAME password=$PASSWORD",
192216
"add-source $USERNAME 127.0.0.1/32 password",
193217
"add-user $CERTUSER password=$CERTPASS",
@@ -243,12 +267,6 @@ def run(self):
243267
for perm in self._grants:
244268
self._apply_grant(perm, self._grants[perm])
245269

246-
def check_output(self, *args, **kwargs):
247-
if self.dry_run:
248-
log.info(' '.join(args))
249-
return bytearray()
250-
else:
251-
return check_output(*args, **kwargs)
252270

253271
def _check_available(self):
254272
try:
@@ -269,33 +287,61 @@ def _apply_grant(self, perm, targets):
269287
.format(perm, target, self.certuser))
270288
self.run_security_command(cmd)
271289

272-
def check_security_command(self, *args):
273-
cmd = self._security_command(*args)
274-
return self.check_output(cmd)
275290

276-
def run_security_command(self, *args):
277-
self.spawn(self._security_command(*args))
291+
class enable_security(Command,security_commands):
292+
"""
293+
Actually turn on security.
294+
"""
295+
description = "turn on security within Riak"
278296

279-
def _security_command(self, *args):
280-
cmd = [self.riak_admin, "security"]
281-
if isinstance(args, tuple):
282-
for elem in args:
283-
cmd.extend(elem)
284-
else:
285-
cmd.extend(args)
286-
return cmd
297+
user_options = [
298+
('riak-admin=', None, 'path to the riak-admin script'),
299+
]
300+
301+
def initialize_options(self):
302+
self.riak_admin = None
303+
304+
def finalize_options(self):
305+
if self.riak_admin is None:
306+
raise DistutilsOptionError("riak-admin option not set")
307+
308+
def run(self):
309+
cmd = "enable"
310+
self.run_security_command(tuple(cmd.split(' ')))
287311

288312

289-
class preconfig_security(Command):
313+
class disable_security(Command,security_commands):
314+
"""
315+
Actually turn off security.
316+
"""
317+
description = "turn off security within Riak"
318+
319+
user_options = [
320+
('riak-admin=', None, 'path to the riak-admin script'),
321+
]
322+
323+
def initialize_options(self):
324+
self.riak_admin = None
325+
326+
def finalize_options(self):
327+
if self.riak_admin is None:
328+
raise DistutilsOptionError("riak-admin option not set")
329+
330+
def run(self):
331+
cmd = "disable"
332+
self.run_security_command(tuple(cmd.split(' ')))
333+
334+
335+
class preconfigure(Command):
290336
"""
291337
Sets up security configuration.
292338
293339
* Update these lines in riak.conf
294340
* storage_backend = leveldb
295341
* search = on
296342
* listener.protobuf.internal = 127.0.0.1:8087
297-
* listener.https.internal = 127.0.0.1:8098
298-
* ## listener.http.internal = 127.0.0.1:8098
343+
* listener.http.internal = 127.0.0.1:8098
344+
* listener.https.internal = 127.0.0.1:8099
299345
* ssl.certfile = $pwd/tests/resources/server.crt
300346
* ssl.keyfile = $pwd/tests/resources/server.key
301347
* ssl.cacertfile = $pwd/tests/resources/ca.crt
@@ -314,6 +360,7 @@ def initialize_options(self):
314360
self.riak_conf = None
315361
self.host = "127.0.0.1"
316362
self.pb_port = "8087"
363+
self.http_port = "8098"
317364
self.https_port = "8099"
318365

319366
def finalize_options(self):
@@ -326,6 +373,7 @@ def run(self):
326373
self._update_riak_conf()
327374

328375
def _update_riak_conf(self):
376+
http_host = self.host + ':' + self.http_port
329377
https_host = self.host + ':' + self.https_port
330378
pb_host = self.host + ':' + self.pb_port
331379
self._backup_file(self.riak_conf)
@@ -347,6 +395,9 @@ def _update_riak_conf(self):
347395
r'ssl.cacertfile = ' + self.cert_dir +
348396
'/ca.crt',
349397
conf, flags=re.MULTILINE)
398+
conf = re.sub(r'^#*\s*listener.http.internal\s+=\s+\S+',
399+
r'listener.http.internal = ' + http_host,
400+
conf, flags=re.MULTILINE)
350401
conf = re.sub(r'^#*\s*listener.https.internal\s+=\s+\S+',
351402
r'listener.https.internal = ' + https_host,
352403
conf, flags=re.MULTILINE)
@@ -365,7 +416,7 @@ def _backup_file(self, name):
365416
log.info("Cannot backup missing file {!r}".format(name))
366417

367418

368-
class setup_tests(Command):
419+
class configure(Command):
369420
"""
370421
Sets up security configuration.
371422

setup.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import platform
33
from setuptools import setup, find_packages
44
from version import get_version
5-
from commands import create_bucket_types, setup_security, \
6-
preconfig_security, setup_tests
5+
from commands import preconfigure, configure, create_bucket_types, \
6+
setup_security, enable_security, disable_security
77

88
install_requires = ["riak_pb >=2.0.0", "pyOpenSSL >= 0.14"]
99
requires = ["riak_pb(>=2.0.0)", "pyOpenSSL(>=0.14)"]
@@ -31,8 +31,10 @@
3131
url='https://github.com/basho/riak-python-client',
3232
cmdclass={'create_bucket_types': create_bucket_types,
3333
'setup_security': setup_security,
34-
'preconfig_security': preconfig_security,
35-
'setup_tests': setup_tests},
34+
'preconfigure': preconfigure,
35+
'configure': configure,
36+
'enable_security': enable_security,
37+
'disable_security': disable_security},
3638
classifiers=['License :: OSI Approved :: Apache Software License',
3739
'Intended Audience :: Developers',
3840
'Operating System :: OS Independent',

0 commit comments

Comments
 (0)