Skip to content

Commit

Permalink
Twilio - 27416 - Updated dependencies | Updated SDK to the latest ver…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
igorski-r7 committed Jan 7, 2025
1 parent ee5250d commit dfb638e
Show file tree
Hide file tree
Showing 20 changed files with 339 additions and 124 deletions.
10 changes: 5 additions & 5 deletions plugins/twilio/.CHECKSUM
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"spec": "c44c0f5ab7e3a322044a83acfb10b817",
"manifest": "621d693d051b5c4549806163cea779b7",
"setup": "50e952cec8d2c9a5404f295fcf472b33",
"spec": "c662adc9643b66a8cb7fc2a6e6a87b03",
"manifest": "f3977d5869256e5f4069df886f88bd2d",
"setup": "1dd3e232ae06b865b4cc6a4381b97708",
"schemas": [
{
"identifier": "send_sms/schema.py",
"hash": "af20fb89e065530bc9ca6b92313cf3dc"
"hash": "d2bd4c43600e8995db3526323e37d446"
},
{
"identifier": "connection/schema.py",
"hash": "08ac8deb36b6dc3f3430221f8c2a20c8"
"hash": "f43143c7fef8d5dff52d63bbff8ece45"
}
]
}
27 changes: 11 additions & 16 deletions plugins/twilio/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
FROM komand/python-2-plugin:2
# The three supported python parent images are:
# - komand/python-2-plugin
# - komand/python-3-plugin
# - komand/python-pypy3-plugin
#
# Update the tag to a full semver version
FROM --platform=linux/amd64 rapid7/insightconnect-python-3-slim-plugin:6.2.2

# Add any custom package dependencies here
# NOTE: Add pip packages to requirements.txt
LABEL organization=rapid7
LABEL sdk=python

# End package dependencies

# Add source code
WORKDIR /python/src

ADD ./plugin.spec.yaml /plugin.spec.yaml
ADD . /python/src
ADD ./requirements.txt /python/src/requirements.txt

# Install pip dependencies
RUN if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

# Install plugin
ADD . /python/src

RUN python setup.py build && python setup.py install

ENTRYPOINT ["/usr/local/bin/komand_twilio"]
# User to run plugin code. The two supported users are: root, nobody
USER nobody

ENTRYPOINT ["/usr/local/bin/komand_twilio"]
46 changes: 30 additions & 16 deletions plugins/twilio/bin/komand_twilio
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
#!/usr/bin/env python
# GENERATED BY KOMAND SDK - DO NOT EDIT
import komand
from komand_twilio import connection, actions, triggers
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
import os
import json
from sys import argv

Name = "Twilio"
Vendor = "rapid7"
Version = "1.0.3"
Description = "Send SMS directly from a workflow using Twilio"

Name = 'Twilio'
Vendor = 'rapid7'
Version = '1.0.2'
Description = 'Send SMS directly from a workflow using Twilio'


class ICONTwilio(komand.Plugin):
def __init__(self):
super(self.__class__, self).__init__(
def main():
if 'http' in argv:
if os.environ.get("GUNICORN_CONFIG_FILE"):
with open(os.environ.get("GUNICORN_CONFIG_FILE")) as gf:
gunicorn_cfg = json.load(gf)
if gunicorn_cfg.get("worker_class", "sync") == "gevent":
from gevent import monkey
monkey.patch_all()
elif 'gevent' in argv:
from gevent import monkey
monkey.patch_all()

import insightconnect_plugin_runtime
from komand_twilio import connection, actions, triggers, tasks

class ICONTwilio(insightconnect_plugin_runtime.Plugin):
def __init__(self):
super(self.__class__, self).__init__(
name=Name,
vendor=Vendor,
version=Version,
description=Description,
connection=connection.Connection()
)
self.add_action(actions.SendSms())
)
self.add_action(actions.SendSms())



def main():
"""Run plugin"""
cli = komand.CLI(ICONTwilio())
cli = insightconnect_plugin_runtime.CLI(ICONTwilio())
cli.run()


Expand Down
80 changes: 59 additions & 21 deletions plugins/twilio/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ purposes.
* Authentication token
* Account ID

# Supported Product Versions

* Twilio Client 9.4.1

# Documentation

## Setup
Expand All @@ -23,47 +27,79 @@ The account SID and Auth Token are viewable in your [console](https://www.twilio

The connection configuration accepts the following parameters:

|Name|Type|Default|Required|Description|Enum|
|----|----|-------|--------|-----------|----|
|twilio_phone_number|string|None|True|Twilio phone number|None|
|auth_token|string|None|True|Twilio Auth Token|None|
|account_id|string|None|True|Twilio Account SID|None|
|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip|
| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- |
|credentials|credential_username_password|None|True|Username should be your account ID, and your password should be your auth token|None|{"username": "ExampleUsername", "password": "ExamplePassword"}|None|None|
|twilio_phone_number|string|None|True|The phone number of a Twilio user from which the SMS will be sent|None|+00000111222|None|None|

Example input:

```
{
"credentials": {
"password": "ExamplePassword",
"username": "ExampleUsername"
},
"twilio_phone_number": "+00000111222"
}
```

## Technical Details

### Actions


#### Send SMS

This action is used to send an SMS message to a phone number.
This action is used to send an SMS message to a phone number

##### Input

|Name|Type|Default|Required|Description|Enum|
|----|----|-------|--------|-----------|----|
|message|string|None|True|Message to send|None|
|to_number|string|None|True|Phone number to send SMS message|None|
|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip|
| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- |
|message|string|None|True|Message to send|None|ExampleMessage|None|None|
|to_number|string|None|True|Phone number to send SMS message|None|+00000111222|None|None|

Example input:

##### Output
```
{
"message": "ExampleMessage",
"to_number": "+00000111222"
}
```

|Name|Type|Required|Description|
|----|----|--------|-----------|
|message_sid|string|False|Message SID|
##### Output

|Name|Type|Required|Description|Example|
| :--- | :--- | :--- | :--- | :--- |
|message_sid|string|False|Message SID|ExampleMessageSID|

Example output:

```
{
"message_sid": "ExampleMessageSID"
}
```
### Triggers

*This plugin does not contain any triggers.*
### Tasks

*This plugin does not contain any tasks.*

_This plugin does not contain any triggers._

### Custom Output Types

_This plugin does not contain any custom output types._
### Custom Types

*This plugin does not contain any custom output types.*

## Troubleshooting

Before sending the SMS make sure that the country you're sending the message to is enabled [here](https://www.twilio.com/console/sms/settings/geo-permissions).

# Version History

* 1.0.3 - Updated dependencies | Updated SDK to the latest version
* 1.0.2 - New spec and help.md format for the Extension Library
* 1.0.1 - Update Twilio dependency to 6.19.1
* 1.0.0 - Update to v2 Python plugin architecture | Support web server mode | Update to new credential types
Expand All @@ -72,8 +108,10 @@ Before sending the SMS make sure that the country you're sending the message to

# Links

* [Twilio](https://www.twilio.com/)
* [SMS Geo-permissions](https://www.twilio.com/console/sms/settings/geo-permissions)

## References

* [Twilio](https://www.twilio.com/)
* [Twilio Python Library](https://www.twilio.com/docs/libraries/python)

* [Twilio Python Library](https://www.twilio.com/docs/libraries/python)
4 changes: 3 additions & 1 deletion plugins/twilio/komand_twilio/actions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# GENERATED BY KOMAND SDK - DO NOT EDIT
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT

from .send_sms.action import SendSms

2 changes: 1 addition & 1 deletion plugins/twilio/komand_twilio/actions/send_sms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# GENERATED BY KOMAND SDK - DO NOT EDIT
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
from .action import SendSms
30 changes: 18 additions & 12 deletions plugins/twilio/komand_twilio/actions/send_sms/action.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
import komand
from .schema import SendSmsInput, SendSmsOutput
import insightconnect_plugin_runtime
from insightconnect_plugin_runtime.exceptions import PluginException
from .schema import SendSmsInput, SendSmsOutput, Input, Output, Component


class SendSms(komand.Action):
class SendSms(insightconnect_plugin_runtime.Action):
def __init__(self):
super(self.__class__, self).__init__(
name="send_sms",
description="Send an SMS message to a phone number",
description=Component.DESCRIPTION,
input=SendSmsInput(),
output=SendSmsOutput(),
)

def run(self, params={}):
message = self.connection.client.messages.create(
body=params.get("message"),
to=params.get("to_number"),
from_=self.connection.twilio_phone_number,
)
return {"message_sid": message.sid}
# START INPUT BINDING - DO NOT REMOVE - ANY INPUTS BELOW WILL UPDATE WITH YOUR PLUGIN SPEC AFTER REGENERATION
message = params.get(Input.MESSAGE, "")
send_to_number = params.get(Input.TO_NUMBER, "").strip()
# END INPUT BINDING - DO NOT REMOVE

def test(self):
return {"message_sid": "SM91b89296d763426db7b50d165f6eadfb"}
try:
message = self.connection.client.messages.create(
body=message,
to=send_to_number,
from_=self.connection.twilio_phone_number,
)
return {Output.MESSAGE_SID: message.sid}
except Exception as error:
raise PluginException(preset=PluginException.Preset.UNKNOWN, data=error)
22 changes: 12 additions & 10 deletions plugins/twilio/komand_twilio/actions/send_sms/schema.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# GENERATED BY KOMAND SDK - DO NOT EDIT
import komand
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
import insightconnect_plugin_runtime
import json


Expand All @@ -10,14 +10,14 @@ class Component:
class Input:
MESSAGE = "message"
TO_NUMBER = "to_number"


class Output:
MESSAGE_SID = "message_sid"


class SendSmsInput(komand.Input):
schema = json.loads("""

class SendSmsInput(insightconnect_plugin_runtime.Input):
schema = json.loads(r"""
{
"type": "object",
"title": "Variables",
Expand All @@ -38,16 +38,17 @@ class SendSmsInput(komand.Input):
"required": [
"message",
"to_number"
]
],
"definitions": {}
}
""")

def __init__(self):
super(self.__class__, self).__init__(self.schema)


class SendSmsOutput(komand.Output):
schema = json.loads("""
class SendSmsOutput(insightconnect_plugin_runtime.Output):
schema = json.loads(r"""
{
"type": "object",
"title": "Variables",
Expand All @@ -58,7 +59,8 @@ class SendSmsOutput(komand.Output):
"description": "Message SID",
"order": 1
}
}
},
"definitions": {}
}
""")

Expand Down
2 changes: 1 addition & 1 deletion plugins/twilio/komand_twilio/connection/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# GENERATED BY KOMAND SDK - DO NOT EDIT
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
from .connection import Connection
30 changes: 22 additions & 8 deletions plugins/twilio/komand_twilio/connection/connection.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import komand
from .schema import ConnectionSchema
import insightconnect_plugin_runtime
from insightconnect_plugin_runtime.exceptions import ConnectionTestException
from typing import Dict, Any
from .schema import ConnectionSchema, Input

# Custom imports below
from twilio.rest import Client
from twilio.http.http_client import TwilioHttpClient


class Connection(komand.Connection):
class Connection(insightconnect_plugin_runtime.Connection):
def __init__(self):
super(self.__class__, self).__init__(input=ConnectionSchema())
self.twilio_phone_number = None
self.client = None

def connect(self, params):
account_sid = params.get("credentials").get("username")
auth_token = params.get("credentials").get("password")
def connect(self, params={}) -> None:
self.logger.info("Connect: Connecting...")
account_sid = params.get(Input.CREDENTIALS, {}).get("username").strip()
auth_token = params.get(Input.CREDENTIALS, {}).get("password").strip()
self.twilio_phone_number = params.get(Input.TWILIO_PHONE_NUMBER, "").strip()
self.client = Client(account_sid, auth_token)
self.twilio_phone_number = params.get("twilio_phone_number")

self.logger.info("connecting")
def test(self) -> Dict[str, Any]:
try:
self.logger.info("Running TLS test over twilio...")
TwilioHttpClient().request("GET", "https://tls-test.twilio.com")
self.logger.info("TLS test passed.")
self.client.messages.list(limit=1)
return {"success": True}
except Exception as error:
raise ConnectionTestException(preset=ConnectionTestException.Preset.UNKNOWN, data=error)
Loading

0 comments on commit dfb638e

Please sign in to comment.