Skip to content

Commit

Permalink
Implement designated path for informational files
Browse files Browse the repository at this point in the history
  • Loading branch information
PhongT16 committed Jul 21, 2023
1 parent 4a7b1e8 commit 3841352
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
15 changes: 8 additions & 7 deletions OutlookCalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,24 +302,25 @@ 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)

count = count + 1
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__':
Expand All @@ -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)

2 changes: 1 addition & 1 deletion SimpleEvent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
11 changes: 6 additions & 5 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ 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()
if accounts:
# 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()

Expand All @@ -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"]
Expand All @@ -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']
Expand All @@ -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:
Expand Down

0 comments on commit 3841352

Please sign in to comment.