Skip to content

Commit

Permalink
Edit README and Modify error report
Browse files Browse the repository at this point in the history
  • Loading branch information
PhongT16 committed Aug 4, 2023
1 parent 1896b57 commit be25f01
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ENV VCS_CONFIG="/root/vacation_calendar_sync_config.yaml"
#ENV VCS_COLLECTION_PATH="/root/vacation_calendar_sync/"
#RUN mkdir /duo_auth/app

CMD ["bash"]
#CMD ["bash"]

#CMD [ "python3 OutlookCalendar.py -s" ]

Expand Down
3 changes: 2 additions & 1 deletion IndividualCalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def get_individual_calendars(start_date, end_date, group_members, access_token):
if response.status_code != 200:
message = 'Unable to retrieve individual calendar from the getSchedule endpoint'
utils.send_email(message, access_token)
logger.error(response.json())
#logger.error(response.json())
logger.error(f"response.text: {response.text}")
raise ConnectionError(message)

return response.json()
Expand Down
4 changes: 2 additions & 2 deletions OutlookCalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,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)

21 changes: 8 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@ Microsoft Azure Project Config (`/root/vacation_calendar_sync_config.yaml`)

Look at [sample_config.yaml](sample_config.yaml)

# Netrc setup (`/home/.ssh/netrc`)
```
machine OUTLOOK_LOGIN
login ...
password ...
## Pull Image from DockerHub
```

<!-- ## Pull Image from DockerHub
docker pull ghcr.io/ncsa/vacation_calendar_sync:production
```
docker pull phongtran27/outlook_calendar_report_generator
``` -->

# Build Container
```
docker run -it --name ncsa_vacation_calendar_sync --mount type=bind,source=$HOME,dst=/home ghcr.io/ncsa/vacation_calendar_sync
```

Once the container is created, entrypoint will execute the entrypoint.sh file, which effectively runs the program with python3 OutlookCalendar -s mode. To override this default command run:

```
docker run -it --name ncsa_vacation_calendar_sync entrypoint python3 OutlookCalendar -m [year]-[month]-[day] [year]-[month]-[day] --mount type=bind,source=$HOME,dst=/home ghcr.io/ncsa/vacation_calendar_sync
```


# Quick Start
The commnad below will generate a report to console of events that occurs between the start and end date.
Expand All @@ -47,11 +46,7 @@ Example: python3 OutlookCalendar.py -s

`-h` : Display the help screen

# Notes

The `.netrc` file needs to have the correct permission (`-rw-------`).

If not, do: `chmod u+rw,u-x,go-rwx ~/.netrc`

To check: `ls -la ~/.netrc`

18 changes: 12 additions & 6 deletions SharedCalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def get_shared_calendar_id(shared_calendar_name, access_token):
if response.status_code != 200:
message = f"Unable to connect to the {endpoint} endpoint to retrieve {shared_calendar_name}"
utils.send_email(message, access_token)
logger.error(response.json())
#logger.error(response.json())
logger.error(f"response.text: {response.text}")
raise ConnectionError(message)

# Loop through all the calendars available to the user, and find the one indicated in the yaml file and retrieve its calendar ID
Expand All @@ -46,7 +47,8 @@ def get_shared_calendar_id(shared_calendar_name, access_token):

message = f"{shared_calendar_name} was not found"
utils.send_email(message, access_token)
logger.error(response.json())
#logger.error(response.json())
logger.error(f"response.text: {response.text}")
raise KeyError(message)

def get_shared_calendar(shared_calendar_id, start_date, end_date, access_token):
Expand Down Expand Up @@ -84,7 +86,8 @@ def get_shared_calendar(shared_calendar_id, start_date, end_date, access_token):
if (response.status_code != 200):
message = f'Unable to retrieve shared calendar from {endpoint} endpoint'
utils.send_email(message)
logger.error(response.json())
#logger.error(response.json())
logger.error(f"response.text: {response.text}")
raise ConnectionError(message)

return response.json()
Expand Down Expand Up @@ -350,7 +353,8 @@ def post_batch(access_token, batches, info=None):
message = "Unable to post batch \n" + str(response.json()["error"])
#utils.send_email(user_client, access_token, message)
logger.warning(message)
logger.warning(response.json())
logger.warning(f"response.text: {response.text}")
#logger.warning(response.json())
continue

if info:
Expand Down Expand Up @@ -381,7 +385,8 @@ def get_category(access_token, category_name, category_color):
if (response.status_code != 200):
message = f"Unable to connect to {endpoint} endpoint to retrieve the masterCategories"
utils.send_email(message, access_token)
logger.error(response.json())
#logger.error(response.json())
logger.error(f"response.text: {response.text}")
raise ConnectionError(message)

response = response.json()['value']
Expand Down Expand Up @@ -422,7 +427,8 @@ def create_category(access_token, category_name, category_color):
if response.status_code != 201:
message = f"Unable to create {category_name}"
utils.send_email(message, access_token)
logger.error(response.json())
#logger.error(response.json())
logger.error(f"response.text: {response.text}")
raise ConnectionError(message)
#print("category created")
return category_name
Expand Down
3 changes: 2 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def send_email(message, access_token):
response = requests.post(endpoint, data=json.dumps(payload), headers=header)

if (response.status_code != 202):
logger.error(response.json())
#logger.error(response.json())
logger.error(f"response.text: {response.text}")
raise ConnectionError("Unable to send email")

# TODO: consider a case if the status code isn't 202
Expand Down

0 comments on commit be25f01

Please sign in to comment.