Skip to content

Commit

Permalink
Add a new driver for Vault
Browse files Browse the repository at this point in the history
Will open up possibilities of writing/testing a new castellan
driver in OpenStack

Details on how to run Vault in developer mode is here:
https://www.vaultproject.io/intro/getting-started/dev-server.html
https://www.vaultproject.io/docs/concepts/dev-server.html
  • Loading branch information
dims committed Jul 11, 2017
1 parent 482c981 commit 67c35e0
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Pifpaf currently supports:
* `S3rver`_
* `MongoDB`_
* `OpenStack Swift`_
* `Vault`_

.. _Consul: https://www.consul.io/
.. _PostgreSQL: http://postgresql.org
Expand All @@ -61,6 +62,7 @@ Pifpaf currently supports:
.. _S3rver: https://www.npmjs.com/package/s3rver
.. _MongoDB: https://www.mongodb.com
.. _OpenStack Swift: https://docs.openstack.org/developer/swift/
.. _Vault: https://www.vaultproject.io/

Usage
=====
Expand Down
52 changes: 52 additions & 0 deletions pifpaf/drivers/vault.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import uuid

from pifpaf import drivers


class VaultDriver(drivers.Driver):
DEFAULT_ROOT_TOKEN_ID = str(uuid.uuid4())
DEFAULT_LISTEN_ADDRESS = "127.0.0.1:8200"

def __init__(self, root_token_id=DEFAULT_ROOT_TOKEN_ID,
listen_address=DEFAULT_LISTEN_ADDRESS, **kwargs):
super(VaultDriver, self).__init__(**kwargs)
self.root_token_id = root_token_id
self.listen_address = listen_address

@classmethod
def get_parser(cls, parser):
parser.add_argument("--root-token-id",
default=cls.DEFAULT_ROOT_TOKEN_ID,
help="root token for vault")
parser.add_argument("--listen-address",
default=cls.DEFAULT_LISTEN_ADDRESS,
help="listen address for vault")
return parser

def _setUp(self):
super(VaultDriver, self)._setUp()
c, _ = self._exec(["vault",
"server",
"-dev",
"-dev-root-token-id=" + self.root_token_id,
"-dev-listen-address=" + self.listen_address],
wait_for_line="Vault server started!")

self.addCleanup(self._kill, c)

self.putenv("ROOT_TOKEN", self.root_token_id)
self.putenv("VAULT_ADDR", "http://%s" % self.listen_address)
self.putenv("URL", "http://%s" % self.listen_address)
12 changes: 12 additions & 0 deletions pifpaf/tests/test_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from pifpaf.drivers import redis
from pifpaf.drivers import s3rver
from pifpaf.drivers import swift
from pifpaf.drivers import vault
from pifpaf.drivers import zookeeper


Expand Down Expand Up @@ -155,6 +156,17 @@ def test_memcached(self):
os.getenv("PIFPAF_URL"))
self.assertEqual(str(port), os.getenv("PIFPAF_MEMCACHED_PORT"))

@testtools.skipUnless(spawn.find_executable("vault"),
"vault not found")
def test_vault(self):
listen_address = "localhost:5049"
self.useFixture(vault.VaultDriver(listen_address=listen_address))
self.assertEqual("http://%s" % listen_address,
os.getenv("PIFPAF_URL"))
self.assertEqual("http://%s" % listen_address,
os.getenv("PIFPAF_VAULT_ADDR"))
self.assertTrue(len(os.getenv("PIFPAF_ROOT_TOKEN")) > 0)

@testtools.skipUnless(spawn.find_executable("fakes3"),
"fakes3 not found")
def test_fakes3(self):
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pifpaf.daemons =
redis = pifpaf.drivers.redis:RedisDriver
s3rver = pifpaf.drivers.s3rver:S3rverDriver
zookeeper = pifpaf.drivers.zookeeper:ZooKeeperDriver
vault = pifpaf.drivers.vault:VaultDriver

console_scripts =
pifpaf = pifpaf.__main__:main
Expand Down

0 comments on commit 67c35e0

Please sign in to comment.