Skip to content

Commit c396fc5

Browse files
committed
Initial commit
0 parents  commit c396fc5

9 files changed

+475
-0
lines changed

.gitignore

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
48+
.pytest_cache/
49+
50+
# Translations
51+
*.mo
52+
*.pot
53+
54+
# Django stuff:
55+
*.log
56+
local_settings.py
57+
db.sqlite3
58+
59+
# Flask stuff:
60+
instance/
61+
.webassets-cache
62+
63+
# Scrapy stuff:
64+
.scrapy
65+
66+
# Sphinx documentation
67+
docs/_build/
68+
69+
# PyBuilder
70+
target/
71+
72+
# Jupyter Notebook
73+
.ipynb_checkpoints
74+
75+
# pyenv
76+
.python-version
77+
78+
# celery beat schedule file
79+
celerybeat-schedule
80+
81+
# SageMath parsed files
82+
*.sage.py
83+
84+
# Environments
85+
.env
86+
.venv
87+
env/
88+
venv/
89+
ENV/
90+
env.bak/
91+
venv.bak/
92+
93+
# Spyder project settings
94+
.spyderproject
95+
.spyproject
96+
97+
# Rope project settings
98+
.ropeproject
99+
100+
# mkdocs documentation
101+
/site
102+
103+
# mypy
104+
.mypy_cache/
105+
106+
#VIM
107+
*.swp
108+
*.swo

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# OMERO user token
2+

appveyor.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
image: ubuntu1804
2+
3+
install:
4+
- sudo apt-get update
5+
- sudo apt-get install -y python-setuptools python-wheel twine
6+
7+
build: off
8+
9+
build_script:
10+
- python setup.py build
11+
12+
#test_script:
13+
# - python3 setup.py test
14+
15+
after_test:
16+
- python setup.py bdist_wheel bdist_egg
17+
18+
artifacts:
19+
- path: dist/*
20+
21+
cache:
22+
- ${HOME}/.eggs -> setup.py

omero_user_token/__init__.py

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2019 Glencoe Software, Inc. All rights reserved.
5+
#
6+
# This software is distributed under the terms described by the LICENSE.txt
7+
# file you can find at the root of the distribution bundle. If the file is
8+
# missing please request a copy by contacting [email protected]
9+
10+
import os
11+
12+
import omero
13+
import omero.all
14+
15+
from configparser import ConfigParser
16+
17+
from omero.rtypes import unwrap
18+
19+
20+
def assert_and_get_token_dir():
21+
home = os.path.expanduser('~')
22+
token_dir = os.path.join(home, '.omero_user_token')
23+
if not os.path.exists(token_dir):
24+
os.makedirs(token_dir)
25+
os.chmod(token_dir, 0700)
26+
return token_dir
27+
28+
29+
def assert_and_get_token_path():
30+
token_dir = assert_and_get_token_dir()
31+
return os.path.join(token_dir, 'token')
32+
33+
34+
def assert_and_get_config_path():
35+
token_dir = assert_and_get_token_dir()
36+
return os.path.join(token_dir, 'config')
37+
38+
39+
CONFIG = ConfigParser()
40+
CONFIG.read(assert_and_get_config_path())
41+
42+
if not CONFIG.has_section('server'):
43+
CONFIG.add_section('server')
44+
CONFIG.set('server', 'host', 'localhost')
45+
CONFIG.set('server', 'port', '4064')
46+
47+
48+
def setter(server, port, user, password, time_to_idle):
49+
client = omero.client(server.encode('utf-8'), port)
50+
try:
51+
session = client.createSession(user, password)
52+
admin_service = session.getAdminService()
53+
session_service = session.getSessionService()
54+
ec = admin_service.getEventContext()
55+
token = '%s@%s:%s' % (unwrap(session_service.createUserSession(
56+
0, # timeToLiveMilliseconds
57+
time_to_idle, # timetoIdleMilliseconds
58+
ec.groupName # defaultGroup
59+
).uuid), server, port)
60+
with open(assert_and_get_token_path(), 'w') as token_file:
61+
token_file.write(token)
62+
return token
63+
finally:
64+
client.closeSession()
65+
66+
67+
def getter():
68+
token_path = assert_and_get_token_path()
69+
if os.path.exists(token_path):
70+
with open(token_path, 'r') as token_file:
71+
return token_file.read()

omero_user_token/cli/__init__.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# encoding: utf-8
2+
#
3+
# Copyright (c) 2017 Glencoe Software, Inc. All rights reserved.
4+
#
5+
# This software is distributed under the terms described by the LICENCE file
6+
# you can find at the root of the distribution bundle.
7+
# If the file is missing please request a copy by contacting
8+
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# encoding: utf-8
2+
#
3+
# Copyright (c) 2019 Glencoe Software, Inc. All rights reserved.
4+
#
5+
# This software is distributed under the terms described by the LICENCE file
6+
# you can find at the root of the distribution bundle.
7+
# If the file is missing please request a copy by contacting
8+
9+
10+
import getpass
11+
12+
import click
13+
14+
from .. import CONFIG, getter, setter
15+
16+
17+
@click.group()
18+
def cli():
19+
pass
20+
21+
22+
@click.command()
23+
@click.option(
24+
'-s', '--server', default=CONFIG.get('server', 'host'), show_default=True,
25+
help="OMERO server hostname"
26+
)
27+
@click.option(
28+
'-p', '--port', default=CONFIG.getint('server', 'port'), type=int,
29+
show_default=True,
30+
help="OMERO server port"
31+
)
32+
@click.option(
33+
'-u', '--user', default=getpass.getuser(), show_default=True,
34+
help="OMERO username"
35+
)
36+
@click.option(
37+
'--time_to_idle', default=2**31 - 1, type=int,
38+
help="Number of seconds to set the timeToIdle value to; "
39+
"defaults to maximum allowed"
40+
)
41+
def _set(server, port, user, time_to_idle):
42+
password = getpass.getpass("Password: ")
43+
token = setter(server, port, user, password, time_to_idle)
44+
print('Successfuly set token: %s' % token)
45+
46+
47+
@click.command()
48+
def _get():
49+
token = getter()
50+
if token is not None:
51+
print(token)
52+
53+
54+
cli.add_command(_set, name='set')
55+
cli.add_command(_get, name='get')
56+
57+
58+
def main():
59+
cli()

omero_user_token/version.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VERSION = '0.1.0rc6.post6.dev83821103'

setup.py

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import os
2+
import sys
3+
4+
from setuptools import setup, find_packages
5+
from setuptools.command.test import test as TestCommand
6+
7+
import version
8+
9+
# Hack to prevent stupid "TypeError: 'NoneType' object is not callable" error
10+
# in multiprocessing/util.py _exit_function when running `python
11+
# setup.py test` or `python setup.py flake8`. See:
12+
# * http://www.eby-sarna.com/pipermail/peak/2010-May/003357.html)
13+
# * https://github.com/getsentry/raven-python/blob/master/setup.py
14+
import multiprocessing
15+
assert multiprocessing # silence flake8
16+
17+
18+
class PyTest(TestCommand):
19+
20+
user_options = [('pytest-args=', 'a', 'Arguments to pass to py.test')]
21+
22+
def initialize_options(self):
23+
TestCommand.initialize_options(self)
24+
self.pytest_args = []
25+
26+
def finalize_options(self):
27+
TestCommand.finalize_options(self)
28+
self.test_args = []
29+
self.test_suite = True
30+
31+
def run_tests(self):
32+
import pytest
33+
if isinstance(self.pytest_args, str):
34+
# pytest requires arguments as a list or tuple even if singular
35+
self.pytest_args = [self.pytest_args]
36+
errno = pytest.main(self.pytest_args)
37+
sys.exit(errno)
38+
39+
40+
def read(fname):
41+
"""
42+
Utility function to read the README file.
43+
:rtype : String
44+
"""
45+
return open(os.path.join(os.path.dirname(__file__), fname)).read()
46+
47+
48+
setup(name='omero-user-token',
49+
version=version.getVersion(),
50+
description='OMERO user token management system',
51+
long_description=read('README.md'),
52+
long_description_content_type='text/markdown',
53+
classifiers=[], # Get strings from
54+
# http://pypi.python.org/pypi?%3Aaction=list_classifiers
55+
keywords='',
56+
author='Glencoe Software, Inc.',
57+
author_email='[email protected]',
58+
url='https://github.com/glencoesoftware/omero-user-token',
59+
license='License :: OSI Approved :: BSD License',
60+
packages=find_packages(),
61+
zip_safe=True,
62+
include_package_data=True,
63+
platforms='any',
64+
setup_requires=['flake8'],
65+
install_requires=[
66+
'click==7.0',
67+
],
68+
tests_require=[],
69+
cmdclass={'test': PyTest},
70+
data_files=[(
71+
'config', [
72+
'message_consumer.cfg.example',
73+
'message-consumer.service'
74+
]
75+
)],
76+
entry_points={
77+
'console_scripts': [
78+
'omero_user_token = omero_user_token.cli.omero_user_token:main',
79+
]
80+
}
81+
)

0 commit comments

Comments
 (0)