Return full token-info #241
3 changed files with 18 additions and 15 deletions
|
|
@ -4,8 +4,6 @@ import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from itertools import count
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import yaml
|
import yaml
|
||||||
|
|
@ -53,6 +51,11 @@ def main():
|
||||||
else ['admin_tokens', 'collections', 'tokens']
|
else ['admin_tokens', 'collections', 'tokens']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if arguments.server_api.endswith('/'):
|
||||||
|
server_api = arguments.server_api[:-1]
|
||||||
|
else:
|
||||||
|
server_api = arguments.server_api
|
||||||
|
|
||||||
admin_token = os.environ.get('DTS_ADMIN_TOKEN')
|
admin_token = os.environ.get('DTS_ADMIN_TOKEN')
|
||||||
if not admin_token:
|
if not admin_token:
|
||||||
print(
|
print(
|
||||||
|
|
@ -63,7 +66,7 @@ def main():
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
configuration = get_configuration(
|
configuration = get_configuration(
|
||||||
arguments.server_api,
|
server_api,
|
||||||
admin_token,
|
admin_token,
|
||||||
entities,
|
entities,
|
||||||
)
|
)
|
||||||
|
|
@ -167,7 +170,7 @@ def _get_data(
|
||||||
) -> list:
|
) -> list:
|
||||||
result = requests.get(url, headers={'x-dumpthings-token': token})
|
result = requests.get(url, headers={'x-dumpthings-token': token})
|
||||||
if result.status_code >= 300:
|
if result.status_code >= 300:
|
||||||
msg = f'Error downloading {content_class}: {result.text}'
|
msg = f'Error downloading {content_class} from {url}: {result.text}'
|
||||||
raise RuntimeError(msg)
|
raise RuntimeError(msg)
|
||||||
return result.json()
|
return result.json()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,8 @@ def test_collection_adding(fastapi_client_simple):
|
||||||
'name': new_token_request.name,
|
'name': new_token_request.name,
|
||||||
'user_id': new_token_request.user_id,
|
'user_id': new_token_request.user_id,
|
||||||
'collections': new_token_request.model_dump(mode='json')['collections'],
|
'collections': new_token_request.model_dump(mode='json')['collections'],
|
||||||
|
'hashed': new_token_request.hashed,
|
||||||
|
'representation': new_token_request.representation
|
||||||
}
|
}
|
||||||
|
|
||||||
new_record = {
|
new_record = {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
from os import name
|
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
|
|
||||||
from fastapi import (
|
from fastapi import (
|
||||||
|
|
@ -205,7 +204,7 @@ def create_or_replace_token(
|
||||||
)
|
)
|
||||||
async def get_tokens(
|
async def get_tokens(
|
||||||
api_key: str = Depends(api_key_header_scheme),
|
api_key: str = Depends(api_key_header_scheme),
|
||||||
) -> list[TokenResponse]:
|
) -> list[TokenRequest]:
|
||||||
|
|
||||||
instance_state = get_instance_state()
|
instance_state = get_instance_state()
|
||||||
abstract_config = read_config(store_path=instance_state.store_path)
|
abstract_config = read_config(store_path=instance_state.store_path)
|
||||||
|
|
@ -213,10 +212,12 @@ async def get_tokens(
|
||||||
authenticate_admin(instance_state, abstract_config, api_key)
|
authenticate_admin(instance_state, abstract_config, api_key)
|
||||||
|
|
||||||
return [
|
return [
|
||||||
TokenResponse(
|
TokenRequest(
|
||||||
name=n,
|
name=n,
|
||||||
user_id=t.user_id,
|
user_id=t.user_id,
|
||||||
collections=t.collections,
|
collections=t.collections,
|
||||||
|
hashed=t.hashed,
|
||||||
|
representation=t.representation,
|
||||||
)
|
)
|
||||||
for n, t in abstract_config.tokens.items()
|
for n, t in abstract_config.tokens.items()
|
||||||
]
|
]
|
||||||
|
|
@ -230,7 +231,7 @@ async def get_tokens(
|
||||||
async def get_token_with_name(
|
async def get_token_with_name(
|
||||||
token_name: str,
|
token_name: str,
|
||||||
api_key: str = Depends(api_key_header_scheme),
|
api_key: str = Depends(api_key_header_scheme),
|
||||||
) -> TokenResponse:
|
) -> TokenRequest:
|
||||||
|
|
||||||
instance_state = get_instance_state()
|
instance_state = get_instance_state()
|
||||||
abstract_config = get_config()
|
abstract_config = get_config()
|
||||||
|
|
@ -243,10 +244,12 @@ async def get_token_with_name(
|
||||||
raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail=detail)
|
raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail=detail)
|
||||||
|
|
||||||
t = abstract_config.tokens[token_name]
|
t = abstract_config.tokens[token_name]
|
||||||
return TokenResponse(
|
return TokenRequest(
|
||||||
name=token_name,
|
name=token_name,
|
||||||
user_id=t.user_id,
|
user_id=t.user_id,
|
||||||
collections=t.collections,
|
collections=t.collections,
|
||||||
|
hashed=t.hashed,
|
||||||
|
representation=t.representation,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -320,7 +323,7 @@ def create_or_replace_admin_token(
|
||||||
if body.name == '__bootstrap__':
|
if body.name == '__bootstrap__':
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTP_409_CONFLICT,
|
status_code=HTTP_409_CONFLICT,
|
||||||
detail=f"The admin token name '{body.name}' is reserved and cannot be used.",
|
detail=f"The admin token name '{body.name}' is reserved and cannot be used",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check for token content
|
# Check for token content
|
||||||
|
|
@ -389,11 +392,6 @@ async def get_admin_token(
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
return list(abstract_config.admin_tokens) + (
|
|
||||||
[]
|
|
||||||
if instance_state.bootstrap_token is None
|
|
||||||
else ['__bootstrap__']
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@router.delete(
|
@router.delete(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue