-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support checking if token value is in specified set
Also, read token configuration from YAML file using new option --config
- Loading branch information
Showing
9 changed files
with
271 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
author='Suresh Thirugn', | ||
author_email='[email protected]', | ||
packages=find_packages(), | ||
install_requires=['Click', 'termcolor', 'docutils'], | ||
install_requires=['Click', 'termcolor', 'docutils', 'pyyaml'], | ||
entry_points=''' | ||
[console_scripts] | ||
testimony=testimony.cli:testimony | ||
|
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,63 @@ | ||
# -*- coding: UTF-8 -*- | ||
|
||
""" | ||
Parse config for testimony. | ||
Example: | ||
--- | ||
Status: | ||
type: choice | ||
choices: | ||
- Manual | ||
- Automated | ||
... | ||
Currently only supported type is 'choice', but in the future more can be added. | ||
""" | ||
|
||
import sys | ||
import yaml | ||
|
||
TOKEN_TYPES = ['choice'] | ||
|
||
|
||
def parse_config(filename): | ||
"""Parse the config.""" | ||
try: | ||
with open(filename, 'r') as fp: | ||
data = yaml.load(fp, Loader=yaml.SafeLoader) | ||
return {k.lower(): TokenConfig(k, v) for k, v in data.items()} | ||
except FileNotFoundError: | ||
print('ERROR: File {} not found'.format(filename)) | ||
sys.exit(1) | ||
|
||
|
||
class TokenConfig(object): | ||
""" | ||
Represent config for one token. | ||
Curently only chacks for value. | ||
""" | ||
|
||
def __init__(self, name, config): | ||
""" | ||
Initialize token config object. | ||
Takes name of the token and actual config structure as a param | ||
""" | ||
self.name = name.lower() | ||
|
||
assert 'type' in config | ||
assert config['type'] in TOKEN_TYPES | ||
self.token_type = config['type'] | ||
|
||
if self.token_type == 'choice': | ||
assert 'choices' in config | ||
assert isinstance(config['choices'], list) | ||
self.choices = [i.lower() for i in config['choices']] | ||
|
||
def validate(self, what): | ||
"""Ensure that 'what' meets value validation criteria.""" | ||
if self.token_type == 'choice': | ||
return what.lower() in self.choices |
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,12 @@ | ||
--- | ||
Status: | ||
type: choice | ||
choices: | ||
- Manual | ||
- Automated | ||
Feature: | ||
type: choice | ||
choices: | ||
- Login - Positive | ||
- Login - Negative | ||
... |