mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-16 03:38:03 +01:00
Rename user_token to api_token
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
class AuthCommand(object):
|
||||
|
||||
def __init__(self, api_url, user_token):
|
||||
def __init__(self, api_url, api_token):
|
||||
self.api_url = api_url
|
||||
self.user_token = user_token
|
||||
self.api_token = api_token
|
||||
|
||||
def execute(self):
|
||||
url = '%s/connect/%s' % (self.api_url, self.user_token)
|
||||
url = '%s/connect/%s' % (self.api_url, self.api_token)
|
||||
print('Open following URL in your browser to authenticate and/or ' \
|
||||
'claim recorded asciicasts:\n%s' % url)
|
||||
|
||||
@@ -38,9 +38,9 @@ def get_command(argv, config):
|
||||
skip_confirmation = True
|
||||
|
||||
if command == 'rec':
|
||||
return RecordCommand(config.api_url, config.user_token, cmd, title,
|
||||
return RecordCommand(config.api_url, config.api_token, cmd, title,
|
||||
skip_confirmation)
|
||||
elif command == 'auth':
|
||||
return AuthCommand(config.api_url, config.user_token)
|
||||
return AuthCommand(config.api_url, config.api_token)
|
||||
|
||||
return ErrorCommand("'%s' is not an asciinema command" % command)
|
||||
|
||||
@@ -7,10 +7,10 @@ from asciinema.confirmator import Confirmator
|
||||
|
||||
class RecordCommand(object):
|
||||
|
||||
def __init__(self, api_url, user_token, cmd, title, skip_confirmation,
|
||||
def __init__(self, api_url, api_token, cmd, title, skip_confirmation,
|
||||
recorder=None, uploader=None, confirmator=None):
|
||||
self.api_url = api_url
|
||||
self.user_token = user_token
|
||||
self.api_token = api_token
|
||||
self.cmd = cmd
|
||||
self.title = title
|
||||
self.skip_confirmation = skip_confirmation
|
||||
@@ -42,7 +42,7 @@ class RecordCommand(object):
|
||||
if self._upload_confirmed():
|
||||
print('~ Uploading...')
|
||||
try:
|
||||
url = self.uploader.upload(self.api_url, self.user_token, asciicast)
|
||||
url = self.uploader.upload(self.api_url, self.api_token, asciicast)
|
||||
print(url)
|
||||
except SystemExit:
|
||||
print('~ Error during upload. Try again in a minute.')
|
||||
|
||||
@@ -45,18 +45,18 @@ class Config:
|
||||
return api_url
|
||||
|
||||
@property
|
||||
def user_token(self):
|
||||
def api_token(self):
|
||||
try:
|
||||
user_token = self.config.get('user', 'token')
|
||||
api_token = self.config.get('user', 'token')
|
||||
except NoOptionError:
|
||||
user_token = str(uuid.uuid1())
|
||||
self.config.set('user', 'token', user_token)
|
||||
api_token = str(uuid.uuid1())
|
||||
self.config.set('user', 'token', api_token)
|
||||
|
||||
self._ensure_base_dir()
|
||||
with open(self.path, 'w') as f:
|
||||
self.config.write(f)
|
||||
|
||||
return user_token
|
||||
return api_token
|
||||
|
||||
def _ensure_base_dir(self):
|
||||
dir = os.path.dirname(self.path)
|
||||
|
||||
@@ -9,19 +9,19 @@ class Uploader(object):
|
||||
def __init__(self, http_adapter=None):
|
||||
self.http_adapter = http_adapter if http_adapter is not None else RequestsHttpAdapter()
|
||||
|
||||
def upload(self, api_url, user_token, asciicast):
|
||||
def upload(self, api_url, api_token, asciicast):
|
||||
url = '%s/api/asciicasts' % api_url
|
||||
files = self._asciicast_files(asciicast, user_token)
|
||||
files = self._asciicast_files(asciicast, api_token)
|
||||
|
||||
status, headers, body = self.http_adapter.post(url, files=files)
|
||||
|
||||
return body
|
||||
|
||||
def _asciicast_files(self, asciicast, user_token):
|
||||
def _asciicast_files(self, asciicast, api_token):
|
||||
return {
|
||||
'asciicast[stdout]': self._stdout_data_file(asciicast.stdout),
|
||||
'asciicast[stdout_timing]': self._stdout_timing_file(asciicast.stdout),
|
||||
'asciicast[meta]': self._meta_file(asciicast, user_token)
|
||||
'asciicast[meta]': self._meta_file(asciicast, api_token)
|
||||
}
|
||||
|
||||
def _stdout_data_file(self, stdout):
|
||||
@@ -30,12 +30,12 @@ class Uploader(object):
|
||||
def _stdout_timing_file(self, stdout):
|
||||
return ('stdout.time', bz2.compress(stdout.timing))
|
||||
|
||||
def _meta_file(self, asciicast, user_token):
|
||||
return ('meta.json', self._meta_json(asciicast, user_token))
|
||||
def _meta_file(self, asciicast, api_token):
|
||||
return ('meta.json', self._meta_json(asciicast, api_token))
|
||||
|
||||
def _meta_json(self, asciicast, user_token):
|
||||
def _meta_json(self, asciicast, api_token):
|
||||
meta_data = asciicast.meta_data()
|
||||
auth_data = { 'user_token': user_token }
|
||||
auth_data = { 'user_token': api_token }
|
||||
data = dict(list(meta_data.items()) + list(auth_data.items()))
|
||||
|
||||
return json.dumps(data)
|
||||
|
||||
@@ -13,7 +13,7 @@ class Config(object):
|
||||
def api_url(self):
|
||||
return 'http://api/url'
|
||||
|
||||
def user_token(self):
|
||||
def api_token(self):
|
||||
return 'a-toh-can'
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class TestGetCommand(object):
|
||||
|
||||
assert_equal(RecordCommand, type(command))
|
||||
assert_equal(self.config.api_url, command.api_url)
|
||||
assert_equal(self.config.user_token, command.user_token)
|
||||
assert_equal(self.config.api_token, command.api_token)
|
||||
assert_equal(None, command.cmd)
|
||||
assert_equal(None, command.title)
|
||||
assert_equal(False, command.skip_confirmation)
|
||||
@@ -43,7 +43,7 @@ class TestGetCommand(object):
|
||||
|
||||
assert_equal(RecordCommand, type(command))
|
||||
assert_equal(self.config.api_url, command.api_url)
|
||||
assert_equal(self.config.user_token, command.user_token)
|
||||
assert_equal(self.config.api_token, command.api_token)
|
||||
assert_equal('/bin/bash -l', command.cmd)
|
||||
assert_equal("O'HAI LOL", command.title)
|
||||
assert_equal(True, command.skip_confirmation)
|
||||
@@ -53,7 +53,7 @@ class TestGetCommand(object):
|
||||
|
||||
assert_equal(AuthCommand, type(command))
|
||||
assert_equal(self.config.api_url, command.api_url)
|
||||
assert_equal(self.config.user_token, command.user_token)
|
||||
assert_equal(self.config.api_token, command.api_token)
|
||||
|
||||
def test_get_command_when_options_include_h(self):
|
||||
command = get_command(['-h'], self.config)
|
||||
|
||||
@@ -37,25 +37,25 @@ class TestConfig(object):
|
||||
'ASCIINEMA_API_URL': 'http://the/url2' })
|
||||
assert_equal('http://the/url2', config.api_url)
|
||||
|
||||
def test_user_token_when_no_file(self):
|
||||
def test_api_token_when_no_file(self):
|
||||
config = create_config()
|
||||
|
||||
assert re.match('^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}', config.user_token)
|
||||
assert re.match('^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}', config.api_token)
|
||||
assert os.path.isfile(config.path)
|
||||
|
||||
def test_user_token_when_no_dir(self):
|
||||
def test_api_token_when_no_dir(self):
|
||||
config = create_config()
|
||||
dir = os.path.dirname(config.path)
|
||||
os.rmdir(dir)
|
||||
|
||||
assert re.match('^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}', config.user_token)
|
||||
assert re.match('^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}', config.api_token)
|
||||
assert os.path.isfile(config.path)
|
||||
|
||||
def test_user_token_when_no_token_set(self):
|
||||
def test_api_token_when_no_token_set(self):
|
||||
config = create_config('')
|
||||
assert re.match('^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}', config.user_token)
|
||||
assert re.match('^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}', config.api_token)
|
||||
|
||||
def test_user_token_when_token_set(self):
|
||||
def test_api_token_when_token_set(self):
|
||||
token = 'foo-bar-baz'
|
||||
config = create_config("[user]\ntoken = %s" % token)
|
||||
assert re.match(token, config.user_token)
|
||||
assert re.match(token, config.api_token)
|
||||
|
||||
@@ -28,8 +28,8 @@ class FakeUploader(object):
|
||||
def __init__(self):
|
||||
self.uploaded = None
|
||||
|
||||
def upload(self, api_url, user_token, asciicast):
|
||||
self.uploaded = [api_url, user_token, asciicast]
|
||||
def upload(self, api_url, api_token, asciicast):
|
||||
self.uploaded = [api_url, api_token, asciicast]
|
||||
return 'http://asciicast/url'
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user