Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nleiva/check-calendar
Simple app to verify whether a time slot is taken/busy in Google Calendar from Ansible.
https://github.com/nleiva/check-calendar
ansible google-calendar
Last synced: 3 months ago
JSON representation
Simple app to verify whether a time slot is taken/busy in Google Calendar from Ansible.
- Host: GitHub
- URL: https://github.com/nleiva/check-calendar
- Owner: nleiva
- License: gpl-3.0
- Created: 2020-08-31T19:03:32.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-10-09T19:04:36.000Z (over 4 years ago)
- Last Synced: 2023-02-27T09:24:05.148Z (almost 2 years ago)
- Topics: ansible, google-calendar
- Language: Go
- Homepage:
- Size: 38.7 MB
- Stars: 3
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Check Calendar
![Ansible Lint](https://github.com/nleiva/check-calendar/workflows/Ansible%20Lint/badge.svg)
Simple app to verify whether a timeslot is taken/busy or not from Ansible.
## Requirements
### Go
If you want to compile the examples, you need Go installed. Otherwise you can use the binaries included for convenience in [here](roles/go-role/library).
### Google Calendar API
You need to [turn on the Google Calendar API](https://developers.google.com/calendar/quickstart/go#step_1_turn_on_the) and download your OAuth 2.0 client credentials (json file) from [API Credentials](https://console.developers.google.com/apis/credentials) as in the image below.
Name this file as `desktop.json`, as we reference it in the code.
```go
b, err := ioutil.ReadFile("desktop.json")
if err != nil {
return false, fmt.Errorf("Unable to read client secret file: %v", err)
}
```The file `token.json` will be automatically generated once an API Token has been granted. Store this file securely as it will have a refresh token that never expires.
## Compiling
To compile your own binaries for multiple target Operating Systems (`GOOS`), run `make compile`. The binaries in this repo were compiled in an `amd64` platform (`GOARCH`).
## Testing
### Manually
Execute `make test-manual`. You need an arguments file named `args.json` with something like:
```json
{
"Name": "Test",
"Time": "2020-09-01T19:50:00Z"
}
```**Note**: Z is the zone designator for the zero UTC offset.
### From Ansible
Execute: `make test-ansible`.
```yaml
...
- name: Test the module (from role)
calendar_linux:
name: Testing the Calendar module
time: "{{ ansible_date_time.iso8601 }}"
register: output
...
```If you are running this during a big event or scheduled maintenance window, the module will return true so you can act accordingly. See this calendar example:
The output would look as follows. Notice `"busy": true` or `"msg": "The timeslot 2020-09-02T17:53:43Z is busy: true"`.
```ruby
$ make test-ansible
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'PLAY [Test Calendar module] **********************************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************************************
ok: [localhost]TASK [Print the time (ISO 8601) - Module input] **************************************************************************************************************
ok: [localhost] => {
"ansible_date_time.iso8601": "2020-09-02T17:53:43Z"
}TASK [go-role : Test the module (from role)] *****************************************************************************************************************
included: /home/centos/check-calendar/roles/go-role/tasks/Linux.yml for localhostTASK [go-role : Test the module (from role) on Linux [Linux]] ************************************************************************************************
ok: [localhost]TASK [Print out Calendar module output] **********************************************************************************************************************
ok: [localhost] => {
"output": {
"busy": true,
"changed": false,
"failed": false,
"msg": "The timeslot 2020-09-02T17:53:43Z is busy: true"
}
}PLAY RECAP ***************************************************************************************************************************************************
localhost : ok=5 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```## Art work
Repo image from [Maria Letta's Free Gophers Pack](https://github.com/MariaLetta/free-gophers-pack)