Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OS-1001] Adding systemd timer to refresh Kano World token #317

Merged
merged 10 commits into from Aug 1, 2019
58 changes: 58 additions & 0 deletions bin/kano-refresh-token
@@ -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 = True if args['--verbose'] else False
skarbat marked this conversation as resolved.
Show resolved Hide resolved

# 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
@@ -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 <dev@kano.me> Mon, 8 Apr 2019 18:30:00 +0100

Expand Down
4 changes: 3 additions & 1 deletion debian/control
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
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
@@ -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
@@ -0,0 +1,16 @@
#
# kano-common-refresh-token.timer
skarbat marked this conversation as resolved.
Show resolved Hide resolved
#
# 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
skarbat marked this conversation as resolved.
Show resolved Hide resolved

Unit=kano-common-refresh-token.service
3 changes: 2 additions & 1 deletion systemd/user/kano-common.target
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