Skip to content

Queries

Source code in api/src/graphql_types/query.py
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
@strawberry.type
class Query:
    @strawberry.field
    def github_endpoint(self, url: str) -> GithubEndpoint:
        """
        # Get Properties of a Single Github Endpoint

        Given a url, retrieves the properties of a single Github Endpoint.

        # Example

        ```graphql
        query {
            githubEndpoint(url: "https://github.com/someOrg/someRepo") {
                url
                kind
                license
                visibility
                automatedSecurityFixes {
                    checkPasses
                    metadata
                }
            }
        }
        ```
        """
        client = GraphDB()
        endpoint = client.get_scanner_endpoint(url)
        client.close()
        # Remove unecessary db fields from the endpoint dict
        endpoint.pop("_id", None)
        endpoint.pop("_rev", None)
        return GithubEndpoint(
                **{
                    k: CheckPasses(**v)
                    for k, v in endpoint.items()
                    if type(v) is dict
                },
                **{
                    k: v
                    for k, v in endpoint.items()
                    if type(v) is not dict
                }
        )
        # return GithubEndpoint(**endpoint)

    @strawberry.field
    def github_endpoints(self, limit: int) -> List[GithubEndpoint]:
        """
        # Get Multiple Github Endpoints

        Retrieves a list of Github Endpoints. The number of endpoints returned is
        determined by the `limit` parameter.

        # Example

        ```graphql
        query	{
            githubEndpoints(limit: 10){
            url
            kind
            Key
            owner
        }
        }
        ```
        """
        client = GraphDB()
        endpoints = client.get_scanner_endpoints("Github", limit)
        client.close()
        # Remove unecessary db fields from the endpoint dict
        for endpoint in endpoints:
            endpoint.pop("_id", None)
            endpoint.pop("_rev", None)
        return [GithubEndpoint(
                        **{
                            k: CheckPasses(**v)
                            for k, v in endpoint.items()
                            if type(v) is dict
                        },
                        **{
                            k: v
                            for k, v in endpoint.items()
                            if type(v) is not dict
                        }
                    )    
                for endpoint in endpoints]
        # return [GithubEndpoint(**endpoint) for endpoint in endpoints]

    @strawberry.field
    def web_endpoint(self, url: str) -> WebEndpoint:
        """
        # Get Properties of a Single Web Endpoint

        Given a url, retrieves the properties of a single Web Endpoint.

        # Example

        ```graphql
        query {
            webEndpoint(url: "https://safeinputs.phac.alpha.canada.ca") {
                url
                accessibility {
                url
                areaAlt {
                    checkPasses
                    metadata
                }
                }
            }
        }
        ```
        """
        client = GraphDB()
        endpoint = client.get_scanner_endpoint(url)
        client.close()
        # Remove unecessary db fields from the endpoint dict
        endpoint.pop("_id", None)
        endpoint.pop("_rev", None)

        if 'accessibility' not in endpoint:
            endpoint['accessibility'] = []

        # Strawberry doesn't recursively resolve fields. The code below
        # is a workaround to recursively resolve the accessibility field
        # and the "check passes" fields contained within.
        return WebEndpoint(
            url=endpoint['url'],
            kind=endpoint['kind'],
            _key=endpoint['_key'],
            accessibility=[
                Accessibility(**{
                    k: AccessibilityCheckPasses(**v)
                    for k, v in ep.items()
                    if type(v) is not str
                },
                url=ep['url'])
                for ep in endpoint['accessibility']
            ]
        )

    @strawberry.field
    def web_endpoints(self, limit: int) -> List[WebEndpoint]:
        """
        # Get Multiple Web Endpoints

        Retrieves a list of Web Endpoints. The number of endpoints returned is
        determined by the `limit` parameter.

        # Example

        ```graphql
        query {
            webEndpoints(limit: 10) {
                url
                accessibility {
                url
                areaAlt {
                    checkPasses
                    metadata
                }
                }
            }
        }
        ```
        """
        client = GraphDB()
        endpoints = client.get_scanner_endpoints("Web", limit)
        client.close()
        # Remove unecessary db fields from the endpoint dict
        for endpoint in endpoints:
            endpoint.pop("_id", None)
            endpoint.pop("_rev", None)
        # Strawberry doesn't recursively resolve fields. The code below
        # is a workaround to recursively resolve the accessibility field
        # and the "check passes" fields contained within.
        return [
            WebEndpoint(
                url=endpoint['url'],
                kind=endpoint['kind'],
                _key=endpoint['_key'],
                accessibility=[
                    Accessibility(**{
                        k: AccessibilityCheckPasses(**v)
                        for k, v in ep.items()
                        if type(v) is not str
                    },
                    url=ep['url'])
                    for ep in endpoint['accessibility']
                ]
            )
            for endpoint in endpoints
        ]

    @strawberry.field
    def endpoints(self, urls: List[str]) -> List[Endpoint]:
        """
        # Get Multiple Endpoints

        Given a subset of URLs, retrieves all URLs assocaited with any
        URLs in the subset. Note that the purpose of this query is to get information
        on which URLs are related to eachother, not to get detailed information about
        any specific kind of endpoint.

        # Example

        ```graphql
        query {
            endpoints(urls:["https://some-webapp.canada.ca"]) {
                url
            }
        }
        ```

        """
        client = GraphDB()
        endpoints = client.get_endpoints(urls)
        client.close()
        return [Endpoint(url=vertex['url'],
                         kind=vertex['kind']) for vertex in endpoints]

    @strawberry.field
    def referenced_endpoints(self, url: str) -> List[Endpoint]:
        """
        # Get Multiple Endpoints

        Given a subset of URLs, retrieves all URLs assocaited with any
        URLs in the subset. Note that the purpose of this query is to get information
        on which URLs are related to eachother, not to get detailed information about
        any specific kind of endpoint.

        # Example

        ```graphql
        query {
            endpoints(urls:["https://some-webapp.canada.ca"]) {
                url
            }
        }
        ```

        """
        client = GraphDB()
        endpoints = client.get_referenced_endpoints(url)
        client.close()
        return [Endpoint(url=vertex['url'],
                         kind=vertex['kind'],
                         _key=vertex['_key']) for vertex in endpoints]

    @strawberry.field
    def all_edges(self) -> List[Edge]:
        """
        # Get All Edges

        Returns all existing edges within the Arango Graph

        # Example

        ```graphql
        query {
            allEdges {
                url
            }
        }
        ```

        """
        client = GraphDB()
        edges = client.get_all_edges()
        client.close()
        return [Edge(_key=edge['_key'],
                     _id=edge['_id'],
                     from_url=Endpoint(url=edge['_from'],kind=None),
                     to_url=Endpoint(url=edge['_to'],kind=None)) for edge in edges]

    @strawberry.field
    def all_endpoints(self) -> List[Endpoint]:
        """
        # Get All Endpoints

        Returns all existing endpoints within the Arango Graph 

        # Example

        ```graphql
        query {
            allEndpoints {
                url
            }
        }
        ```

        """
        client = GraphDB()
        endpoints = client.get_all_endpoints()
        # print(endpoints)
        client.close()
        return [Endpoint(url=endpoint['url'],
                         kind=endpoint['kind']) for endpoint in endpoints]

    @strawberry.field
    def filter(self, criteria : FilterCriteriaInput) -> List[Endpoint]:
        """
        # Filter Endpoints

        Returns all existing endpoints within the Arango Graph that match the filter cirteria

        # Example

        ```graphql
        query {
            filter(criteria: {kind: "Service"}) {
                url
                kind
            }
        }
        ```

        """
        client = GraphDB()
        endpoints = client.filter_endpoints(criteria=criteria)
        client.close()
        return [Endpoint(url=endpoint['url'],
                         kind=endpoint['kind']) for endpoint in endpoints]

    @strawberry.field
    def service(self, name: str) -> Service:
        client = GraphDB()
        """
        # Fetch a Service

        Returns a Service that contains its related Github Repo and Web URL

        # Example

        ```graphql
        query{
            service(name : "observatory-alpha-phac-gc-ca"){
                url
                kind
                githubEndpoint {
                    url
                    kind
                    programmingLanguage
                    license
                    visibility
                    hasSecurityMd {
                        metadata
                        checkPasses
                    }
                    hasDependabotYaml {
                        metadata
                        checkPasses
                    }
                }
                webEndpoint {
                    url
                    kind
                    accessibility {
                        areaAlt {
                        metadata 
                        checkPasses
                        }
                    }
                }
            }
        }
        ```

        """
        result = client.get_service(name)
        client.close()
        service = result['Service']
        githubEndpoint = result['Github']
        githubEndpoint.pop("_id", None)
        githubEndpoint.pop("_rev", None)

        webEndpoint = result['Web']
        webEndpoint.pop("_id", None)
        webEndpoint.pop("_rev", None)

        if 'accessibility' not in webEndpoint:
            webEndpoint['accessibility'] = []

        return Service(url = service['url'],
                       kind = service['kind'],
                       _key = service['_key'],
                       webEndpoint =  WebEndpoint(
                                        url=webEndpoint['url'],
                                        kind=webEndpoint['kind'],
                                        _key=webEndpoint['_key'],
                                        accessibility=[
                                            Accessibility(**{
                                                k: AccessibilityCheckPasses(**v)
                                                for k, v in ep.items()
                                                if type(v) is not str
                                            },
                                            url=ep['url'])
                                            for ep in webEndpoint['accessibility']
                                        ]
                                    ),
                        githubEndpoint = GithubEndpoint(
                                        **{
                                            k: CheckPasses(**v)
                                            for k, v in githubEndpoint.items()
                                            if type(v) is dict
                                        },
                                        **{
                                            k: v
                                            for k, v in githubEndpoint.items()
                                            if type(v) is not dict
                                        }
                    ))

all_edges()

Get All Edges

Returns all existing edges within the Arango Graph

Example

1
2
3
4
5
query {
    allEdges {
        url
    }
}
Source code in api/src/graphql_types/query.py
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
@strawberry.field
def all_edges(self) -> List[Edge]:
    """
    # Get All Edges

    Returns all existing edges within the Arango Graph

    # Example

    ```graphql
    query {
        allEdges {
            url
        }
    }
    ```

    """
    client = GraphDB()
    edges = client.get_all_edges()
    client.close()
    return [Edge(_key=edge['_key'],
                 _id=edge['_id'],
                 from_url=Endpoint(url=edge['_from'],kind=None),
                 to_url=Endpoint(url=edge['_to'],kind=None)) for edge in edges]

all_endpoints()

Get All Endpoints

Returns all existing endpoints within the Arango Graph

Example

1
2
3
4
5
query {
    allEndpoints {
        url
    }
}
Source code in api/src/graphql_types/query.py
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
@strawberry.field
def all_endpoints(self) -> List[Endpoint]:
    """
    # Get All Endpoints

    Returns all existing endpoints within the Arango Graph 

    # Example

    ```graphql
    query {
        allEndpoints {
            url
        }
    }
    ```

    """
    client = GraphDB()
    endpoints = client.get_all_endpoints()
    # print(endpoints)
    client.close()
    return [Endpoint(url=endpoint['url'],
                     kind=endpoint['kind']) for endpoint in endpoints]

endpoints(urls)

Get Multiple Endpoints

Given a subset of URLs, retrieves all URLs assocaited with any URLs in the subset. Note that the purpose of this query is to get information on which URLs are related to eachother, not to get detailed information about any specific kind of endpoint.

Example

1
2
3
4
5
query {
    endpoints(urls:["https://some-webapp.canada.ca"]) {
        url
    }
}
Source code in api/src/graphql_types/query.py
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
@strawberry.field
def endpoints(self, urls: List[str]) -> List[Endpoint]:
    """
    # Get Multiple Endpoints

    Given a subset of URLs, retrieves all URLs assocaited with any
    URLs in the subset. Note that the purpose of this query is to get information
    on which URLs are related to eachother, not to get detailed information about
    any specific kind of endpoint.

    # Example

    ```graphql
    query {
        endpoints(urls:["https://some-webapp.canada.ca"]) {
            url
        }
    }
    ```

    """
    client = GraphDB()
    endpoints = client.get_endpoints(urls)
    client.close()
    return [Endpoint(url=vertex['url'],
                     kind=vertex['kind']) for vertex in endpoints]

filter(criteria)

Filter Endpoints

Returns all existing endpoints within the Arango Graph that match the filter cirteria

Example

1
2
3
4
5
6
query {
    filter(criteria: {kind: "Service"}) {
        url
        kind
    }
}
Source code in api/src/graphql_types/query.py
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
@strawberry.field
def filter(self, criteria : FilterCriteriaInput) -> List[Endpoint]:
    """
    # Filter Endpoints

    Returns all existing endpoints within the Arango Graph that match the filter cirteria

    # Example

    ```graphql
    query {
        filter(criteria: {kind: "Service"}) {
            url
            kind
        }
    }
    ```

    """
    client = GraphDB()
    endpoints = client.filter_endpoints(criteria=criteria)
    client.close()
    return [Endpoint(url=endpoint['url'],
                     kind=endpoint['kind']) for endpoint in endpoints]

github_endpoint(url)

Get Properties of a Single Github Endpoint

Given a url, retrieves the properties of a single Github Endpoint.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
query {
    githubEndpoint(url: "https://github.com/someOrg/someRepo") {
        url
        kind
        license
        visibility
        automatedSecurityFixes {
            checkPasses
            metadata
        }
    }
}
Source code in api/src/graphql_types/query.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
@strawberry.field
def github_endpoint(self, url: str) -> GithubEndpoint:
    """
    # Get Properties of a Single Github Endpoint

    Given a url, retrieves the properties of a single Github Endpoint.

    # Example

    ```graphql
    query {
        githubEndpoint(url: "https://github.com/someOrg/someRepo") {
            url
            kind
            license
            visibility
            automatedSecurityFixes {
                checkPasses
                metadata
            }
        }
    }
    ```
    """
    client = GraphDB()
    endpoint = client.get_scanner_endpoint(url)
    client.close()
    # Remove unecessary db fields from the endpoint dict
    endpoint.pop("_id", None)
    endpoint.pop("_rev", None)
    return GithubEndpoint(
            **{
                k: CheckPasses(**v)
                for k, v in endpoint.items()
                if type(v) is dict
            },
            **{
                k: v
                for k, v in endpoint.items()
                if type(v) is not dict
            }
    )

github_endpoints(limit)

Get Multiple Github Endpoints

Retrieves a list of Github Endpoints. The number of endpoints returned is determined by the limit parameter.

Example

1
2
3
4
5
6
7
8
query   {
    githubEndpoints(limit: 10){
    url
    kind
    Key
    owner
}
}
Source code in api/src/graphql_types/query.py
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
@strawberry.field
def github_endpoints(self, limit: int) -> List[GithubEndpoint]:
    """
    # Get Multiple Github Endpoints

    Retrieves a list of Github Endpoints. The number of endpoints returned is
    determined by the `limit` parameter.

    # Example

    ```graphql
    query	{
        githubEndpoints(limit: 10){
        url
        kind
        Key
        owner
    }
    }
    ```
    """
    client = GraphDB()
    endpoints = client.get_scanner_endpoints("Github", limit)
    client.close()
    # Remove unecessary db fields from the endpoint dict
    for endpoint in endpoints:
        endpoint.pop("_id", None)
        endpoint.pop("_rev", None)
    return [GithubEndpoint(
                    **{
                        k: CheckPasses(**v)
                        for k, v in endpoint.items()
                        if type(v) is dict
                    },
                    **{
                        k: v
                        for k, v in endpoint.items()
                        if type(v) is not dict
                    }
                )    
            for endpoint in endpoints]

referenced_endpoints(url)

Get Multiple Endpoints

Given a subset of URLs, retrieves all URLs assocaited with any URLs in the subset. Note that the purpose of this query is to get information on which URLs are related to eachother, not to get detailed information about any specific kind of endpoint.

Example

1
2
3
4
5
query {
    endpoints(urls:["https://some-webapp.canada.ca"]) {
        url
    }
}
Source code in api/src/graphql_types/query.py
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
@strawberry.field
def referenced_endpoints(self, url: str) -> List[Endpoint]:
    """
    # Get Multiple Endpoints

    Given a subset of URLs, retrieves all URLs assocaited with any
    URLs in the subset. Note that the purpose of this query is to get information
    on which URLs are related to eachother, not to get detailed information about
    any specific kind of endpoint.

    # Example

    ```graphql
    query {
        endpoints(urls:["https://some-webapp.canada.ca"]) {
            url
        }
    }
    ```

    """
    client = GraphDB()
    endpoints = client.get_referenced_endpoints(url)
    client.close()
    return [Endpoint(url=vertex['url'],
                     kind=vertex['kind'],
                     _key=vertex['_key']) for vertex in endpoints]

web_endpoint(url)

Get Properties of a Single Web Endpoint

Given a url, retrieves the properties of a single Web Endpoint.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
query {
    webEndpoint(url: "https://safeinputs.phac.alpha.canada.ca") {
        url
        accessibility {
        url
        areaAlt {
            checkPasses
            metadata
        }
        }
    }
}
Source code in api/src/graphql_types/query.py
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
@strawberry.field
def web_endpoint(self, url: str) -> WebEndpoint:
    """
    # Get Properties of a Single Web Endpoint

    Given a url, retrieves the properties of a single Web Endpoint.

    # Example

    ```graphql
    query {
        webEndpoint(url: "https://safeinputs.phac.alpha.canada.ca") {
            url
            accessibility {
            url
            areaAlt {
                checkPasses
                metadata
            }
            }
        }
    }
    ```
    """
    client = GraphDB()
    endpoint = client.get_scanner_endpoint(url)
    client.close()
    # Remove unecessary db fields from the endpoint dict
    endpoint.pop("_id", None)
    endpoint.pop("_rev", None)

    if 'accessibility' not in endpoint:
        endpoint['accessibility'] = []

    # Strawberry doesn't recursively resolve fields. The code below
    # is a workaround to recursively resolve the accessibility field
    # and the "check passes" fields contained within.
    return WebEndpoint(
        url=endpoint['url'],
        kind=endpoint['kind'],
        _key=endpoint['_key'],
        accessibility=[
            Accessibility(**{
                k: AccessibilityCheckPasses(**v)
                for k, v in ep.items()
                if type(v) is not str
            },
            url=ep['url'])
            for ep in endpoint['accessibility']
        ]
    )

web_endpoints(limit)

Get Multiple Web Endpoints

Retrieves a list of Web Endpoints. The number of endpoints returned is determined by the limit parameter.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
query {
    webEndpoints(limit: 10) {
        url
        accessibility {
        url
        areaAlt {
            checkPasses
            metadata
        }
        }
    }
}
Source code in api/src/graphql_types/query.py
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
@strawberry.field
def web_endpoints(self, limit: int) -> List[WebEndpoint]:
    """
    # Get Multiple Web Endpoints

    Retrieves a list of Web Endpoints. The number of endpoints returned is
    determined by the `limit` parameter.

    # Example

    ```graphql
    query {
        webEndpoints(limit: 10) {
            url
            accessibility {
            url
            areaAlt {
                checkPasses
                metadata
            }
            }
        }
    }
    ```
    """
    client = GraphDB()
    endpoints = client.get_scanner_endpoints("Web", limit)
    client.close()
    # Remove unecessary db fields from the endpoint dict
    for endpoint in endpoints:
        endpoint.pop("_id", None)
        endpoint.pop("_rev", None)
    # Strawberry doesn't recursively resolve fields. The code below
    # is a workaround to recursively resolve the accessibility field
    # and the "check passes" fields contained within.
    return [
        WebEndpoint(
            url=endpoint['url'],
            kind=endpoint['kind'],
            _key=endpoint['_key'],
            accessibility=[
                Accessibility(**{
                    k: AccessibilityCheckPasses(**v)
                    for k, v in ep.items()
                    if type(v) is not str
                },
                url=ep['url'])
                for ep in endpoint['accessibility']
            ]
        )
        for endpoint in endpoints
    ]