|
21 | 21 | PIHandlerWeb, |
22 | 22 | get_auth_aspen, |
23 | 23 | get_auth_pi, |
| 24 | + get_url_aspen, |
24 | 25 | list_aspenone_sources, |
25 | 26 | list_piwebapi_sources, |
26 | 27 | ) |
@@ -121,17 +122,34 @@ def get_handler( |
121 | 122 | url: Optional[str], |
122 | 123 | options: Dict[str, Union[int, float, str]], |
123 | 124 | verify_ssl: Optional[Union[bool, str]], |
124 | | - auth: Optional[Any], |
| 125 | + auth: Optional[Any] = None, |
125 | 126 | cache: Optional[Union[SmartCache, BucketCache]] = None, |
126 | 127 | ): |
127 | 128 | if imstype is None: |
| 129 | + orig_auth = auth |
| 130 | + orig_url = url |
128 | 131 | try: |
129 | | - if datasource in list_aspenone_sources( |
| 132 | + aspen_source = list_aspenone_sources( |
130 | 133 | url=None, auth=None, verify_ssl=verify_ssl |
131 | | - ): |
132 | | - imstype = IMSType.ASPENONE |
133 | | - except requests.exceptions.HTTPError as e: |
134 | | - logger.debug(f"Could not list Aspenone sources: {e}") |
| 134 | + ) |
| 135 | + except requests.exceptions.HTTPError: |
| 136 | + # Try again using app registration auth |
| 137 | + try: |
| 138 | + auth = get_auth_aspen(False) |
| 139 | + url = get_url_aspen(False) |
| 140 | + aspen_source = list_aspenone_sources( |
| 141 | + auth=auth, url=url, verify_ssl=verify_ssl |
| 142 | + ) |
| 143 | + except requests.exceptions.HTTPError as e: |
| 144 | + logger.debug(f"Could not list Aspenone sources: {e}") |
| 145 | + aspen_source = [] |
| 146 | + |
| 147 | + if datasource in aspen_source: |
| 148 | + imstype = IMSType.ASPENONE |
| 149 | + else: |
| 150 | + auth = orig_auth |
| 151 | + url = orig_url |
| 152 | + |
135 | 153 | if imstype is None: |
136 | 154 | try: |
137 | 155 | if datasource in list_piwebapi_sources( |
|
0 commit comments