egain-api-python 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- egain_api_python/__init__.py +17 -0
- egain_api_python/_hooks/__init__.py +5 -0
- egain_api_python/_hooks/registration.py +13 -0
- egain_api_python/_hooks/sdkhooks.py +76 -0
- egain_api_python/_hooks/types.py +112 -0
- egain_api_python/_version.py +15 -0
- egain_api_python/aiservices.py +23 -0
- egain_api_python/answers.py +281 -0
- egain_api_python/articlelists.py +469 -0
- egain_api_python/basesdk.py +368 -0
- egain_api_python/connectorssearchevents.py +537 -0
- egain_api_python/content.py +23 -0
- egain_api_python/errors/__init__.py +78 -0
- egain_api_python/errors/egaindefaulterror.py +40 -0
- egain_api_python/errors/egainerror.py +30 -0
- egain_api_python/errors/gethealthop.py +74 -0
- egain_api_python/errors/no_response_error.py +17 -0
- egain_api_python/errors/responsevalidationerror.py +27 -0
- egain_api_python/errors/schemas_wserrorcommon.py +51 -0
- egain_api_python/errors/wserrorcommon.py +49 -0
- egain_api_python/escalation.py +955 -0
- egain_api_python/export.py +487 -0
- egain_api_python/federatedsearchevent.py +287 -0
- egain_api_python/general.py +925 -0
- egain_api_python/guidedhelp.py +3373 -0
- egain_api_python/health.py +253 -0
- egain_api_python/httpclient.py +125 -0
- egain_api_python/import_.py +1161 -0
- egain_api_python/models/__init__.py +2136 -0
- egain_api_python/models/acceptghsolutionop.py +52 -0
- egain_api_python/models/acceptlanguage.py +23 -0
- egain_api_python/models/accessibleportal.py +37 -0
- egain_api_python/models/action.py +56 -0
- egain_api_python/models/actionsearch.py +92 -0
- egain_api_python/models/addasreferenceop.py +52 -0
- egain_api_python/models/addbookmarkop.py +43 -0
- egain_api_python/models/additionalsnippets.py +57 -0
- egain_api_python/models/addtoreplyop.py +52 -0
- egain_api_python/models/aisearchop.py +131 -0
- egain_api_python/models/aisearchresponse.py +67 -0
- egain_api_python/models/allaccessibleportals.py +28 -0
- egain_api_python/models/answer.py +21 -0
- egain_api_python/models/answeredquestion.py +125 -0
- egain_api_python/models/answerrange.py +41 -0
- egain_api_python/models/answersrequest.py +78 -0
- egain_api_python/models/answersresponse.py +93 -0
- egain_api_python/models/article.py +241 -0
- egain_api_python/models/articleactivitylink.py +62 -0
- egain_api_python/models/articleadditionalattributes.py +23 -0
- egain_api_python/models/articleaisearchresult.py +254 -0
- egain_api_python/models/articleattachment.py +44 -0
- egain_api_python/models/articlelist.py +48 -0
- egain_api_python/models/articlelistresult.py +38 -0
- egain_api_python/models/articlelistsresult.py +22 -0
- egain_api_python/models/articlepermissions.py +25 -0
- egain_api_python/models/articlepermissionsresult.py +27 -0
- egain_api_python/models/articlerating.py +51 -0
- egain_api_python/models/articleratingsresponse.py +28 -0
- egain_api_python/models/articleresult.py +159 -0
- egain_api_python/models/articleresultadditionalattributes.py +22 -0
- egain_api_python/models/articleresults.py +32 -0
- egain_api_python/models/articlesearchresult.py +243 -0
- egain_api_python/models/articlesearchresults.py +32 -0
- egain_api_python/models/articlesort.py +11 -0
- egain_api_python/models/articlesortorder.py +11 -0
- egain_api_python/models/articletype.py +56 -0
- egain_api_python/models/articlewitheditions.py +227 -0
- egain_api_python/models/attachment.py +31 -0
- egain_api_python/models/attachmentadditionalattributes.py +10 -0
- egain_api_python/models/attachmentcontent.py +57 -0
- egain_api_python/models/attachmentcontentresult.py +22 -0
- egain_api_python/models/attachmentforcreatesuggestion.py +25 -0
- egain_api_python/models/attachments.py +35 -0
- egain_api_python/models/attachmentsummary.py +37 -0
- egain_api_python/models/attachmentupload.py +20 -0
- egain_api_python/models/avertcustomerescalationop.py +44 -0
- egain_api_python/models/bookmark.py +57 -0
- egain_api_python/models/bookmarkresult.py +26 -0
- egain_api_python/models/bookmarkstatus.py +34 -0
- egain_api_python/models/case.py +158 -0
- egain_api_python/models/caseadditionalattributes.py +11 -0
- egain_api_python/models/caseanswer.py +21 -0
- egain_api_python/models/casebase.py +67 -0
- egain_api_python/models/casebaseresult.py +28 -0
- egain_api_python/models/casebasesearchsettings.py +26 -0
- egain_api_python/models/caselistresult.py +74 -0
- egain_api_python/models/caselistresults.py +28 -0
- egain_api_python/models/casequestion.py +16 -0
- egain_api_python/models/casequestiondetail.py +29 -0
- egain_api_python/models/casesearch.py +80 -0
- egain_api_python/models/clusterid.py +16 -0
- egain_api_python/models/clusterresult.py +37 -0
- egain_api_python/models/clusterresults.py +28 -0
- egain_api_python/models/comment.py +33 -0
- egain_api_python/models/comments.py +26 -0
- egain_api_python/models/completecustomerescalationop.py +44 -0
- egain_api_python/models/compliancearticleresult.py +166 -0
- egain_api_python/models/compliancearticleresultadditionalattributes.py +22 -0
- egain_api_python/models/compliancearticleresults.py +35 -0
- egain_api_python/models/complianceforarticle.py +59 -0
- egain_api_python/models/complyarticleop.py +40 -0
- egain_api_python/models/components_schemas_tag.py +25 -0
- egain_api_python/models/components_schemas_tagcategory.py +39 -0
- egain_api_python/models/components_schemas_taggroup.py +25 -0
- egain_api_python/models/configurableattribute.py +25 -0
- egain_api_python/models/configurableattributes.py +15 -0
- egain_api_python/models/contactperson.py +43 -0
- egain_api_python/models/contacts.py +21 -0
- egain_api_python/models/createbookmark.py +64 -0
- egain_api_python/models/createdby.py +37 -0
- egain_api_python/models/createfederatedsearchevent.py +85 -0
- egain_api_python/models/createfederatedsearchresulteventop.py +46 -0
- egain_api_python/models/createimportop.py +20 -0
- egain_api_python/models/createimportvalidationop.py +20 -0
- egain_api_python/models/createquickpick.py +34 -0
- egain_api_python/models/createquickpickop.py +55 -0
- egain_api_python/models/createsearchresulteventforconnectors.py +71 -0
- egain_api_python/models/createsearchresulteventforconnectorsop.py +48 -0
- egain_api_python/models/createsignedurlop.py +29 -0
- egain_api_python/models/createsuggestion.py +126 -0
- egain_api_python/models/createviewedsearchresulteventforconnectors.py +76 -0
- egain_api_python/models/createviewedsearchresultseventforconnectorsop.py +48 -0
- egain_api_python/models/customattribute.py +35 -0
- egain_api_python/models/deletebookmarkop.py +40 -0
- egain_api_python/models/deletesuggestionop.py +40 -0
- egain_api_python/models/department.py +21 -0
- egain_api_python/models/detailfield.py +32 -0
- egain_api_python/models/displayfield.py +27 -0
- egain_api_python/models/dynamiccluster.py +21 -0
- egain_api_python/models/dynamicsearch.py +40 -0
- egain_api_python/models/edition.py +79 -0
- egain_api_python/models/editionwithcontent.py +68 -0
- egain_api_python/models/email.py +21 -0
- egain_api_python/models/exportcontentop.py +14 -0
- egain_api_python/models/exportstatus.py +106 -0
- egain_api_python/models/exportstatusop.py +31 -0
- egain_api_python/models/feedbackarticleforsuggestion.py +34 -0
- egain_api_python/models/folderbreadcrumb.py +24 -0
- egain_api_python/models/foldersummary.py +29 -0
- egain_api_python/models/getacknowledgedcompliancearticlesop.py +119 -0
- egain_api_python/models/getallarticlelistsop.py +47 -0
- egain_api_python/models/getallcasebasesreleasesop.py +65 -0
- egain_api_python/models/getallcasesop.py +83 -0
- egain_api_python/models/getallportalsop.py +60 -0
- egain_api_python/models/getallprofilesinportalop.py +64 -0
- egain_api_python/models/getallquickpicksop.py +83 -0
- egain_api_python/models/getalltopicsop.py +132 -0
- egain_api_python/models/getalluserprofilesop.py +47 -0
- egain_api_python/models/getancestortopicsop.py +133 -0
- egain_api_python/models/getannouncementarticlesop.py +134 -0
- egain_api_python/models/getarticleattachmentbyidop.py +31 -0
- egain_api_python/models/getarticlebyidop.py +257 -0
- egain_api_python/models/getarticlebyidwitheditionsop.py +46 -0
- egain_api_python/models/getarticleeditiondetailsop.py +55 -0
- egain_api_python/models/getarticlelistdetailsop.py +115 -0
- egain_api_python/models/getarticlepermissionsbyidop.py +40 -0
- egain_api_python/models/getarticlepersonalizationop.py +73 -0
- egain_api_python/models/getarticleratingsop.py +74 -0
- egain_api_python/models/getarticlesintopicop.py +172 -0
- egain_api_python/models/getattachmentbyidinportalop.py +56 -0
- egain_api_python/models/getbookmarkop.py +31 -0
- egain_api_python/models/getcasebasereleasebyidop.py +64 -0
- egain_api_python/models/getcasebyidop.py +75 -0
- egain_api_python/models/getchildtopicsop.py +150 -0
- egain_api_python/models/getclusterbycasebasereleaseidop.py +74 -0
- egain_api_python/models/gethealthop.py +130 -0
- egain_api_python/models/getimportcontentop.py +46 -0
- egain_api_python/models/getmyportalsop.py +97 -0
- egain_api_python/models/getmysubscriptionop.py +115 -0
- egain_api_python/models/getpendingcompliancearticlesop.py +119 -0
- egain_api_python/models/getpopulararticlesop.py +133 -0
- egain_api_python/models/getportaldetailsbyidop.py +47 -0
- egain_api_python/models/getrelatedarticlesforsuggestionop.py +96 -0
- egain_api_python/models/getrelatedarticlesop.py +143 -0
- egain_api_python/models/getsuggestionattachmentbyidop.py +76 -0
- egain_api_python/models/getsuggestionattachmentsop.py +40 -0
- egain_api_python/models/getsuggestioncommentsop.py +40 -0
- egain_api_python/models/getsuggestionop.py +107 -0
- egain_api_python/models/gettagcategoriesforinterestforportalop.py +46 -0
- egain_api_python/models/gettopicbreadcrumbforarticleop.py +55 -0
- egain_api_python/models/getuserdetailsop.py +22 -0
- egain_api_python/models/getusermilestonesop.py +22 -0
- egain_api_python/models/ghsearchrequest.py +67 -0
- egain_api_python/models/ghsearchresult.py +75 -0
- egain_api_python/models/ghstepsearchrequest.py +64 -0
- egain_api_python/models/image.py +17 -0
- egain_api_python/models/importcontent.py +79 -0
- egain_api_python/models/importstatus.py +29 -0
- egain_api_python/models/kblanguage.py +63 -0
- egain_api_python/models/kblanguagecode.py +48 -0
- egain_api_python/models/kblanguages.py +22 -0
- egain_api_python/models/knowledgeexport.py +237 -0
- egain_api_python/models/l10nstring.py +22 -0
- egain_api_python/models/languagecode.py +39 -0
- egain_api_python/models/languagecode_parameter.py +39 -0
- egain_api_python/models/languagequeryparameter.py +39 -0
- egain_api_python/models/link.py +25 -0
- egain_api_python/models/makesuggestionop.py +44 -0
- egain_api_python/models/mandatorylanguagequeryparameter.py +38 -0
- egain_api_python/models/metadata.py +29 -0
- egain_api_python/models/milestone.py +21 -0
- egain_api_python/models/milestonename.py +26 -0
- egain_api_python/models/milestones.py +21 -0
- egain_api_python/models/modifiedby.py +37 -0
- egain_api_python/models/modifysuggestion.py +78 -0
- egain_api_python/models/modifysuggestionsop.py +44 -0
- egain_api_python/models/optionalarticleattributes.py +20 -0
- egain_api_python/models/order.py +10 -0
- egain_api_python/models/ownedby.py +37 -0
- egain_api_python/models/paginationinfo.py +32 -0
- egain_api_python/models/patchimportcontentvalidationop.py +46 -0
- egain_api_python/models/personalization.py +67 -0
- egain_api_python/models/phone.py +21 -0
- egain_api_python/models/portal.py +102 -0
- egain_api_python/models/portalresult.py +28 -0
- egain_api_python/models/portalsettings.py +398 -0
- egain_api_python/models/post_portalid_answersop.py +88 -0
- egain_api_python/models/post_portalid_retrieveop.py +88 -0
- egain_api_python/models/profile.py +26 -0
- egain_api_python/models/profileresult.py +24 -0
- egain_api_python/models/publishprofile.py +30 -0
- egain_api_python/models/publishview.py +38 -0
- egain_api_python/models/question.py +101 -0
- egain_api_python/models/questionandanswer.py +26 -0
- egain_api_python/models/quickpickrating.py +32 -0
- egain_api_python/models/quickpickresult.py +38 -0
- egain_api_python/models/quickpickresults.py +28 -0
- egain_api_python/models/ratearticleop.py +71 -0
- egain_api_python/models/referenceresponse.py +80 -0
- egain_api_python/models/rejectghsolutionop.py +52 -0
- egain_api_python/models/relatedquestions.py +28 -0
- egain_api_python/models/resourcetype_parameter.py +10 -0
- egain_api_python/models/restorequickpickop.py +63 -0
- egain_api_python/models/retrieverequest.py +47 -0
- egain_api_python/models/retrieveresponse.py +96 -0
- egain_api_python/models/role.py +26 -0
- egain_api_python/models/roletemplate.py +25 -0
- egain_api_python/models/schemas_answer.py +94 -0
- egain_api_python/models/schemas_customattribute.py +35 -0
- egain_api_python/models/schemas_link.py +27 -0
- egain_api_python/models/schemas_tag.py +21 -0
- egain_api_python/models/schemas_tagcategory.py +75 -0
- egain_api_python/models/schemas_taggroup.py +31 -0
- egain_api_python/models/schemas_tags.py +19 -0
- egain_api_python/models/schemas_wserrorcommon.py +17 -0
- egain_api_python/models/searchfilterattribute.py +61 -0
- egain_api_python/models/searchpriortoescalationop.py +108 -0
- egain_api_python/models/searchresult.py +101 -0
- egain_api_python/models/searchsuggestionop.py +93 -0
- egain_api_python/models/security.py +25 -0
- egain_api_python/models/selectuserprofileop.py +44 -0
- egain_api_python/models/sessioncontextvariable.py +17 -0
- egain_api_python/models/shorturl.py +32 -0
- egain_api_python/models/sortidname.py +10 -0
- egain_api_python/models/sortidnamedepartment.py +11 -0
- egain_api_python/models/stage.py +26 -0
- egain_api_python/models/startcustomerescalationop.py +66 -0
- egain_api_python/models/startescalationrequest.py +94 -0
- egain_api_python/models/startghsearchop.py +74 -0
- egain_api_python/models/startquestionandanswer.py +26 -0
- egain_api_python/models/stepghsearchop.py +62 -0
- egain_api_python/models/stringattributevalue.py +30 -0
- egain_api_python/models/structuredauthoringfields.py +33 -0
- egain_api_python/models/subscribearticleop.py +40 -0
- egain_api_python/models/suggestion.py +190 -0
- egain_api_python/models/suggestionadditionalattributes.py +11 -0
- egain_api_python/models/suggestionattachment.py +46 -0
- egain_api_python/models/suggestions.py +28 -0
- egain_api_python/models/tag.py +17 -0
- egain_api_python/models/tagcategoriesforinterest.py +22 -0
- egain_api_python/models/tagcategory.py +34 -0
- egain_api_python/models/taggroup.py +17 -0
- egain_api_python/models/taggroups.py +20 -0
- egain_api_python/models/tags.py +17 -0
- egain_api_python/models/topic.py +113 -0
- egain_api_python/models/topicadditionalattributes.py +20 -0
- egain_api_python/models/topicaisearchresult.py +67 -0
- egain_api_python/models/topicbreadcrumb.py +24 -0
- egain_api_python/models/topicresult.py +26 -0
- egain_api_python/models/topicsummary.py +31 -0
- egain_api_python/models/topictreenode.py +27 -0
- egain_api_python/models/topictreeresult.py +28 -0
- egain_api_python/models/unsubscribearticleop.py +55 -0
- egain_api_python/models/uploadattachmentop.py +36 -0
- egain_api_python/models/userdetails.py +44 -0
- egain_api_python/models/userprofile.py +33 -0
- egain_api_python/models/userprofiles.py +21 -0
- egain_api_python/models/userview.py +33 -0
- egain_api_python/models/validateimportcontent.py +58 -0
- egain_api_python/models/virtualcase.py +52 -0
- egain_api_python/models/workflow.py +21 -0
- egain_api_python/models/workflowmilestone.py +11 -0
- egain_api_python/models/wserrorcommon.py +17 -0
- egain_api_python/populararticles.py +287 -0
- egain_api_python/portal_article.py +4935 -0
- egain_api_python/portal_attachment.py +494 -0
- egain_api_python/portal_bookmark.py +707 -0
- egain_api_python/portal_sdk.py +88 -0
- egain_api_python/portal_suggestion.py +2283 -0
- egain_api_python/portal_topic.py +975 -0
- egain_api_python/portal_userdetails.py +211 -0
- egain_api_python/portal_userprofile.py +431 -0
- egain_api_python/py.typed +1 -0
- egain_api_python/retrieve.py +265 -0
- egain_api_python/sdk.py +216 -0
- egain_api_python/sdkconfiguration.py +50 -0
- egain_api_python/search.py +251 -0
- egain_api_python/types/__init__.py +21 -0
- egain_api_python/types/basemodel.py +39 -0
- egain_api_python/usermilestones.py +219 -0
- egain_api_python/utils/__init__.py +200 -0
- egain_api_python/utils/annotations.py +79 -0
- egain_api_python/utils/datetimes.py +23 -0
- egain_api_python/utils/enums.py +74 -0
- egain_api_python/utils/eventstreaming.py +248 -0
- egain_api_python/utils/forms.py +223 -0
- egain_api_python/utils/headers.py +136 -0
- egain_api_python/utils/logger.py +27 -0
- egain_api_python/utils/metadata.py +118 -0
- egain_api_python/utils/queryparams.py +205 -0
- egain_api_python/utils/requestbodies.py +66 -0
- egain_api_python/utils/retries.py +217 -0
- egain_api_python/utils/security.py +192 -0
- egain_api_python/utils/serializers.py +249 -0
- egain_api_python/utils/unmarshal_json_response.py +24 -0
- egain_api_python/utils/url.py +155 -0
- egain_api_python/utils/values.py +137 -0
- egain_api_python-0.1.1.dist-info/METADATA +827 -0
- egain_api_python-0.1.1.dist-info/RECORD +332 -0
- egain_api_python-0.1.1.dist-info/WHEEL +5 -0
- egain_api_python-0.1.1.dist-info/licenses/LICENSE +21 -0
- egain_api_python-0.1.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
2
|
+
|
3
|
+
import io
|
4
|
+
from dataclasses import dataclass
|
5
|
+
import re
|
6
|
+
from typing import (
|
7
|
+
Any,
|
8
|
+
Optional,
|
9
|
+
)
|
10
|
+
|
11
|
+
from .forms import serialize_form_data, serialize_multipart_form
|
12
|
+
|
13
|
+
from .serializers import marshal_json
|
14
|
+
|
15
|
+
SERIALIZATION_METHOD_TO_CONTENT_TYPE = {
|
16
|
+
"json": "application/json",
|
17
|
+
"form": "application/x-www-form-urlencoded",
|
18
|
+
"multipart": "multipart/form-data",
|
19
|
+
"raw": "application/octet-stream",
|
20
|
+
"string": "text/plain",
|
21
|
+
}
|
22
|
+
|
23
|
+
|
24
|
+
@dataclass
|
25
|
+
class SerializedRequestBody:
|
26
|
+
media_type: Optional[str] = None
|
27
|
+
content: Optional[Any] = None
|
28
|
+
data: Optional[Any] = None
|
29
|
+
files: Optional[Any] = None
|
30
|
+
|
31
|
+
|
32
|
+
def serialize_request_body(
|
33
|
+
request_body: Any,
|
34
|
+
nullable: bool,
|
35
|
+
optional: bool,
|
36
|
+
serialization_method: str,
|
37
|
+
request_body_type,
|
38
|
+
) -> Optional[SerializedRequestBody]:
|
39
|
+
if request_body is None:
|
40
|
+
if not nullable and optional:
|
41
|
+
return None
|
42
|
+
|
43
|
+
media_type = SERIALIZATION_METHOD_TO_CONTENT_TYPE[serialization_method]
|
44
|
+
|
45
|
+
serialized_request_body = SerializedRequestBody(media_type)
|
46
|
+
|
47
|
+
if re.match(r"(application|text)\/.*?\+*json.*", media_type) is not None:
|
48
|
+
serialized_request_body.content = marshal_json(request_body, request_body_type)
|
49
|
+
elif re.match(r"multipart\/.*", media_type) is not None:
|
50
|
+
(
|
51
|
+
serialized_request_body.media_type,
|
52
|
+
serialized_request_body.data,
|
53
|
+
serialized_request_body.files,
|
54
|
+
) = serialize_multipart_form(media_type, request_body)
|
55
|
+
elif re.match(r"application\/x-www-form-urlencoded.*", media_type) is not None:
|
56
|
+
serialized_request_body.data = serialize_form_data(request_body)
|
57
|
+
elif isinstance(request_body, (bytes, bytearray, io.BytesIO, io.BufferedReader)):
|
58
|
+
serialized_request_body.content = request_body
|
59
|
+
elif isinstance(request_body, str):
|
60
|
+
serialized_request_body.content = request_body
|
61
|
+
else:
|
62
|
+
raise TypeError(
|
63
|
+
f"invalid request body type {type(request_body)} for mediaType {media_type}"
|
64
|
+
)
|
65
|
+
|
66
|
+
return serialized_request_body
|
@@ -0,0 +1,217 @@
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
2
|
+
|
3
|
+
import asyncio
|
4
|
+
import random
|
5
|
+
import time
|
6
|
+
from typing import List
|
7
|
+
|
8
|
+
import httpx
|
9
|
+
|
10
|
+
|
11
|
+
class BackoffStrategy:
|
12
|
+
initial_interval: int
|
13
|
+
max_interval: int
|
14
|
+
exponent: float
|
15
|
+
max_elapsed_time: int
|
16
|
+
|
17
|
+
def __init__(
|
18
|
+
self,
|
19
|
+
initial_interval: int,
|
20
|
+
max_interval: int,
|
21
|
+
exponent: float,
|
22
|
+
max_elapsed_time: int,
|
23
|
+
):
|
24
|
+
self.initial_interval = initial_interval
|
25
|
+
self.max_interval = max_interval
|
26
|
+
self.exponent = exponent
|
27
|
+
self.max_elapsed_time = max_elapsed_time
|
28
|
+
|
29
|
+
|
30
|
+
class RetryConfig:
|
31
|
+
strategy: str
|
32
|
+
backoff: BackoffStrategy
|
33
|
+
retry_connection_errors: bool
|
34
|
+
|
35
|
+
def __init__(
|
36
|
+
self, strategy: str, backoff: BackoffStrategy, retry_connection_errors: bool
|
37
|
+
):
|
38
|
+
self.strategy = strategy
|
39
|
+
self.backoff = backoff
|
40
|
+
self.retry_connection_errors = retry_connection_errors
|
41
|
+
|
42
|
+
|
43
|
+
class Retries:
|
44
|
+
config: RetryConfig
|
45
|
+
status_codes: List[str]
|
46
|
+
|
47
|
+
def __init__(self, config: RetryConfig, status_codes: List[str]):
|
48
|
+
self.config = config
|
49
|
+
self.status_codes = status_codes
|
50
|
+
|
51
|
+
|
52
|
+
class TemporaryError(Exception):
|
53
|
+
response: httpx.Response
|
54
|
+
|
55
|
+
def __init__(self, response: httpx.Response):
|
56
|
+
self.response = response
|
57
|
+
|
58
|
+
|
59
|
+
class PermanentError(Exception):
|
60
|
+
inner: Exception
|
61
|
+
|
62
|
+
def __init__(self, inner: Exception):
|
63
|
+
self.inner = inner
|
64
|
+
|
65
|
+
|
66
|
+
def retry(func, retries: Retries):
|
67
|
+
if retries.config.strategy == "backoff":
|
68
|
+
|
69
|
+
def do_request() -> httpx.Response:
|
70
|
+
res: httpx.Response
|
71
|
+
try:
|
72
|
+
res = func()
|
73
|
+
|
74
|
+
for code in retries.status_codes:
|
75
|
+
if "X" in code.upper():
|
76
|
+
code_range = int(code[0])
|
77
|
+
|
78
|
+
status_major = res.status_code / 100
|
79
|
+
|
80
|
+
if code_range <= status_major < code_range + 1:
|
81
|
+
raise TemporaryError(res)
|
82
|
+
else:
|
83
|
+
parsed_code = int(code)
|
84
|
+
|
85
|
+
if res.status_code == parsed_code:
|
86
|
+
raise TemporaryError(res)
|
87
|
+
except httpx.ConnectError as exception:
|
88
|
+
if retries.config.retry_connection_errors:
|
89
|
+
raise
|
90
|
+
|
91
|
+
raise PermanentError(exception) from exception
|
92
|
+
except httpx.TimeoutException as exception:
|
93
|
+
if retries.config.retry_connection_errors:
|
94
|
+
raise
|
95
|
+
|
96
|
+
raise PermanentError(exception) from exception
|
97
|
+
except TemporaryError:
|
98
|
+
raise
|
99
|
+
except Exception as exception:
|
100
|
+
raise PermanentError(exception) from exception
|
101
|
+
|
102
|
+
return res
|
103
|
+
|
104
|
+
return retry_with_backoff(
|
105
|
+
do_request,
|
106
|
+
retries.config.backoff.initial_interval,
|
107
|
+
retries.config.backoff.max_interval,
|
108
|
+
retries.config.backoff.exponent,
|
109
|
+
retries.config.backoff.max_elapsed_time,
|
110
|
+
)
|
111
|
+
|
112
|
+
return func()
|
113
|
+
|
114
|
+
|
115
|
+
async def retry_async(func, retries: Retries):
|
116
|
+
if retries.config.strategy == "backoff":
|
117
|
+
|
118
|
+
async def do_request() -> httpx.Response:
|
119
|
+
res: httpx.Response
|
120
|
+
try:
|
121
|
+
res = await func()
|
122
|
+
|
123
|
+
for code in retries.status_codes:
|
124
|
+
if "X" in code.upper():
|
125
|
+
code_range = int(code[0])
|
126
|
+
|
127
|
+
status_major = res.status_code / 100
|
128
|
+
|
129
|
+
if code_range <= status_major < code_range + 1:
|
130
|
+
raise TemporaryError(res)
|
131
|
+
else:
|
132
|
+
parsed_code = int(code)
|
133
|
+
|
134
|
+
if res.status_code == parsed_code:
|
135
|
+
raise TemporaryError(res)
|
136
|
+
except httpx.ConnectError as exception:
|
137
|
+
if retries.config.retry_connection_errors:
|
138
|
+
raise
|
139
|
+
|
140
|
+
raise PermanentError(exception) from exception
|
141
|
+
except httpx.TimeoutException as exception:
|
142
|
+
if retries.config.retry_connection_errors:
|
143
|
+
raise
|
144
|
+
|
145
|
+
raise PermanentError(exception) from exception
|
146
|
+
except TemporaryError:
|
147
|
+
raise
|
148
|
+
except Exception as exception:
|
149
|
+
raise PermanentError(exception) from exception
|
150
|
+
|
151
|
+
return res
|
152
|
+
|
153
|
+
return await retry_with_backoff_async(
|
154
|
+
do_request,
|
155
|
+
retries.config.backoff.initial_interval,
|
156
|
+
retries.config.backoff.max_interval,
|
157
|
+
retries.config.backoff.exponent,
|
158
|
+
retries.config.backoff.max_elapsed_time,
|
159
|
+
)
|
160
|
+
|
161
|
+
return await func()
|
162
|
+
|
163
|
+
|
164
|
+
def retry_with_backoff(
|
165
|
+
func,
|
166
|
+
initial_interval=500,
|
167
|
+
max_interval=60000,
|
168
|
+
exponent=1.5,
|
169
|
+
max_elapsed_time=3600000,
|
170
|
+
):
|
171
|
+
start = round(time.time() * 1000)
|
172
|
+
retries = 0
|
173
|
+
|
174
|
+
while True:
|
175
|
+
try:
|
176
|
+
return func()
|
177
|
+
except PermanentError as exception:
|
178
|
+
raise exception.inner
|
179
|
+
except Exception as exception: # pylint: disable=broad-exception-caught
|
180
|
+
now = round(time.time() * 1000)
|
181
|
+
if now - start > max_elapsed_time:
|
182
|
+
if isinstance(exception, TemporaryError):
|
183
|
+
return exception.response
|
184
|
+
|
185
|
+
raise
|
186
|
+
sleep = (initial_interval / 1000) * exponent**retries + random.uniform(0, 1)
|
187
|
+
sleep = min(sleep, max_interval / 1000)
|
188
|
+
time.sleep(sleep)
|
189
|
+
retries += 1
|
190
|
+
|
191
|
+
|
192
|
+
async def retry_with_backoff_async(
|
193
|
+
func,
|
194
|
+
initial_interval=500,
|
195
|
+
max_interval=60000,
|
196
|
+
exponent=1.5,
|
197
|
+
max_elapsed_time=3600000,
|
198
|
+
):
|
199
|
+
start = round(time.time() * 1000)
|
200
|
+
retries = 0
|
201
|
+
|
202
|
+
while True:
|
203
|
+
try:
|
204
|
+
return await func()
|
205
|
+
except PermanentError as exception:
|
206
|
+
raise exception.inner
|
207
|
+
except Exception as exception: # pylint: disable=broad-exception-caught
|
208
|
+
now = round(time.time() * 1000)
|
209
|
+
if now - start > max_elapsed_time:
|
210
|
+
if isinstance(exception, TemporaryError):
|
211
|
+
return exception.response
|
212
|
+
|
213
|
+
raise
|
214
|
+
sleep = (initial_interval / 1000) * exponent**retries + random.uniform(0, 1)
|
215
|
+
sleep = min(sleep, max_interval / 1000)
|
216
|
+
await asyncio.sleep(sleep)
|
217
|
+
retries += 1
|
@@ -0,0 +1,192 @@
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
2
|
+
|
3
|
+
import base64
|
4
|
+
|
5
|
+
from typing import (
|
6
|
+
Any,
|
7
|
+
Dict,
|
8
|
+
List,
|
9
|
+
Optional,
|
10
|
+
Tuple,
|
11
|
+
)
|
12
|
+
from pydantic import BaseModel
|
13
|
+
from pydantic.fields import FieldInfo
|
14
|
+
|
15
|
+
from .metadata import (
|
16
|
+
SecurityMetadata,
|
17
|
+
find_field_metadata,
|
18
|
+
)
|
19
|
+
import os
|
20
|
+
|
21
|
+
|
22
|
+
def get_security(security: Any) -> Tuple[Dict[str, str], Dict[str, List[str]]]:
|
23
|
+
headers: Dict[str, str] = {}
|
24
|
+
query_params: Dict[str, List[str]] = {}
|
25
|
+
|
26
|
+
if security is None:
|
27
|
+
return headers, query_params
|
28
|
+
|
29
|
+
if not isinstance(security, BaseModel):
|
30
|
+
raise TypeError("security must be a pydantic model")
|
31
|
+
|
32
|
+
sec_fields: Dict[str, FieldInfo] = security.__class__.model_fields
|
33
|
+
for name in sec_fields:
|
34
|
+
sec_field = sec_fields[name]
|
35
|
+
|
36
|
+
value = getattr(security, name)
|
37
|
+
if value is None:
|
38
|
+
continue
|
39
|
+
|
40
|
+
metadata = find_field_metadata(sec_field, SecurityMetadata)
|
41
|
+
if metadata is None:
|
42
|
+
continue
|
43
|
+
if metadata.option:
|
44
|
+
_parse_security_option(headers, query_params, value)
|
45
|
+
return headers, query_params
|
46
|
+
if metadata.scheme:
|
47
|
+
# Special case for basic auth or custom auth which could be a flattened model
|
48
|
+
if metadata.sub_type in ["basic", "custom"] and not isinstance(
|
49
|
+
value, BaseModel
|
50
|
+
):
|
51
|
+
_parse_security_scheme(headers, query_params, metadata, name, security)
|
52
|
+
else:
|
53
|
+
_parse_security_scheme(headers, query_params, metadata, name, value)
|
54
|
+
|
55
|
+
return headers, query_params
|
56
|
+
|
57
|
+
|
58
|
+
def get_security_from_env(security: Any, security_class: Any) -> Optional[BaseModel]:
|
59
|
+
if security is not None:
|
60
|
+
return security
|
61
|
+
|
62
|
+
if not issubclass(security_class, BaseModel):
|
63
|
+
raise TypeError("security_class must be a pydantic model class")
|
64
|
+
|
65
|
+
security_dict: Any = {}
|
66
|
+
|
67
|
+
if os.getenv("EGAIN_ACCESS_TOKEN"):
|
68
|
+
security_dict["access_token"] = os.getenv("EGAIN_ACCESS_TOKEN")
|
69
|
+
|
70
|
+
return security_class(**security_dict) if security_dict else None
|
71
|
+
|
72
|
+
|
73
|
+
def _parse_security_option(
|
74
|
+
headers: Dict[str, str], query_params: Dict[str, List[str]], option: Any
|
75
|
+
):
|
76
|
+
if not isinstance(option, BaseModel):
|
77
|
+
raise TypeError("security option must be a pydantic model")
|
78
|
+
|
79
|
+
opt_fields: Dict[str, FieldInfo] = option.__class__.model_fields
|
80
|
+
for name in opt_fields:
|
81
|
+
opt_field = opt_fields[name]
|
82
|
+
|
83
|
+
metadata = find_field_metadata(opt_field, SecurityMetadata)
|
84
|
+
if metadata is None or not metadata.scheme:
|
85
|
+
continue
|
86
|
+
_parse_security_scheme(
|
87
|
+
headers, query_params, metadata, name, getattr(option, name)
|
88
|
+
)
|
89
|
+
|
90
|
+
|
91
|
+
def _parse_security_scheme(
|
92
|
+
headers: Dict[str, str],
|
93
|
+
query_params: Dict[str, List[str]],
|
94
|
+
scheme_metadata: SecurityMetadata,
|
95
|
+
field_name: str,
|
96
|
+
scheme: Any,
|
97
|
+
):
|
98
|
+
scheme_type = scheme_metadata.scheme_type
|
99
|
+
sub_type = scheme_metadata.sub_type
|
100
|
+
|
101
|
+
if isinstance(scheme, BaseModel):
|
102
|
+
if scheme_type == "http":
|
103
|
+
if sub_type == "basic":
|
104
|
+
_parse_basic_auth_scheme(headers, scheme)
|
105
|
+
return
|
106
|
+
if sub_type == "custom":
|
107
|
+
return
|
108
|
+
|
109
|
+
scheme_fields: Dict[str, FieldInfo] = scheme.__class__.model_fields
|
110
|
+
for name in scheme_fields:
|
111
|
+
scheme_field = scheme_fields[name]
|
112
|
+
|
113
|
+
metadata = find_field_metadata(scheme_field, SecurityMetadata)
|
114
|
+
if metadata is None or metadata.field_name is None:
|
115
|
+
continue
|
116
|
+
|
117
|
+
value = getattr(scheme, name)
|
118
|
+
|
119
|
+
_parse_security_scheme_value(
|
120
|
+
headers, query_params, scheme_metadata, metadata, name, value
|
121
|
+
)
|
122
|
+
else:
|
123
|
+
_parse_security_scheme_value(
|
124
|
+
headers, query_params, scheme_metadata, scheme_metadata, field_name, scheme
|
125
|
+
)
|
126
|
+
|
127
|
+
|
128
|
+
def _parse_security_scheme_value(
|
129
|
+
headers: Dict[str, str],
|
130
|
+
query_params: Dict[str, List[str]],
|
131
|
+
scheme_metadata: SecurityMetadata,
|
132
|
+
security_metadata: SecurityMetadata,
|
133
|
+
field_name: str,
|
134
|
+
value: Any,
|
135
|
+
):
|
136
|
+
scheme_type = scheme_metadata.scheme_type
|
137
|
+
sub_type = scheme_metadata.sub_type
|
138
|
+
|
139
|
+
header_name = security_metadata.get_field_name(field_name)
|
140
|
+
|
141
|
+
if scheme_type == "apiKey":
|
142
|
+
if sub_type == "header":
|
143
|
+
headers[header_name] = value
|
144
|
+
elif sub_type == "query":
|
145
|
+
query_params[header_name] = [value]
|
146
|
+
else:
|
147
|
+
raise ValueError("sub type {sub_type} not supported")
|
148
|
+
elif scheme_type == "openIdConnect":
|
149
|
+
headers[header_name] = _apply_bearer(value)
|
150
|
+
elif scheme_type == "oauth2":
|
151
|
+
if sub_type != "client_credentials":
|
152
|
+
headers[header_name] = _apply_bearer(value)
|
153
|
+
elif scheme_type == "http":
|
154
|
+
if sub_type == "bearer":
|
155
|
+
headers[header_name] = _apply_bearer(value)
|
156
|
+
elif sub_type == "custom":
|
157
|
+
return
|
158
|
+
else:
|
159
|
+
raise ValueError("sub type {sub_type} not supported")
|
160
|
+
else:
|
161
|
+
raise ValueError("scheme type {scheme_type} not supported")
|
162
|
+
|
163
|
+
|
164
|
+
def _apply_bearer(token: str) -> str:
|
165
|
+
return token.lower().startswith("bearer ") and token or f"Bearer {token}"
|
166
|
+
|
167
|
+
|
168
|
+
def _parse_basic_auth_scheme(headers: Dict[str, str], scheme: Any):
|
169
|
+
username = ""
|
170
|
+
password = ""
|
171
|
+
|
172
|
+
if not isinstance(scheme, BaseModel):
|
173
|
+
raise TypeError("basic auth scheme must be a pydantic model")
|
174
|
+
|
175
|
+
scheme_fields: Dict[str, FieldInfo] = scheme.__class__.model_fields
|
176
|
+
for name in scheme_fields:
|
177
|
+
scheme_field = scheme_fields[name]
|
178
|
+
|
179
|
+
metadata = find_field_metadata(scheme_field, SecurityMetadata)
|
180
|
+
if metadata is None or metadata.field_name is None:
|
181
|
+
continue
|
182
|
+
|
183
|
+
field_name = metadata.field_name
|
184
|
+
value = getattr(scheme, name)
|
185
|
+
|
186
|
+
if field_name == "username":
|
187
|
+
username = value
|
188
|
+
if field_name == "password":
|
189
|
+
password = value
|
190
|
+
|
191
|
+
data = f"{username}:{password}".encode()
|
192
|
+
headers["Authorization"] = f"Basic {base64.b64encode(data).decode()}"
|