예제 #1
0
 def test_admin_read_part(self):
     admin_auth = HmacAuth("edd", self.admin_ice_user.email)
     ice = IceApi(admin_auth)
     # verify that admin user can load specific entry
     entry = ice.get_entry(self.part_ids[0])
     self.assertIsNotNone(entry)
     entry = ice.get_entry(self.part_ids[5])
     self.assertIsNotNone(entry)
예제 #2
0
 def test_none_read_part(self):
     none_auth = HmacAuth("edd", self.none_ice_user.email)
     ice = IceApi(none_auth)
     # verify no permission user cannot load entries
     with self.assertRaises(IceApiException):
         ice.get_entry(self.part_ids[0])
     with self.assertRaises(IceApiException):
         ice.get_entry(self.part_ids[5])
예제 #3
0
 def test_reader_read_part(self):
     reader_auth = HmacAuth("edd", self.read_ice_user.email)
     ice = IceApi(reader_auth)
     # verify that reader user can load specific entry with permission
     entry = ice.get_entry(self.part_ids[0])
     self.assertIsNotNone(entry)
     # verify that reader user cannot load entry without permission
     with self.assertRaises(IceApiException):
         ice.get_entry(self.part_ids[5])
예제 #4
0
파일: forms.py 프로젝트: rpavez/edd
 def load_part_from_ice(self, registry_id):
     update = Update.load_update()
     user_email = update.mod_by.email
     try:
         ice = IceApi(auth=HmacAuth(key_id=settings.ICE_KEY_ID,
                                    username=user_email),
                      verify_ssl_cert=settings.VERIFY_ICE_CERT)
         ice.timeout = settings.ICE_REQUEST_TIMEOUT
         self.entry = ice.get_entry(registry_id)
         self.entry.url = ''.join((
             ice.base_url,
             '/entry/',
             str(self.entry.id),
         ))
     except Exception:
         logger.exception(
             'Exception loading part %(part_id)s from ICE for user '
             '%(user_email)s' % {
                 'part_id': registry_id,
                 'user_email': user_email,
             })
         raise ValidationError(
             _('Failed to load strain %(uuid)s from ICE'),
             code='ice failure',
             params={"uuid": registry_id},
         )
예제 #5
0
    def handle(self, *args, **options):
        # get the username argument
        username = options['username']

        # get ICE authentication configured via EDD's config files (secrets.env and / or
        # settings/local.py)
        auth = HmacAuth(key_id=settings.ICE_KEY_ID, username=username)
        ice = IceApi(auth, verify_ssl_cert=settings.VERIFY_ICE_CERT)
        ice.timeout = settings.ICE_REQUEST_TIMEOUT

        try:
            print('Contacting ICE at %s' % ice.base_url)

            part_id = options.get('part_id')

            if part_id:
                print('Requesting part "%s"' % part_id)
                entry = ice.get_entry(part_id)
                if entry:
                    print('Found the part!')
                else:
                    print('Part "%s" was not found in ICE' % part_id)
            else:

                entries_results_page = ice.search_entries()
                if entries_results_page:
                    self.stdout.write(
                        'Successfully searched ICE for entries.\nICE reports %(total_entries)d '
                        'total entries and returned the first page of  %(returned_entries)d'
                        % {
                            'total_entries':
                            entries_results_page.total_result_count,
                            'returned_entries':
                            entries_results_page.current_result_count,
                        })
                else:
                    print(
                        "No known error occurred, but also didn't find any entries in ICE. If "
                        "user %s has any ICE entries visible to him/her, you might want to "
                        "look into this." % username)
        except Exception as e:
            raise CommandError(e)
예제 #6
0
    def handle(self, *args, **options):
        # get the username argument
        username = options["username"]

        # get ICE authentication configured via EDD's config files (secrets.env and / or
        # settings/local.py)
        auth = HmacAuth(key_id=settings.ICE_KEY_ID, username=username)
        ice = IceApi(auth, verify_ssl_cert=settings.ICE_VERIFY_CERT)
        ice.timeout = settings.ICE_REQUEST_TIMEOUT

        try:
            self.stdout.write("Contacting ICE at %s" % ice.base_url)

            part_id = options.get("part_id")

            if part_id:
                self.stdout.write('Requesting part "%s"' % part_id)
                entry = ice.get_entry(part_id)
                if entry:
                    self.stdout.write("Found the part!")
                else:
                    self.stdout.write(f'Part "{part_id}" was not found in ICE')
            else:
                search_term = options.get("term", "")
                if options.get("advanced", False):
                    self.stdout.write(
                        f'Searching ICE for term "{search_term}" (advanced search)'
                    )
                    results_page = ice.search_entries(search_term)
                    self.print_advanced_search(results_page, username)

                else:
                    self.stdout.write(
                        f'Searching ICE for term "{search_term}" '
                        f"(simple UI-facing search)")
                    entry_info = ice.search(search_term)
                    self.print_simple_search(entry_info)
        except Exception as e:
            raise CommandError(e)
예제 #7
0
 def load_part_from_ice(self, registry_id):
     if self.existing_entry is not None:
         return self.existing_entry
     # using the Update to get the correct user for the search
     update = Update.load_update()
     user_email = update.mod_by.email
     try:
         auth = HmacAuth(key_id=settings.ICE_KEY_ID, username=user_email)
         verify = getattr(settings, "ICE_VERIFY_CERT", True)
         ice = IceApi(auth=auth, verify_ssl_cert=verify)
         ice.timeout = settings.ICE_REQUEST_TIMEOUT
         entry = ice.get_entry(registry_id)
         return entry
     except Exception as e:
         raise ValidationError(
             _("Failed to load strain %(uuid)s from ICE for user %(user)s"),
             code="ice failure",
             params={
                 "user": user_email,
                 "uuid": registry_id
             },
         ) from e
예제 #8
0
파일: forms.py 프로젝트: zhwycsz/edd
 def load_part_from_ice(self, registry_id):
     update = Update.load_update()
     user_email = update.mod_by.email
     try:
         ice = IceApi(
             auth=HmacAuth(key_id=settings.ICE_KEY_ID, username=user_email),
             verify_ssl_cert=settings.ICE_VERIFY_CERT,
         )
         ice.timeout = settings.ICE_REQUEST_TIMEOUT
         self.entry = ice.get_entry(registry_id)
         self.entry.url = f"{ice.base_url}/entry/{self.entry.id}"
     except Exception:
         logger.exception(
             "Exception loading part %(part_id)s from ICE for user "
             "%(user_email)s" % {
                 "part_id": registry_id,
                 "user_email": user_email
             })
         raise ValidationError(
             _("Failed to load strain %(uuid)s from ICE"),
             code="ice failure",
             params={"uuid": registry_id},
         )