Commit c53537ec authored by Daniel Schreiber's avatar Daniel Schreiber

helper tool to fetch remote resource information

parent 01f9125a
Pipeline #27460 failed with stage
in 11 seconds
from __future__ import unicode_literals
from datetime import date, timedelta, datetime
from django.conf import settings
from import BaseCommand
from django.db import transaction
from django.utils import timezone
import requests
from rest_framework.reverse import reverse
from urlparse import urljoin
from api.models import Resource, UserType, TokenAuthUser
from api.utils.queue_utils import dispatch_deletion_sync
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument("uuid", nargs="+")
def handle(self, *args, **options):
for uuid in options['uuid']:
res = Resource.objects.get(uuid=uuid)
remote_user = TokenAuthUser.objects.get(realm=res.realm_idp, user_type=UserType.TYPE_SYNC)
headers = {'Authorization': 'token ' + remote_user.token()}
url = remote_user.remote_reverse('resource_detail', args=(uuid,))
req = requests.get(url, headers=headers)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment