Skip to content
This repository was archived by the owner on Jul 16, 2019. It is now read-only.

Added DummyAuth to support non-duo clients. #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
33 changes: 20 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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__':
Expand Down
28 changes: 28 additions & 0 deletions securitybot/auth/dummy.py
Original file line number Diff line number Diff line change
@@ -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