Skip to content

Commit a7739a6

Browse files
authored
Greengrass v2 IPC Connection and Sample (#144)
1 parent dc07d9b commit a7739a6

26 files changed

+4642
-110
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
docs/.buildinfo
2+
docs/.doctrees/

awsiot/greengrasscoreipc/__init__.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0.
3+
4+
import os
5+
from typing import Optional
6+
7+
from awscrt.io import (
8+
ClientBootstrap,
9+
DefaultHostResolver,
10+
EventLoopGroup,
11+
SocketDomain,
12+
SocketOptions,
13+
)
14+
from awsiot.eventstreamrpc import (
15+
Connection,
16+
LifecycleHandler,
17+
MessageAmendment,
18+
)
19+
from awsiot.greengrasscoreipc.client import GreengrassCoreIPCClient
20+
21+
22+
def connect(*,
23+
ipc_socket: str=None,
24+
authtoken: str=None,
25+
lifecycle_handler: Optional[LifecycleHandler]=None,
26+
timeout=10.0) -> GreengrassCoreIPCClient:
27+
"""
28+
Creates an IPC client and connects to the GreengrassCoreIPC service.
29+
30+
Args:
31+
ipc_socket: Path to the Unix domain socket of Greengrass Nucleus, defaults to
32+
environment variable AWS_GG_NUCLEUS_DOMAIN_SOCKET_FILEPATH_FOR_COMPONENT
33+
authtoken: Authentication token, defaults to environment variable SVCUID
34+
lifecycle_handler: Handler for events over the course of this
35+
network connection. See :class:`LifecycleHandler` for more info.
36+
Handler methods will only be invoked if the connect attempt
37+
succeeds.
38+
timeout: The number of seconds to wait for establishing the connection.
39+
40+
Returns:
41+
Client for the GreengrassCoreIPC service.
42+
"""
43+
44+
if not ipc_socket:
45+
ipc_socket = os.environ["AWS_GG_NUCLEUS_DOMAIN_SOCKET_FILEPATH_FOR_COMPONENT"]
46+
if not authtoken:
47+
authtoken = os.environ["SVCUID"]
48+
if not lifecycle_handler:
49+
lifecycle_handler = LifecycleHandler()
50+
51+
elg = EventLoopGroup(num_threads=1)
52+
resolver = DefaultHostResolver(elg)
53+
bootstrap = ClientBootstrap(elg, resolver)
54+
socket_options = SocketOptions()
55+
socket_options.domain = SocketDomain.Local
56+
amender = MessageAmendment.create_static_authtoken_amender(authtoken)
57+
58+
connection = Connection(
59+
host_name=ipc_socket,
60+
port=0, # dummy port number, not needed for Unix domain sockets
61+
bootstrap=bootstrap,
62+
socket_options=socket_options,
63+
connect_message_amender=amender,
64+
)
65+
connect_future = connection.connect(lifecycle_handler)
66+
connect_future.result(timeout)
67+
68+
return GreengrassCoreIPCClient(connection)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
awsiot.greengrasscoreipc
2+
===========================
3+
4+
.. automodule:: awsiot.greengrasscoreipc
5+
:members:
6+
7+
.. automodule:: awsiot.greengrasscoreipc.client
8+
:members:
9+
10+
.. automodule:: awsiot.greengrasscoreipc.model
11+
:members:

docs/_sources/index.rst.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
.. AWS IoT Device SDK Python v2 documentation master file, created by
1+
.. AWS IoT Device SDK v2 for Python documentation master file, created by
22
sphinx-quickstart on Mon Aug 17 14:57:36 2020.
33
You can adapt this file completely to your liking, but it should at least
44
contain the root `toctree` directive.
55
6-
AWS IoT Device SDK Python v2
7-
============================
6+
AWS IoT Device SDK v2 for Python
7+
================================
88

99
Python bindings for the AWS IoT Device API.
1010

@@ -18,7 +18,8 @@ API Reference
1818
-------------
1919
.. toctree::
2020
:maxdepth: 2
21-
21+
22+
awsiot/greengrasscoreipc
2223
awsiot/greengrass_discovery
2324
awsiot/iotidentity
2425
awsiot/iotjobs

docs/_static/basic.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Sphinx stylesheet -- basic theme.
66
*
7-
* :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
7+
* :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS.
88
* :license: BSD, see LICENSE for details.
99
*
1010
*/
@@ -764,6 +764,7 @@ div.code-block-caption code {
764764
}
765765

766766
table.highlighttable td.linenos,
767+
span.linenos,
767768
div.doctest > div.highlight span.gp { /* gp: Generic.Prompt */
768769
user-select: none;
769770
}

docs/_static/bizstyle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ $(window).resize(function(){
3636
$("li.nav-item-0 a").text("Top");
3737
}
3838
else {
39-
$("li.nav-item-0 a").text("AWS IoT Device SDK Python v2 documentation");
39+
$("li.nav-item-0 a").text("AWS IoT Device SDK v2 for Python documentation");
4040
}
4141
});

docs/_static/doctools.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Sphinx JavaScript utilities for all documentation.
66
*
7-
* :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
7+
* :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS.
88
* :license: BSD, see LICENSE for details.
99
*
1010
*/
@@ -285,9 +285,10 @@ var Documentation = {
285285
initOnKeyListeners: function() {
286286
$(document).keydown(function(event) {
287287
var activeElementType = document.activeElement.tagName;
288-
// don't navigate when in search box or textarea
288+
// don't navigate when in search box, textarea, dropdown or button
289289
if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT'
290-
&& !event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey) {
290+
&& activeElementType !== 'BUTTON' && !event.altKey && !event.ctrlKey && !event.metaKey
291+
&& !event.shiftKey) {
291292
switch (event.keyCode) {
292293
case 37: // left
293294
var prevHref = $('link[rel="prev"]').prop('href');

docs/_static/language_data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* This script contains the language-specific data used by searchtools.js,
66
* namely the list of stopwords, stemmer, scorer and splitter.
77
*
8-
* :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
8+
* :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS.
99
* :license: BSD, see LICENSE for details.
1010
*
1111
*/

docs/_static/pygments.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
pre { line-height: 125%; margin: 0; }
2+
td.linenos pre { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
3+
span.linenos { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
4+
td.linenos pre.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
5+
span.linenos.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
16
.highlight .hll { background-color: #ffffcc }
2-
.highlight { background: #f0f0f0; }
7+
.highlight { background: #f0f0f0; }
38
.highlight .c { color: #60a0b0; font-style: italic } /* Comment */
49
.highlight .err { border: 1px solid #FF0000 } /* Error */
510
.highlight .k { color: #007020; font-weight: bold } /* Keyword */

docs/_static/searchtools.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Sphinx JavaScript utilities for the full-text search.
66
*
7-
* :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
7+
* :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS.
88
* :license: BSD, see LICENSE for details.
99
*
1010
*/
@@ -59,10 +59,10 @@ var Search = {
5959
_pulse_status : -1,
6060

6161
htmlToText : function(htmlString) {
62-
var htmlElement = document.createElement('span');
63-
htmlElement.innerHTML = htmlString;
64-
$(htmlElement).find('.headerlink').remove();
65-
docContent = $(htmlElement).find('[role=main]')[0];
62+
var virtualDocument = document.implementation.createHTMLDocument('virtual');
63+
var htmlElement = $(htmlString, virtualDocument);
64+
htmlElement.find('.headerlink').remove();
65+
docContent = htmlElement.find('[role=main]')[0];
6666
if(docContent === undefined) {
6767
console.warn("Content block not found. Sphinx search tries to obtain it " +
6868
"via '[role=main]'. Could you check your theme or template.");

docs/awsiot/greengrass_discovery.html

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@
66
<head>
77
<meta charset="utf-8" />
88
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
9-
<title>awsiot.greengrass_discovery &#8212; AWS IoT Device SDK Python v2 documentation</title>
10-
<link rel="stylesheet" href="../_static/bizstyle.css" type="text/css" />
9+
<title>awsiot.greengrass_discovery &#8212; AWS IoT Device SDK v2 for Python documentation</title>
1110
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
11+
<link rel="stylesheet" href="../_static/bizstyle.css" type="text/css" />
1212

1313
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
1414
<script src="../_static/jquery.js"></script>
1515
<script src="../_static/underscore.js"></script>
1616
<script src="../_static/doctools.js"></script>
17-
<script src="../_static/language_data.js"></script>
1817
<script src="../_static/bizstyle.js"></script>
1918
<link rel="index" title="Index" href="../genindex.html" />
2019
<link rel="search" title="Search" href="../search.html" />
2120
<link rel="next" title="awsiot.iotidentity" href="iotidentity.html" />
22-
<link rel="prev" title="AWS IoT Device SDK Python v2" href="../index.html" />
21+
<link rel="prev" title="awsiot.greengrasscoreipc" href="greengrasscoreipc.html" />
2322
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
2423
<!--[if lt IE 9]>
2524
<script src="_static/css3-mediaqueries.js"></script>
@@ -38,9 +37,9 @@ <h3>Navigation</h3>
3837
<a href="iotidentity.html" title="awsiot.iotidentity"
3938
accesskey="N">next</a> |</li>
4039
<li class="right" >
41-
<a href="../index.html" title="AWS IoT Device SDK Python v2"
40+
<a href="greengrasscoreipc.html" title="awsiot.greengrasscoreipc"
4241
accesskey="P">previous</a> |</li>
43-
<li class="nav-item nav-item-0"><a href="../index.html">AWS IoT Device SDK Python v2 documentation</a> &#187;</li>
42+
<li class="nav-item nav-item-0"><a href="../index.html">AWS IoT Device SDK v2 for Python documentation</a> &#187;</li>
4443
<li class="nav-item nav-item-this"><a href="">awsiot.greengrass_discovery</a></li>
4544
</ul>
4645
</div>
@@ -87,8 +86,8 @@ <h3>Navigation</h3>
8786
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
8887
<div class="sphinxsidebarwrapper">
8988
<h4>Previous topic</h4>
90-
<p class="topless"><a href="../index.html"
91-
title="previous chapter">AWS IoT Device SDK Python v2</a></p>
89+
<p class="topless"><a href="greengrasscoreipc.html"
90+
title="previous chapter">awsiot.greengrasscoreipc</a></p>
9291
<h4>Next topic</h4>
9392
<p class="topless"><a href="iotidentity.html"
9493
title="next chapter">awsiot.iotidentity</a></p>
@@ -126,15 +125,15 @@ <h3>Navigation</h3>
126125
<a href="iotidentity.html" title="awsiot.iotidentity"
127126
>next</a> |</li>
128127
<li class="right" >
129-
<a href="../index.html" title="AWS IoT Device SDK Python v2"
128+
<a href="greengrasscoreipc.html" title="awsiot.greengrasscoreipc"
130129
>previous</a> |</li>
131-
<li class="nav-item nav-item-0"><a href="../index.html">AWS IoT Device SDK Python v2 documentation</a> &#187;</li>
130+
<li class="nav-item nav-item-0"><a href="../index.html">AWS IoT Device SDK v2 for Python documentation</a> &#187;</li>
132131
<li class="nav-item nav-item-this"><a href="">awsiot.greengrass_discovery</a></li>
133132
</ul>
134133
</div>
135134
<div class="footer" role="contentinfo">
136-
&#169; Copyright 2020, Amazon Web Services, Inc.
137-
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
135+
&#169; Copyright 2021, Amazon Web Services, Inc.
136+
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.4.2.
138137
</div>
139138
</body>
140139
</html>

0 commit comments

Comments
 (0)