Skip to content

Commit

Permalink
[OS-1001] Adding systemd timer to refresh Kano World token (#317)
Browse files Browse the repository at this point in the history
* 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
skarbat authored Aug 1, 2019
1 parent 780dce0 commit a43a4ec
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 2 deletions.
58 changes: 58 additions & 0 deletions bin/kano-refresh-token
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)
1 change: 1 addition & 0 deletions debian/changelog
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

Expand Down
4 changes: 3 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ Depends:
kano-toolset,
kano-touch-support,
kano-os-homedir-content,
kano-notifications (>= 4.2.1)
kano-notifications (>= 4.2.1),
python3-docopt,
python-mercury
Replaces:
kano-settings (<< 1.1-1.20140512build2),
kano-feedback (<< 1.1-3)
Expand Down
1 change: 1 addition & 0 deletions debian/kano-desktop.install
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ bin/kano-track-space usr/bin
bin/kano-boot-splash usr/bin
bin/kano-boot-splash-cli usr/bin
bin/kano-os-loader usr/bin
bin/kano-refresh-token usr/bin

scripts/* usr/share/kano-desktop/scripts

Expand Down
16 changes: 16 additions & 0 deletions systemd/user/kano-common-refresh-token.service
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
16 changes: 16 additions & 0 deletions systemd/user/kano-common-refresh-token.timer
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
3 changes: 2 additions & 1 deletion systemd/user/kano-common.target
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ IgnoreOnIsolate=true
Wants=kano-common-tracker.service kano-common-notifications.service \
kano-boards.service kano-speakerleds.service \
kano-common-keyboard.service kano-home-button.service \
kano-common-track-space.service kano-touch-flip.service
kano-common-track-space.service kano-touch-flip.service \
kano-common-refresh-token.timer

0 comments on commit a43a4ec

Please sign in to comment.