Skip to content
This repository was archived by the owner on Jul 21, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion sydent/config/sms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import configparser
from configparser import ConfigParser
from typing import Dict, List

import sydent.sms.openmarket
from sydent.config._base import BaseConfig
from sydent.config.exceptions import ConfigError
from sydent.util.loader import load_class


class SMSConfig(BaseConfig):
Expand All @@ -33,6 +35,16 @@ def parse_config(self, cfg: "ConfigParser") -> bool:
self.api_username = cfg.get("sms", "username").encode("UTF-8")
self.api_password = cfg.get("sms", "password").encode("UTF-8")

self.provider_class = sydent.sms.openmarket.OpenMarketSMS
try:
sms_provider = cfg.get("sms", "provider")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add documentation for this configuration option.

except configparser.NoOptionError:
pass
else:
if sms_provider:
self.provider_class = load_class(sms_provider)
self.provider_config = cfg.get("sms", "provider_config", fallback={})

self.originators: Dict[str, List[Dict[str, str]]] = {}
self.smsRules = {}

Expand Down
13 changes: 13 additions & 0 deletions sydent/util/loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import importlib
from typing import Type

from sydent.config.exceptions import ConfigError


def load_class(full_path: str) -> Type:
try:
_module, class_name = full_path.rsplit(".", 1)
module = importlib.import_module(_module)
return getattr(module, class_name)
except (AttributeError, ModuleNotFoundError):
raise ConfigError("Cannot load: %s" % full_path)
5 changes: 2 additions & 3 deletions sydent/validators/msisdnvalidator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import phonenumbers

from sydent.db.valsession import ThreePidValSessionStore
from sydent.sms.openmarket import OpenMarketSMS
from sydent.util import time_msec
from sydent.validators import DestinationRejectedException, common

Expand All @@ -32,7 +31,7 @@
class MsisdnValidator:
def __init__(self, sydent: "Sydent") -> None:
self.sydent = sydent
self.omSms = OpenMarketSMS(sydent)
self.Sms = sydent.config.sms.provider_class(sydent)

# cache originators & sms rules from config file
self.originators = self.sydent.config.sms.originators
Expand Down Expand Up @@ -94,7 +93,7 @@ async def requestToken(

smsBody = smsBodyTemplate.format(token=token_info.token)

await self.omSms.sendTextSMS(smsBody, msisdn, originator)
await self.Sms.sendTextSMS(smsBody, msisdn, originator)

valSessionStore.setSendAttemptNumber(valSession.id, send_attempt)

Expand Down