diff --git a/main.py b/main.py index 9d81a72..a4458e4 100644 --- a/main.py +++ b/main.py @@ -1,18 +1,29 @@ #!/usr/bin/env python import logging - +import os from securitybot.bot import SecurityBot from securitybot.chat.slack import Slack from securitybot.tasker.sql_tasker import SQLTasker -from securitybot.auth.duo import DuoAuth from securitybot.sql import init_sql -import duo_client + +DUO_INTEGRATION = os.environ.get("DUO_INTEGRATION", None) +DUO_SECRET = os.environ.get("DUO_SECRET", None) +DUO_ENDPOINT = os.environ.get("DUO_ENDPOINT", None) + +if all(DUO_SECRET, DUO_ENDPOINT, DUO_INTEGRATION): + from securitybot.auth.duo import DuoAuth as AuthService + import duo_client + auth_api = duo_client.Auth( + ikey=DUO_INTEGRATION, + skey=DUO_SECRET, + host=DUO_ENDPOINT + ) +else: + from securitybot.auth.dummy import DummyAuth as AuthService + auth_api = None CONFIG = {} SLACK_KEY = 'slack_api_token' -DUO_INTEGRATION = 'duo_integration_key' -DUO_SECRET = 'duo_secret_key' -DUO_ENDPOINT = 'duo_endpoint' REPORTING_CHANNEL = 'some_slack_channel_id' ICON_URL = 'https://dl.dropboxusercontent.com/s/t01pwfrqzbz3gzu/securitybot.png' @@ -28,17 +39,13 @@ def main(): init_sql() # Create components needed for Securitybot - duo_api = duo_client.Auth( - ikey=DUO_INTEGRATION, - skey=DUO_SECRET, - host=DUO_ENDPOINT - ) - duo_builder = lambda name: DuoAuth(duo_api, name) + + auth_builder = lambda name: AuthService(auth_api, name) chat = Slack('securitybot', SLACK_KEY, ICON_URL) tasker = SQLTasker() - sb = SecurityBot(chat, tasker, duo_builder, REPORTING_CHANNEL, 'config/bot.yaml') + sb = SecurityBot(chat, tasker, auth_builder, REPORTING_CHANNEL, 'config/bot.yaml') sb.run() if __name__ == '__main__': diff --git a/securitybot/auth/dummy.py b/securitybot/auth/dummy.py new file mode 100644 index 0000000..ede4e9d --- /dev/null +++ b/securitybot/auth/dummy.py @@ -0,0 +1,28 @@ +from securitybot.auth.auth import Auth, AUTH_STATES + + +class DummyAuth(Auth): + def __init__(self, auth_api, username): + # type: (Any, str) -> None + ''' + Args: + auth_api: Just to match API + username (str): Just to match API + ''' + pass + + def can_auth(self): + # type: () -> bool + return True + + def auth(self, reason=None): + # type: (str) -> None + pass + + def auth_status(self): + # type: () -> int + return AUTH_STATES.AUTHORIZED + + def reset(self): + # type: () -> None + pass