-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move sensitive configuration options into separate files
Read credentials for cloud testing services from configuration files in the working or home directory. Fixes #60
- Loading branch information
Showing
12 changed files
with
366 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import os | ||
import sys | ||
|
||
from pytest_selenium.exceptions import MissingCloudCredentialError | ||
|
||
if sys.version_info[0] == 2: | ||
import ConfigParser as configparser | ||
else: | ||
import configparser | ||
|
||
|
||
class Provider(object): | ||
|
||
@property | ||
def driver(self): | ||
return type(self).__name__ | ||
|
||
@property | ||
def name(self): | ||
return self.driver | ||
|
||
@property | ||
def config(self): | ||
name = '.{0}'.format(self.driver.lower()) | ||
config = configparser.ConfigParser() | ||
config.read([name, os.path.join(os.path.expanduser('~'), name)]) | ||
return config | ||
|
||
def get_credential(self, key, env): | ||
try: | ||
value = self.config.get('credentials', key) | ||
except (configparser.NoSectionError, | ||
configparser.NoOptionError, | ||
KeyError): | ||
value = os.getenv(env) | ||
if not value: | ||
raise MissingCloudCredentialError(self.name, key, env) | ||
return value |
Oops, something went wrong.