@@ -20,8 +20,7 @@ class ResponseStatus:
20
20
class Options :
21
21
product_id : str
22
22
client_id : str
23
- client_secret : str
24
- access_token_url : str
23
+ api_key : str
25
24
retry_count : int = 10
26
25
sleep_seconds : int = 3
27
26
@@ -36,34 +35,28 @@ def submit(self, file_path: str, notes: str) -> str:
36
35
if not path .exists (file_path ):
37
36
raise FileNotFoundError (f"Unable to locate file at { file_path } " )
38
37
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 )
43
41
44
42
def fetch_publish_status (self , operation_id : str ) -> dict :
45
43
logger .debug (f"Fetching publish status for { operation_id } " )
46
- access_token = self ._get_access_token ()
47
44
response = requests .get (
48
45
self ._publish_status_endpoint (operation_id ),
49
- headers = {
50
- "Authorization" : f"Bearer { access_token } " ,
51
- },
46
+ headers = self ._publish_default_headers (),
52
47
)
53
48
54
49
response .raise_for_status ()
55
50
56
51
logger .debug (f"Publish status response: { response .content .decode ()} " )
57
52
return response .json ()
58
53
59
- def _publish (self , notes : str , access_token : str ) -> str :
54
+ def _publish (self , notes : str ) -> str :
60
55
logger .debug ("Publishing" )
61
56
response = requests .post (
62
57
self ._publish_endpoint (),
63
58
data = {"notes" : notes },
64
- headers = {
65
- "Authorization" : f"Bearer { access_token } " ,
66
- },
59
+ headers = self ._publish_default_headers (),
67
60
)
68
61
69
62
response .raise_for_status ()
@@ -72,15 +65,15 @@ def _publish(self, notes: str, access_token: str) -> str:
72
65
73
66
return response .headers ["Location" ]
74
67
75
- def _upload (self , file_path : str , access_token : str ) -> str :
68
+ def _upload (self , file_path : str ) -> str :
76
69
logger .debug (f"Uploading { file_path } " )
77
70
with open (file_path , "rb" ) as f :
78
71
response = requests .post (
79
72
self ._upload_endpoint (),
80
73
data = f ,
81
74
headers = {
82
- "Authorization" : f"Bearer { access_token } " ,
83
75
"Content-Type" : "application/zip" ,
76
+ ** self ._publish_default_headers (),
84
77
},
85
78
)
86
79
@@ -93,7 +86,6 @@ def _upload(self, file_path: str, access_token: str) -> str:
93
86
def _check_upload (
94
87
self ,
95
88
operation_id ,
96
- access_token : str ,
97
89
) -> str :
98
90
logger .debug ("Checking upload" )
99
91
@@ -106,9 +98,7 @@ def _check_upload(
106
98
):
107
99
response = requests .get (
108
100
self ._status_endpoint (operation_id ),
109
- headers = {
110
- "Authorization" : f"Bearer { access_token } " ,
111
- },
101
+ headers = self ._publish_default_headers (),
112
102
)
113
103
114
104
response .raise_for_status ()
@@ -129,23 +119,6 @@ def _check_upload(
129
119
130
120
return upload_status
131
121
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
-
149
122
def _product_endpoint (self ) -> str :
150
123
return f"{ self .BASE_URL } /v1/products/{ self .options .product_id } "
151
124
@@ -160,3 +133,9 @@ def _status_endpoint(self, operation_id: str) -> str:
160
133
161
134
def _publish_status_endpoint (self , operation_id : str ) -> str :
162
135
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