|
|
- #!/usr/bin/python
- """Configuration settings for console app using device flow authentication
- """
-
- import re
- import os
- import configparser
-
-
- # Read Config from File
- config = configparser.RawConfigParser({
- 'machine': '',
- 'login': '',
- 'days_history': 7,
- 'days_future': 30,
- 'max_entries': 100
- })
- directory = os.path.dirname(os.path.realpath(__file__))
- config.read(os.path.join(directory, 'config.cfg'))
-
-
- def get_secret(machine, login, key):
- s = "^machine %s login %s[\^]%s password (.*)$" % (machine, login, key)
- p = re.compile(s, re.MULTILINE)
- authinfo = os.popen("gpg -q --no-tty -d ~/.authinfo.gpg").read()
- matches = p.search(authinfo)
- if matches is not None:
- return matches.group(1)
- else:
- return None
-
- RESOURCE = config.get('msgraph-orgmode', 'resource')
- API_VERSION = config.get('msgraph-orgmode', 'api_version')
- LOGIN = config.get('msgraph-orgmode', 'login')
- MACHINE = config.get('msgraph-orgmode', 'machine')
- CLIENT_ID = config.get('msgraph-orgmode', 'client_id')
- CLIENT_SECRET = get_secret(MACHINE, LOGIN, 'client_secret')
-
- daysHistory = config.getint('msgraph-orgmode', 'days_history')
- daysFuture = config.getint('msgraph-orgmode', 'days_future')
- maxEntries = config.getint('msgraph-orgmode', 'max_entries')
-
- if not CLIENT_ID and not CLIENT_SECRET:
- print('ERROR: CLIENT_ID and CLIENT_SECRET are required.')
- import sys
- sys.exit(1)
|