Skip to content

Commit

Permalink
Merge pull request #24 from laerfulaolun/add-swimlane
Browse files Browse the repository at this point in the history
swimlane: add client and config
  • Loading branch information
naisanzaa authored Mar 23, 2024
2 parents c5be9e0 + b0c48aa commit 4142b22
Show file tree
Hide file tree
Showing 17 changed files with 698 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ Github issues and feature requests welcomed.

### Integrations

| Category | Library |
|-----------------|-------------------------------------------------------------|
| API | flask |
| Chat | slack |
| Data Scraping | beautifulsoup<br/>facebook groups<br/>instagram<br/>scrapy |
| Databases | elasticsearch<br/>neo4j<br/>splunk |
| Data Store | minio<br/>swift |
| Devices | snmp |
| Google Cloud | google auth api<br/>google people api<br/>google sheets api |
| Logging | sentryio |
| MacOS | airport<br/>macchanger |
| Python | logging<br/>requests |
| SOAR | swimlane<br/>splunk soar |
| Recon | nmap |
| Test Automation | selenium |
| Category | Library |
|-------------------|-------------------------------------------------------------|
| API | flask |
Expand Down
1 change: 1 addition & 0 deletions automon/integrations/swimlaneWrapper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .client import SwimlaneClient, SwimlaneClientRest, SwimlaneConfig
Empty file.
94 changes: 94 additions & 0 deletions automon/integrations/swimlaneWrapper/api/v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
from enum import Enum


class Api(object):
api = f'api'


class Auth(object):
api = f'{Api.api}/auth'
user = f'{api}/user'
token = f'{api}/token'
create = f'{token}/create'

@classmethod
def delete(cls, userId: str):
return f'{cls.user}/{userId}/token'

@classmethod
def metadata(cls, userId: str):
return f'{cls.user}/{userId}/token'


class ApplicationViewModels(Enum):
"""
[
{
"id": "string",
"name": "string",
"acronym": "string",
"description": "string",
"createdDate": "string",
"createdByUser": {
"id": "string",
"name": "string"
},
"modifiedDate": "string",
"modifiedByUser": {
"id": "string",
"name": "string"
}
}
]
"""
id: str
name: str
acronym: str
description: str
createdDate: str
createdByUser: {
"id": str,
"name": str
}
modifiedDate: str
modifiedByUser: {
"id": str,
"name": str
}


class Application(object):
api = f'{Api.api}/app'
light = f'{api}/light'


class Record(object):

@classmethod
def api(cls, appId: str):
return f'{Application.api}/{appId}/record'

@classmethod
def get(cls, appId: str, id: str):
return f'{cls.api(appId)}/{id}'


class User(object):
api = f'{Api.api}/user'
login = f'{api}/login'
authorize = f'{api}/authorize'


class Workspace(object):
api = f'{Api.api}/workspaces'
nav = f'{api}/nav'

@classmethod
def id(cls, id: str):
"""workspace specified by id"""
return f'{cls.api}/{id}'

@classmethod
def app(cls, id: str):
"""workspaces for application id"""
return f'{cls.api}/app/{id}'
248 changes: 248 additions & 0 deletions automon/integrations/swimlaneWrapper/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
import json

from automon import log
from automon.integrations.requestsWrapper import RequestsClient

from .config import SwimlaneConfig
from .api.v2 import *

logger = log.logging.getLogger(__name__)
logger.setLevel(log.DEBUG)


class SwimlaneClient(object):
pass


class SwimlaneClientRest(object):

def __init__(self):
self.config = SwimlaneConfig()
self.requests = RequestsClient()

self.auth = None
self.apps = None
self.records = None
self.workspaces = None

async def is_ready(self):
if await self.config.is_ready():
if self.config.headers:
return True

async def test_connection(self):
return

async def login(self):
"""tries all types of login"""

if await self.login_username_password():
return True

if await self.login_token():
return True

return False

async def login_username_password(self) -> bool:
"""Login with username and password"""
url = f'{self.host}/{User.login}'

response = await self.requests.post(
url=url,
json=self.config.credentials,
)

apiKey = dict(json.loads(self.requests.content)).get('token')
self.config.apiKey = apiKey

self.requests.session.headers.update(self.config.headers)

self.config.userName_model = await self.requests.to_dict()

return response

async def login_token(self) -> bool:
"""Login with username and password"""
url = f'{self.host}/{User.authorize}'

self.requests.session.headers.update(self.config.headers_jwt_token)

response = await self.requests.get(
url=url,
)

self.config.userName_model = await self.requests.to_dict()

return response

async def create_auth_token(self):
"""Creates a new access token for the user making the request"""
url = f'{self.host}/{Auth.create}'

response = await self.requests.post(
url=url,
)

return response

async def app_list(self):
url = f'{self.host}/{Application.api}'

response = await self.requests.get(
url=url,
)

self.apps = await self.requests.to_dict()

return self.apps

@property
def host(self):
return self.config.host

async def record_resolve_fields(self, appId: str):
"""since swimlane has no documentation on resolving field names"""

url = f'{self.host}/{Record.api(appId)}'

response = await self.requests.get(
url=url,
)

record_hashmap = {}

record = await self.requests.to_dict()
record_values = dict(record.get('values'))

for item in record_values.items():
key, value = item
if '$' in key:
continue
record_hashmap[key] = key

logger.debug(record_hashmap)

record = {
"applicationId": appId,
"values": {
"$type": "System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Object, mscorlib]], mscorlib",
}
}

record.get('values').update(record_hashmap)

record_create = await self.record_create_hard(appId=appId, data=record)

return record_hashmap

async def record_schema(self, appId: str):
url = f'{self.host}/{Record.api(appId)}'

response = await self.requests.get(
url=url,
)

record = await self.requests.to_dict()

return record

async def record_create(self, appId: str, key: str, value: str or int):
"""create a record"""
return await self.record_create_easy(appId=appId, key=key, value=value)

async def record_create_easy(self, appId: str, key: str, value: str or int):
"""create a record with boilerplate added
The bare minimum you need to send is (assuming application id is 5667113fd273a205bc747cf0):
{
"applicationId": "5667113fd273a205bc747cf0",
"values": {
"$type": "System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Object, mscorlib]], mscorlib",
"56674c5cc6c7dea0aeab4aed": "A new value"
}
}
"""
url = f'{self.host}/{Record.api(appId)}'

record = {
"applicationId": appId,
"values": {
"$type": "System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Object, mscorlib]], mscorlib",
key: value
}
}

record_json = json.dumps(record)

response = await self.requests.post(
url=url,
json=record
)

record_created = await self.requests.content_to_dict()

return record_created

async def record_create_hard(self, appId: str, data: dict):
"""create a record the hard way
no handholding. you're on your own"""
url = f'{self.host}/{Record.api(appId)}'

response = await self.requests.post(
url=url,
json=data
)

record_created = await self.requests.content_to_dict()

return record_created

async def record_delete_all(self, appId: str):
"""delete all records in application"""
url = f'{self.host}/{Record.api(appId)}'

response = await self.requests.delete(
url=url
)

return response

async def record_get(self, appId: str, id: str):
"""get a record"""
url = f'{self.host}/{Record.get(appId=appId, id=id)}'

response = await self.requests.get(
url=url
)

record = await self.requests.to_dict()

return record

async def record_get_base(self, appId: str):
"""get a record"""
url = f'{self.host}/{Record.api(appId=appId)}'

response = await self.requests.get(
url=url
)

return response

@property
def userId(self):
return self.config.userName

async def workspace_list(self):
url = f'{self.host}/{Workspace.api}'

response = await self.requests.get(
url=url,
)

self.workspaces = await self.requests.to_dict()

return self.workspaces
Loading

0 comments on commit 4142b22

Please sign in to comment.