def setUp(self): for index in (self.index1, self.index2): self.eldb = get_db_cnx(index, self.prefix) if index in (self.index1, self.index2): for dataset in self.datasets: index_dataset(self.eldb, dataset) webapp.CHANGE_PREFIX = self.prefix webapp.app.config["TESTING"] = True self.client = webapp.app.test_client() self.apikey = "1a2b3c4d5e" config_data = { "tenants": [ { # Private index "index": self.index1, "users": ["jane", "john"], }, { # Public index "index": self.index2, "task_crawlers": [ { "name": "myttcrawler", "api_key": self.apikey, "updated_since": "2020-01-01", } ], }, ] } env.indexes_acl = config.build_index_acl(config_data) env.indexes_task_crawlers = config.build_index_task_crawlers(config_data)
def test_indexes_acl(self): indexes_acl = config.build_index_acl(yaml.safe_load(config.config_sample_yaml)) expected = {"default": ["john", "jane"], "tenant1": []} ddiff = DeepDiff(indexes_acl, expected) if ddiff: raise DiffException(ddiff) self.assertTrue(config.is_public_index(indexes_acl, "tenant1")) self.assertFalse(config.is_public_index(indexes_acl, "default")) users = config.get_authorized_users(indexes_acl, "default") self.assertListEqual(users, ["john", "jane"])
def test_indexes_acl(self): indexes_acl = config.build_index_acl(yaml.safe_load(config.config_sample_yaml)) expected = {'default': ['john', 'jane'], 'tenant1': []} ddiff = DeepDiff(indexes_acl, expected) if ddiff: raise DiffException(ddiff) self.assertTrue(config.is_public_index(indexes_acl, 'tenant1')) self.assertFalse(config.is_public_index(indexes_acl, 'default')) users = config.get_authorized_users(indexes_acl, 'default') self.assertListEqual(users, ['john', 'jane'])
def setUp(self): webapp.CHANGE_PREFIX = self.prefix webapp.app.config['TESTING'] = True self.client = webapp.app.test_client() config_data = { "tenants": [ { # Private index "index": self.index1, "users": ['jane', 'john'], }, { # Public index "index": self.index2 }, ] } webapp.indexes_acl = config.build_index_acl(config_data)
authorize_params=None, api_base_url='https://api.github.com/', client_kwargs={'scope': 'user:email'}, ) indexes_acl: Dict[str, List[config.Username]] = {} config_path = os.getenv('CONFIG', None) if not config_path: print('CONFIG env is missing.', file=sys.stderr) else: if not os.path.isfile(config_path): print('Unable to access %s.' % config_path, file=sys.stderr) sys.exit(1) else: globals()['indexes_acl'] = config.build_index_acl( yaml.safe_load(open(config_path))) @app.route("/api/0/login", methods=['GET']) def login(): github = oauth.create_client('github') redirect_uri = os.getenv('REDIRECT_URL') return github.authorize_redirect(redirect_uri) @app.route("/api/0/authorize", methods=['GET']) def authorize(): github = oauth.create_client('github') # token = github.authorize_access_token() github.authorize_access_token() resp = github.get('user')
client_kwargs={"scope": "user:email"}, ) indexes_acl: Dict[str, List[config.Username]] = {} project_defs: Dict[str, List[config.ProjectDefinition]] = {} config_path = os.getenv("CONFIG", None) if not config_path: print("CONFIG env is missing.", file=sys.stderr) else: if not os.path.isfile(config_path): print("Unable to access %s." % config_path, file=sys.stderr) sys.exit(1) else: rawconfig = yaml.safe_load(open(config_path)) globals()["indexes_acl"] = config.build_index_acl(rawconfig) globals()["project_defs"] = config.build_project_definitions(rawconfig) globals()["indexes_task_crawlers"] = config.build_index_task_crawlers( rawconfig) def returnAPIError(desc: str, code: int, details: Optional[str] = None): abort( make_response( jsonify({ "statusCode": code, "message": desc, "details": details }), code))
# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. import os import sys import yaml from typing import Dict, List from monocle import config config_path = os.getenv("CONFIG", None) if not config_path: print("CONFIG env is missing.", file=sys.stderr) indexes_acl: Dict[str, List[config.Username]] = {} project_defs: Dict[str, List[config.ProjectDefinition]] = {} indexes_task_crawlers = {} else: if not os.path.isfile(config_path): print("Unable to access %s." % config_path, file=sys.stderr) sys.exit(1) else: rawconfig = yaml.safe_load(open(config_path)) indexes_acl = config.build_index_acl(rawconfig) project_defs = config.build_project_definitions(rawconfig) indexes_task_crawlers = config.build_index_task_crawlers(rawconfig)