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 9, 2025
1 parent 55f5e0e commit ff3bacf
Show file tree
Hide file tree
Showing 21 changed files with 378 additions and 128 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": "e87fd8ad2c7e366705ec83b56f1ee15d",
"manifest": "796fa28ed7a5550eff84aca20e347207",
"setup": "0aa42478906c348fb90dce4ab409e91f",
"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 = "[Twilio](https://www.twilio.com/) is a cloud communications platform for building SMS, voice, and messaging applicationson an API built for global scale. Users can send SMS using the Twilio plugin for Rapid7 for notification or other purposes"

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
85 changes: 61 additions & 24 deletions plugins/twilio/help.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Description

[Twilio](https://www.twilio.com/) is a cloud communications platform for building SMS, voice, and messaging applications
on an API built for global scale. Users can send SMS using the Twilio plugin for Rapid7 for notification or other
purposes.
on an API built for global scale. Users can send SMS using the Twilio plugin for Rapid7 for notification or other purposes

# Key Features

Expand All @@ -14,6 +13,10 @@ purposes.
* Authentication token
* Account ID

# Supported Product Versions

* Twilio Client 9.4.1

# Documentation

## Setup
Expand All @@ -23,47 +26,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).
* 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 +107,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
34 changes: 22 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,33 @@
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
from twilio.base.exceptions import TwilioRestException
from komand_twilio.util.utils import handle_exception_status_code


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 TwilioRestException as error:
handle_exception_status_code(error)
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
Loading

0 comments on commit ff3bacf

Please sign in to comment.