Skip to content

Commit 41afc27

Browse files
authored
Updates for IPA 6.x (#230)
* [CAT-501] ADD: functionality for adding exchange integration to a workflow (#202) * WIP * ADD: support for adding exchange integration * fix type conversion * Clean up types and add docstrings * [CAT-502] ADD: support for starting an integration (#203) * ADD: mutation + test for starting an integration * fix: use existing _AddComponent call to add output component * FIX: add output nodes to workflow created during integration tests (#214) * [CAT-515] FIX: force decompress when deserializing if url ends in gz (#213) * FIX: force decompress when deserializing if url ends in gz * update syntax for checking url suffixes in http client * undo dev url change * [CAT-525] ADD: post processing submission status (#215) * ADD: post processing submission status * FIX: update WaitForSubmission to wait until after post processing * Revert "[CAT-525] ADD: post processing submission status (#215)" (#220) This reverts commit 3d946e4. * fix typing for questionnaire calls and update tests (#226) * remove TODO * remove pytest mark skip
1 parent 730ab43 commit 41afc27

21 files changed

+280
-49
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ indico_api_token.txt
5454
examples/readme.py
5555
docsrc/_build
5656
docs/.doctrees
57+
setup_tests.sh
5758

5859
.venv
5960
.vscode/

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM python:3.9.15
22

3-
ENV INDICO_HOST="dev.indico.io"
3+
ENV INDICO_HOST="dev-ci.us-east-2.indico-dev.indico.io"
44

55
COPY . /indico-client
66
WORKDIR /indico-client

codeship-services.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ indico-client-test:
33
dockerfile: tox.Dockerfile
44
container_name: indico-client-test
55
environment:
6-
- INDICO_HOST=dev.indico.io
6+
- INDICO_HOST=dev-ci.us-east-2.indico-dev.indico.io
77
- TOX_PARALLEL_NO_SPINNER=true
88
encrypted_env_file:
99
- env.encrypted

indico/config/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class IndicoConfig:
4646
_disable_cookie_domain: bool = False
4747

4848
def __init__(self, **kwargs):
49+
4950
self.host: str = os.getenv("INDICO_HOST", "app.indico.io")
5051
self.protocol: str = os.getenv("INDICO_PROTOCOL", "https")
5152
self.serializer: str = os.getenv("INDICO_SERIALIZER", "msgpack")

indico/http/client.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import http.cookiejar
22
import logging
3-
from collections import defaultdict
43
from contextlib import contextmanager
54
from copy import deepcopy
65
from pathlib import Path
@@ -149,11 +148,8 @@ def _make_request(
149148
**new_kwargs,
150149
)
151150

152-
# code, api_response =
153-
url_parts = path.split(".")
154-
json = False
155-
if len(url_parts) > 1 and (url_parts[-1] == "json" or url_parts[-2] == "json"):
156-
json = True
151+
json: bool = ".json" in Path(path).suffixes
152+
decompress: bool = Path(path).suffix == ".gz"
157153

158154
# If auth expired refresh
159155
if response.status_code == 401 and not _refreshed:
@@ -172,7 +168,7 @@ def _make_request(
172168
code=response.status_code
173169
)
174170

175-
content = deserialize(response, force_json=json)
171+
content = deserialize(response, force_json=json, force_decompress=decompress)
176172

177173
if response.status_code >= 400:
178174
if isinstance(content, dict):

indico/http/serialization.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,10 @@ def decompress(response):
2121
return gzip.decompress(value)
2222

2323

24-
def raw_bytes(content, *args, **kwargs):
25-
return content
26-
27-
28-
def deserialize(response, force_json=False):
24+
def deserialize(response, force_json=False, force_decompress=False):
2925
content_type, params = cgi.parse_header(response.headers.get("Content-Type"))
3026

31-
if content_type in ["application/x-gzip", "application/gzip"]:
27+
if force_decompress or content_type in ["application/x-gzip", "application/gzip"]:
3228
content = decompress(response)
3329
else:
3430
content = response.content
@@ -48,6 +44,10 @@ def deserialize(response, force_json=False):
4844
)
4945

5046

47+
48+
def raw_bytes(content, *args, **kwargs):
49+
return content
50+
5151
def msgpack_deserialization(content, charset):
5252
return msgpack.unpackb(content)
5353

indico/queries/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
from .workflow_components import *
1111
from .example import *
1212
from .questionnaire import *
13+
from .integration import *

indico/queries/integration.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import jsons
2+
from typing import List
3+
4+
from indico import GraphQLRequest, RequestChain
5+
from indico.errors import IndicoInputError
6+
from indico.types.integration import ExchangeIntegration, ExchangeIntegrationConfiguration, ExchangeIntegrationCredentials
7+
8+
class AddExchangeIntegration(GraphQLRequest):
9+
"""
10+
Mutation to add a Microsoft Exchange integration to a workflow
11+
12+
Args:
13+
workflow_id(int): workflow to add integration to
14+
config(ExchangeIntegrationConfiguration): settings for which mailbox to point to and which emails to process
15+
credentials(ExchangeIntegrationCredentials): client id, client secret, and tenant id for authenticating with Exchange
16+
17+
"""
18+
19+
query = """
20+
mutation addExchangeIntegration($workflow_id: Int!, $config: ExchangeIntegrationConfigurationInput!, $credentials: ExchangeIntegrationCredentialsInput!){
21+
addExchangeIntegrationToWorkflow(workflowId: $workflow_id, config: $config, credentials: $credentials){
22+
integration{
23+
id
24+
enabled
25+
workflowId
26+
createdAt
27+
config {
28+
filters
29+
userId
30+
folderName
31+
folderId
32+
}
33+
}
34+
}
35+
}
36+
"""
37+
38+
def __init__(
39+
self,
40+
config: ExchangeIntegrationConfiguration,
41+
credentials: ExchangeIntegrationCredentials,
42+
workflow_id: int,
43+
):
44+
super().__init__(
45+
self.query,
46+
variables={
47+
"config": config,
48+
"credentials": credentials,
49+
"workflow_id": workflow_id,
50+
},
51+
)
52+
53+
def process_response(self, response) -> ExchangeIntegration:
54+
return ExchangeIntegration(
55+
**super().process_response(response)["addExchangeIntegrationToWorkflow"]["integration"]
56+
)
57+
58+
class StartIntegration(GraphQLRequest):
59+
"""
60+
Mutation to start an existing integration. Once an integration is started, documents will be submitted to the associated workflow.
61+
62+
Args:
63+
integration_id(int): id of the integration to start
64+
65+
"""
66+
67+
query = """
68+
mutation StartIntegration($integration_id: Int!){
69+
startWorkflowIntegration(integrationId: $integration_id){
70+
success
71+
}
72+
}
73+
"""
74+
75+
def __init__(
76+
self,
77+
integration_id: int,
78+
):
79+
super().__init__(
80+
self.query,
81+
variables={
82+
"integration_id": integration_id
83+
},
84+
)

indico/queries/questionnaire.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Debouncer,
1111
)
1212
from indico.queries import AddModelGroupComponent
13-
from indico.types import NewLabelsetArguments, NewQuestionnaireArguments, Workflow
13+
from indico.types import NewLabelsetArguments, NewQuestionnaireArguments, Workflow, ModelTaskType
1414

1515
from indico.types.questionnaire import Questionnaire, Example
1616
from indico.types.dataset import Dataset
@@ -48,6 +48,7 @@ def __init__(
4848
labelset_id: int,
4949
labels: List[dict],
5050
model_group_id: int = None,
51+
dataset_id: int = None
5152
):
5253
super().__init__(
5354
query=self.query,
@@ -297,10 +298,9 @@ def requests(self):
297298
new_labelset_args = NewLabelsetArguments(
298299
datacolumn_id=self.previous.datacolumns[0].id,
299300
name=self.name,
300-
task_type=self.task_type,
301+
task_type=next(v for v in ModelTaskType if v.name == self.task_type),
301302
target_names=self.targets,
302303
)
303-
304304
yield AddModelGroupComponent(
305305
workflow_id=self.workflow_id[0],
306306
source_column_id=self.previous.datacolumns[0].id,

indico/queries/workflow.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class ListWorkflows(GraphQLRequest):
3333
autoReviewEnabled
3434
createdAt
3535
createdBy
36+
submissionRunnable
3637
components {
3738
id
3839
componentType
@@ -500,6 +501,7 @@ class CreateWorkflow(GraphQLRequest):
500501
status
501502
reviewEnabled
502503
autoReviewEnabled
504+
submissionRunnable
503505
components {
504506
id
505507
componentType

0 commit comments

Comments
 (0)