diff --git a/Dockerfile b/Dockerfile index c0dd746..a3476f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,15 +17,17 @@ RUN apt-get update -y \ # RUN echo mailhub=smtp-server >> /etc/ssmtp/ssmtp.conf # RUN echo FromLineOverride=YES >> /etc/ssmtp/ssmtp.conf # RUN apt-get clean +RUN mkdir /home/vacation_calendar_sync COPY . /vacation_calendar_sync WORKDIR /vacation_calendar_sync RUN python -m pip install -r /vacation_calendar_sync/requirements.txt -RUN ln -s /home/.netrc /root/.netrc # RUN ln -s /home/microsoft_graph_auth.yaml /root/microsoft_graph_auth.yaml RUN ln -s /home/vacation_calendar_sync_config.yaml /root/vacation_calendar_sync_config.yaml -ENV AZURE_GRAPH_AUTH="/root/vacation_calendar_sync_config.yaml" + +ENV VCS_CONFIG="/root/vacation_calendar_sync_config.yaml" +ENV VCS_COLLECTION_PATH="/home/vacation_calendar_sync" #RUN mkdir /duo_auth/app CMD ["bash"] diff --git a/OutlookCalendar.py b/OutlookCalendar.py index 3272ecf..f7ff745 100644 --- a/OutlookCalendar.py +++ b/OutlookCalendar.py @@ -302,8 +302,8 @@ def main(configs): start_date = datetime(year=today.year, month=today.month, day=today.day, hour=0,minute=0) end_date = start_date + days_out - individual_calendar_events = calendar.process_individual_calendars(calendar.get_individual_calendars(start_date, end_date), start_date, end_date) - shared_calendar_events, event_ids = calendar.process_shared_calendar(calendar.get_shared_calendar(start_date, end_date)) + individual_calendar_events = calendar.process_individual_calendars(calendar.get_individual_calendars(start_date, end_date, access_token), start_date, end_date) + shared_calendar_events, event_ids = calendar.process_shared_calendar(calendar.get_shared_calendar(start_date, end_date, access_token)) SharedCalendar.update_shared_calendar(individual_calendar_events, shared_calendar_events, event_ids, calendar.shared_calendar_id, access_token) @@ -311,15 +311,16 @@ def main(configs): time.sleep(calendar.update_interval) if args.dump_json: - shared_calendar_events, event_ids = calendar.process_shared_calendar(calendar.get_shared_calendar(start_date, end_date)) + shared_calendar_events, event_ids = calendar.process_shared_calendar(calendar.get_shared_calendar(start_date, end_date, access_token)) GenerateReport(shared_calendar_events, None).dump_calendar_to_json(shared_calendar_events, start_date, end_date) if args.manual_update: + access_token = utils.acquire_access_token(calendar.app, calendar.scopes) dates = sanitize_input(args.manual_update[0], args.manual_update[1]) start_date = dates[0] end_date = dates[1] - individual_calendar_events = calendar.process_individual_calendars(calendar.get_individual_calendars(start_date, end_date), start_date, end_date) - shared_calendar_events, event_ids = calendar.process_shared_calendar(calendar.get_shared_calendar(start_date, end_date)) + individual_calendar_events = calendar.process_individual_calendars(calendar.get_individual_calendars(start_date, end_date, access_token), start_date, end_date) + shared_calendar_events, event_ids = calendar.process_shared_calendar(calendar.get_shared_calendar(start_date, end_date, access_token)) SharedCalendar.update_shared_calendar(individual_calendar_events, shared_calendar_events, event_ids, calendar.shared_calendar_id, access_token) if __name__ == '__main__': @@ -340,6 +341,6 @@ def main(configs): stream_handler.setFormatter(fmt=logging.Formatter('%(name)s:%(asctime)s:%(filename)s:%(levelname)s:%(message)s')) logger.addHandler(stream_handler) - #main(configs) - debug(configs) + main(configs) + #debug(configs) diff --git a/SimpleEvent.py b/SimpleEvent.py index 5e62879..34a0eee 100644 --- a/SimpleEvent.py +++ b/SimpleEvent.py @@ -4,7 +4,7 @@ import yaml import os -path = os.getenv('AZURE_GRAPH_AUTH') +path = os.getenv('VCS_CONFIG') with open(path, 'r') as file: dictionary = yaml.safe_load(file) AM_config = dictionary['AM_config'] diff --git a/utils.py b/utils.py index 6713bc2..be5988e 100644 --- a/utils.py +++ b/utils.py @@ -16,6 +16,7 @@ def init_device_code_flow(app, scopes): def acquire_access_token(app, scopes): + collection_path = os.getenv('VCS_COLLECTION_PATH') # Note access_token usually lasts for a little bit over an hour result = None accounts = app.get_accounts() @@ -23,9 +24,9 @@ def acquire_access_token(app, scopes): # If accounts exist, that means that it is an iteration, since system rebooting and first time running won't have acccount print("Tokens found in cache") result = app.acquire_token_silent(scopes, accounts[0]) - elif os.path.isfile('token.txt'): + elif os.path.isfile(collection_path + '/token.txt'): # if the token file exist, then read the refresh token and use it to acquire the access_token - with open("token.txt", "r") as file: + with open(collection_path + "/token.txt", "r") as file: print("Refresh token found") refresh_token = file.readline() @@ -35,7 +36,7 @@ def acquire_access_token(app, scopes): result = init_device_code_flow(app, scopes) if "access_token" in result: - with open("token.txt", "w") as file: + with open(collection_path + "/token.txt", "w") as file: file.write(result["refresh_token"]) print("Writing new refresh token into token") return result["access_token"] @@ -45,7 +46,7 @@ def acquire_access_token(app, scopes): print(result.get("correlation_id")) -path = os.getenv('AZURE_GRAPH_AUTH') +path = os.getenv('VCS_CONFIG') with open(path, 'r') as file: dictionary = yaml.safe_load(file) recipient_email = dictionary['recipient_email'] @@ -54,7 +55,7 @@ def retrieve_from_yaml(): required_attributes = ['client_id', 'tenant_id', 'scope', 'group_members', 'shared_calendar_name', 'logging_file_path', 'days_out', 'update_interval'] # Created ENV variable using docker's ENV command in Dockerfile - path = os.getenv('AZURE_GRAPH_AUTH') + path = os.getenv('VCS_CONFIG') with open(path, 'r') as file: return yaml.safe_load(file) # for attribute in required_attributes: