@@ -20,8 +20,7 @@ class ResponseStatus:
2020class Options :
2121 product_id : str
2222 client_id : str
23- client_secret : str
24- access_token_url : str
23+ api_key : str
2524 retry_count : int = 10
2625 sleep_seconds : int = 3
2726
@@ -36,34 +35,28 @@ def submit(self, file_path: str, notes: str) -> str:
3635 if not path .exists (file_path ):
3736 raise FileNotFoundError (f"Unable to locate file at { file_path } " )
3837
39- access_token = self ._get_access_token ()
40- operation_id = self ._upload (file_path , access_token )
41- self ._check_upload (operation_id , access_token )
42- return self ._publish (notes , access_token )
38+ operation_id = self ._upload (file_path )
39+ self ._check_upload (operation_id )
40+ return self ._publish (notes )
4341
4442 def fetch_publish_status (self , operation_id : str ) -> dict :
4543 logger .debug (f"Fetching publish status for { operation_id } " )
46- access_token = self ._get_access_token ()
4744 response = requests .get (
4845 self ._publish_status_endpoint (operation_id ),
49- headers = {
50- "Authorization" : f"Bearer { access_token } " ,
51- },
46+ headers = self ._publish_default_headers (),
5247 )
5348
5449 response .raise_for_status ()
5550
5651 logger .debug (f"Publish status response: { response .content .decode ()} " )
5752 return response .json ()
5853
59- def _publish (self , notes : str , access_token : str ) -> str :
54+ def _publish (self , notes : str ) -> str :
6055 logger .debug ("Publishing" )
6156 response = requests .post (
6257 self ._publish_endpoint (),
6358 data = {"notes" : notes },
64- headers = {
65- "Authorization" : f"Bearer { access_token } " ,
66- },
59+ headers = self ._publish_default_headers (),
6760 )
6861
6962 response .raise_for_status ()
@@ -72,15 +65,15 @@ def _publish(self, notes: str, access_token: str) -> str:
7265
7366 return response .headers ["Location" ]
7467
75- def _upload (self , file_path : str , access_token : str ) -> str :
68+ def _upload (self , file_path : str ) -> str :
7669 logger .debug (f"Uploading { file_path } " )
7770 with open (file_path , "rb" ) as f :
7871 response = requests .post (
7972 self ._upload_endpoint (),
8073 data = f ,
8174 headers = {
82- "Authorization" : f"Bearer { access_token } " ,
8375 "Content-Type" : "application/zip" ,
76+ ** self ._publish_default_headers (),
8477 },
8578 )
8679
@@ -93,7 +86,6 @@ def _upload(self, file_path: str, access_token: str) -> str:
9386 def _check_upload (
9487 self ,
9588 operation_id ,
96- access_token : str ,
9789 ) -> str :
9890 logger .debug ("Checking upload" )
9991
@@ -106,9 +98,7 @@ def _check_upload(
10698 ):
10799 response = requests .get (
108100 self ._status_endpoint (operation_id ),
109- headers = {
110- "Authorization" : f"Bearer { access_token } " ,
111- },
101+ headers = self ._publish_default_headers (),
112102 )
113103
114104 response .raise_for_status ()
@@ -129,23 +119,6 @@ def _check_upload(
129119
130120 return upload_status
131121
132- def _get_access_token (self ) -> str :
133- response = requests .post (
134- self .options .access_token_url ,
135- data = {
136- "client_id" : self .options .client_id ,
137- "scope" : f"{ self .BASE_URL } /.default" ,
138- "client_secret" : self .options .client_secret ,
139- "grant_type" : "client_credentials" ,
140- },
141- )
142-
143- response .raise_for_status ()
144-
145- json = response .json ()
146-
147- return json ["access_token" ]
148-
149122 def _product_endpoint (self ) -> str :
150123 return f"{ self .BASE_URL } /v1/products/{ self .options .product_id } "
151124
@@ -160,3 +133,9 @@ def _status_endpoint(self, operation_id: str) -> str:
160133
161134 def _publish_status_endpoint (self , operation_id : str ) -> str :
162135 return f"{ self ._publish_endpoint ()} /operations/{ operation_id } "
136+
137+ def _publish_default_headers (self ):
138+ return {
139+ "Authorization" : f"ApiKey { self .options .api_key } " ,
140+ "X-ClientID" : self .options .client_id ,
141+ }
0 commit comments