Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swimlane: add client and config #24

Merged
merged 41 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
4c0c42c
swimlane: add client and config
laerfulaolun Feb 14, 2024
3eb6973
requests: update to async
laerfulaolun Feb 20, 2024
4ffe908
requests: add reason method
laerfulaolun Feb 20, 2024
672516c
requests: add content prop, add to_json method
laerfulaolun Feb 21, 2024
ecf7404
requests: minor support for request.Session
laerfulaolun Feb 22, 2024
b09d111
requests: default to requests.Session
laerfulaolun Feb 22, 2024
cb00c4a
requests: rename property results to response
laerfulaolun Feb 24, 2024
caac33b
swimlane: update client and config
laerfulaolun Feb 20, 2024
76a08e1
swimlane: support apis "app", "workspace"
laerfulaolun Mar 1, 2024
a262c7b
swimlane: support api "record"
laerfulaolun Mar 2, 2024
32bfd52
swimlane: update record methods
laerfulaolun Mar 8, 2024
2392740
swimlane: add headers_jwt_token
laerfulaolun Mar 8, 2024
331da06
swimlane: update client
laerfulaolun Mar 9, 2024
d85a30b
swimlane: add test_library_record_create.py
laerfulaolun Mar 14, 2024
9840fae
swimlane: rename tests
laerfulaolun Mar 14, 2024
4f39993
requests: fix to_dict, fix to_json
laerfulaolun Mar 14, 2024
806bd71
swimlane: fix record methods
laerfulaolun Mar 14, 2024
eacbc70
swimlane: add get record
laerfulaolun Mar 14, 2024
5c08ac2
swimlane: add appId to config
laerfulaolun Mar 14, 2024
87b000a
requests: add content_to_dict
laerfulaolun Mar 15, 2024
b352754
swimlane: v2 add user authorize endpoint
laerfulaolun Mar 15, 2024
85f83e0
swimlane: fix login_token
laerfulaolun Mar 15, 2024
9c56571
swimlane: update record_create_easy
laerfulaolun Mar 15, 2024
b40324a
swimlane: fix credentials
laerfulaolun Mar 15, 2024
7256af5
swimlane: add test_rest_auth_token.py
laerfulaolun Mar 15, 2024
7990be4
swimlane: add test_rest_record_create.py
laerfulaolun Mar 15, 2024
93cfdf0
swimlane: return record after created
laerfulaolun Mar 15, 2024
822440c
swimlane: update test_rest_app.py
laerfulaolun Mar 15, 2024
f7d17e0
swimlane: update test_rest_record.py
laerfulaolun Mar 15, 2024
ef6890a
swimlane: fix test_library_record_create.py
laerfulaolun Mar 15, 2024
b6d3b25
swimlane: fix record hardcoded key hash
laerfulaolun Mar 15, 2024
5f87b4e
swimlane: add python package
laerfulaolun Mar 17, 2024
4b97fc5
Merge branch 'master' into add-swimlane
laerfulaolun Mar 17, 2024
543b51b
Merge branch 'TheShellLand:master' into add-swimlane
laerfulaolun Mar 19, 2024
48c2819
Merge branch 'master' into add-swimlane
laerfulaolun Mar 19, 2024
9d6a1a5
swimlane: disable library test. its dependencies are so old it breaks…
laerfulaolun Mar 19, 2024
19e3db8
swimlane: update test
laerfulaolun Mar 20, 2024
e66e3cb
swimlane: add method record_resolve_fields. rename method record_sche…
laerfulaolun Mar 23, 2024
2fc3f49
swimlane: add tests
laerfulaolun Mar 23, 2024
c1d5c6b
swimlane: fix tests
laerfulaolun Mar 23, 2024
b0c48aa
swimlane: add tests
laerfulaolun Mar 23, 2024
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
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
Loading