-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OS-1001] Adding systemd timer to refresh Kano World token (#317)
* Adding systemd timer to refresh Kano World token * Removed Copy&Paste spurious line * Updating changelog, docopt dependency * Adding the token refresh script * adding dependency on python3 mercury bindings * Changing the logic to refresh the token * Change systemd service, forking for oneshot * Replacing prints for logger calls * Docopt for the script, replaced kano.logging for print, because it's python2 * Simplify verbose variable assignment
- Loading branch information
Showing
7 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright (C) 2019 Kano Computing Ltd. | ||
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL v2 | ||
# | ||
# kano-refresh-token | ||
# | ||
# Python3 script to refresh the Kano World login token, using the new API. | ||
# | ||
|
||
''' | ||
Command line tool for refreshing the Kano World login token | ||
Usage: | ||
kano-refresh-token refresh [--verbose] | ||
kano-refresh-token -h | --help | ||
Commands: | ||
refresh Request a token refresh to the server if the user is logged in | ||
Options | ||
-v, --verbose Explain the steps taken | ||
''' | ||
|
||
import docopt | ||
import mercury | ||
import os | ||
import sys | ||
|
||
|
||
def debug_print(verbose, literal): | ||
if verbose: | ||
print(literal) | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
rc = 1 | ||
args = docopt.docopt(__doc__) | ||
verbose = args['--verbose'] | ||
|
||
# TODO: add docopt, move out code into a function, implement a test option | ||
debug_print(verbose, 'accessing mercury KanoWorld') | ||
w = mercury.KanoWorld() | ||
logged_in = w.is_logged_in(True) | ||
if logged_in: | ||
debug_print(verbose, 'user is logged in, refreshing the token') | ||
success = w.refresh_token(w.token, True) | ||
if success: | ||
rc = 0 | ||
debug_print(verbose, 'new token: {}'.format(w.token)) | ||
else: | ||
debug_print(verbose, 'error refreshing token') | ||
else: | ||
debug_print(verbose, 'user is not logged in, nothing to do') | ||
|
||
sys.exit(rc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
kano-desktop (4.3.0-0) unstable; urgency=low | ||
|
||
* Removed master_preferences for Chromium from this project | ||
* Added service to automatically refresh Kano World login token | ||
|
||
-- Team Kano <[email protected]> Mon, 8 Apr 2019 18:30:00 +0100 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# | ||
# kano-common-refresh-token.service | ||
# | ||
# Invokes the kano-renew-token script to make sure the | ||
# Kano World login token does not expire. | ||
# | ||
# This service file is invoked through the kano-common-refresh-token.timer unit. | ||
# | ||
|
||
[Unit] | ||
Description=Kano World Token Refresh | ||
IgnoreOnIsolate=true | ||
|
||
[Service] | ||
ExecStart=-/usr/bin/kano-refresh-token | ||
Type=oneshot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# | ||
# kano-common-refresh-token.timer | ||
# | ||
# Systemd timer service to periodically refresh the Kano World login token. | ||
# | ||
# This timer is bound to the kano-common.target file, | ||
# and it will call the Unit file described below when triggered. | ||
# | ||
# Use "systemctl --user list-timers --all" to query the status of this timer. | ||
# | ||
|
||
[Timer] | ||
OnBootSec=60sec | ||
OnUnitActiveSec=60min | ||
|
||
Unit=kano-common-refresh-token.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters