@@ -118,16 +118,15 @@ def __init__(
118
118
):
119
119
confluence_kwargs = confluence_kwargs or {}
120
120
errors = ConfluenceLoader .validate_init_args (
121
- url , api_key , username , oauth2 , token
121
+ url = url ,
122
+ api_key = api_key ,
123
+ username = username ,
124
+ session = session ,
125
+ oauth2 = oauth2 ,
126
+ token = token ,
122
127
)
123
128
if errors :
124
129
raise ValueError (f"Error(s) while validating input: { errors } " )
125
-
126
- self .base_url = url
127
- self .number_of_retries = number_of_retries
128
- self .min_retry_seconds = min_retry_seconds
129
- self .max_retry_seconds = max_retry_seconds
130
-
131
130
try :
132
131
from atlassian import Confluence # noqa: F401
133
132
except ImportError :
@@ -136,6 +135,11 @@ def __init__(
136
135
"`pip install atlassian-python-api`"
137
136
)
138
137
138
+ self .base_url = url
139
+ self .number_of_retries = number_of_retries
140
+ self .min_retry_seconds = min_retry_seconds
141
+ self .max_retry_seconds = max_retry_seconds
142
+
139
143
if session :
140
144
self .confluence = Confluence (url = url , session = session , ** confluence_kwargs )
141
145
elif oauth2 :
@@ -160,6 +164,7 @@ def validate_init_args(
160
164
url : Optional [str ] = None ,
161
165
api_key : Optional [str ] = None ,
162
166
username : Optional [str ] = None ,
167
+ session : Optional [requests .Session ] = None ,
163
168
oauth2 : Optional [dict ] = None ,
164
169
token : Optional [str ] = None ,
165
170
) -> Union [List , None ]:
@@ -175,33 +180,28 @@ def validate_init_args(
175
180
"the other must be as well."
176
181
)
177
182
178
- if (api_key or username ) and oauth2 :
183
+ non_null_creds = list (
184
+ x is not None for x in ((api_key or username ), session , oauth2 , token )
185
+ )
186
+ if sum (non_null_creds ) > 1 :
187
+ all_names = ("(api_key, username)" , "session" , "oath2" , "token" )
188
+ provided = tuple (n for x , n in zip (non_null_creds , all_names ) if x )
179
189
errors .append (
180
- "Cannot provide a value for `api_key` and/or "
181
- "`username` and provide a value for `oauth2` "
190
+ f "Cannot provide a value for more than one of: { all_names } . Received "
191
+ f"values for: { provided } "
182
192
)
183
-
184
- if oauth2 and oauth2 .keys () != [
193
+ if oauth2 and set (oauth2 .keys ()) != {
185
194
"access_token" ,
186
195
"access_token_secret" ,
187
196
"consumer_key" ,
188
197
"key_cert" ,
189
- ] :
198
+ } :
190
199
errors .append (
191
200
"You have either omitted require keys or added extra "
192
201
"keys to the oauth2 dictionary. key values should be "
193
202
"`['access_token', 'access_token_secret', 'consumer_key', 'key_cert']`"
194
203
)
195
-
196
- if token and (api_key or username or oauth2 ):
197
- errors .append (
198
- "Cannot provide a value for `token` and a value for `api_key`, "
199
- "`username` or `oauth2`"
200
- )
201
-
202
- if errors :
203
- return errors
204
- return None
204
+ return errors or None
205
205
206
206
def load (
207
207
self ,
0 commit comments