Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
43f4897
add mysql_source.py
sudharsana-kjl Jul 5, 2019
bd0fb5f
add help for query arg in mysql_source
sudharsana-kjl Jul 7, 2019
fe34a34
fix typo
sudharsana-kjl Jul 8, 2019
a7e19fd
add query format in mysql_source
sudharsana-kjl Jul 8, 2019
1a43843
modify CHANGELOG
sudharsana-kjl Jul 8, 2019
2dbe495
add DictCursor in mysql source
sudharsana-kjl Jul 8, 2019
d36a2f3
modify changelog
sudharsana-kjl Jul 10, 2019
facb3da
modify setup.py to add aiomysql package requirement
sudharsana-kjl Jul 10, 2019
563c04a
source: mysql_source: add different args for different queries
sudharsana-kjl Jul 10, 2019
f0423b5
source: mysql_source: remove defaults for db, user, pass
sudharsana-kjl Jul 10, 2019
fcb1ed4
initial test for mysql connection setup
sudharsana-kjl Jul 13, 2019
31eeffd
source: mysql_source: connection verified and add test for fetch a re…
sudharsana-kjl Jul 14, 2019
3f4a628
source: mysql: modify update()
sudharsana-kjl Jul 14, 2019
3a06cee
source: mysql: modify update()
sudharsana-kjl Jul 16, 2019
05abd5f
source: mysql: update() refined
sudharsana-kjl Jul 16, 2019
9e39bce
add db.sql file
sudharsana-kjl Jul 16, 2019
09b9bc5
source: mysql: modify convert_to_repos()
sudharsana-kjl Jul 16, 2019
1dd30fe
source: mysql: unfold escaped string after fetching
sudharsana-kjl Jul 16, 2019
59b3982
source: mysql: modify convert_to_repo to work for one repo
sudharsana-kjl Jul 16, 2019
896dd91
Create table in mysql testcase setUP
Jul 16, 2019
867dcae
source: mysql: modify help queries in args()
sudharsana-kjl Jul 18, 2019
58f4437
add ssl for mysql source
sudharsana-kjl Jul 21, 2019
f95b9e3
Merge branch 'master' into mysql_feature
sudharsana-kjl Jul 28, 2019
b9a6f4e
fix merge conflict
sudharsana-kjl Jul 28, 2019
2f4cde4
Merge branch 'mysql_feature' of https://github.com/sudharsana-kjl/dff…
sudharsana-kjl Jul 28, 2019
f692839
set up mysql in travis
sudharsana-kjl Aug 1, 2019
6554a2b
Merge branch 'master' into mysql_feature
sudharsana-kjl Aug 1, 2019
57362f7
add mysql test-db for travis
sudharsana-kjl Aug 1, 2019
cfae9a8
modify test-db for travis
sudharsana-kjl Aug 1, 2019
efcd934
modify test-db
sudharsana-kjl Aug 1, 2019
e4d9d7f
modify mysql host in test_mysql
sudharsana-kjl Aug 1, 2019
3897fc3
change port in test_mysql
sudharsana-kjl Aug 1, 2019
6a13093
modify port in test_mysql
sudharsana-kjl Aug 1, 2019
a098103
remove ssl
sudharsana-kjl Aug 1, 2019
c791b2c
fix style
sudharsana-kjl Aug 1, 2019
6c67cee
Merge branch 'master' into mysql_feature
sudharsana-kjl Aug 5, 2019
181bf51
source: mysql: New module
pdxjohnny Aug 9, 2019
67c139b
mysql is being a fucker: line 54: /docker-entrypoint-initdb.d/dump.sq…
Aug 9, 2019
b5f1acd
source: mysql: Test in docker
pdxjohnny Aug 12, 2019
2fa312a
merge master
pdxjohnny Aug 13, 2019
864d2ef
ci: source mysql travis
pdxjohnny Aug 13, 2019
38b2417
source: mysql: certificate verify failed: self signed certificate in …
pdxjohnny Aug 13, 2019
60f837f
signing with intermedate still results in self signed error
pdxjohnny Aug 13, 2019
cfebc4f
internmetiate cert
Aug 13, 2019
2844a02
mariadb and pcks8 to 1
Aug 15, 2019
f4a80c9
tests: TLS with mariadb
Aug 16, 2019
f7a0a58
merge
Aug 16, 2019
34e2e2f
util: Add timing
Aug 16, 2019
bd46437
Squashed commit of the following:
pdxjohnny Sep 9, 2019
d9b08a3
style: Format with black
pdxjohnny Sep 9, 2019
b57872b
Merge remote-tracking branch 'origin/master' into mysql_feature
pdxjohnny Sep 9, 2019
39512c3
fix link to readme
pdxjohnny Sep 9, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
DFFML models and operations.
- Classification type parameter to DNNClassifierModelConfig to specifiy data
type of given classification options.
- Mysql Source feature to work with data from a mysql database
### Changed
- feature/codesec became it's own branch, binsec
- BaseOrchestratorContext `run_operations` strict is default to true. With
Expand Down
114 changes: 114 additions & 0 deletions dffml/source/mysql_source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import json
import aiomysql
from typing import AsyncIterator, NamedTuple, Dict

from dffml.base import BaseConfig
from dffml.repo import Repo
from dffml.source.source import BaseSourceContext, BaseSource
from dffml.util.cli.arg import Arg
from dffml.util.entrypoint import entry_point


class MysqlSourceConfig(BaseConfig, NamedTuple):
host: str
port: int
user: str
password: str
db: str
query: str


class MysqlSourceContext(BaseSourceContext):
async def update(self, repo: Repo):
db = self.conn
marshall = json.dumps(repo.dict())
await db.execute(self.config.query, (repo.src_url, marshall, marshall))
self.logger.debug("updated: %s", marshall)
self.logger.debug("update: %s", await self.repo(repo.src_url))

async def repos(self) -> AsyncIterator[Repo]:
# Query Format:
# SELECT key as src_url, data_1 as feature_1, data_2 as feature_2 FROM list_of_all_repos
query = self.config.query
await self.conn.execute(query)
src_urls = set(map(lambda row: row[0], await self.conn.fetchall()))
for src_url in src_urls:
yield await self.repo(src_url)

async def repo(self, src_url: str):
# Query Format:
# SELECT key as src_url, data_1 as feature_1, data_2 as feature_2 FROM list_of_all_repos WHERE key=%s; -> repo() %s == repo.src_url
query = self.config.query
repo = Repo(src_url)
db = self.conn
await db.execute(query, (src_url,))
dump = await db.fetchone()
if dump is not None and dump[0] is not None:
repo.merge(Repo(src_url, data=json.loads(dump[0])))
return repo

async def __aenter__(self) -> "MysqlSourceContext":
self.__conn = self.parent.db.cursor(aiomysql.DictCursor)
self.conn = await self.__conn.__aenter__()
return self

async def __aexit__(self, exc_type, exc_value, traceback):
await self.__conn.__aexit__(exc_type, exc_value, traceback)
await self.parent.db.commit()


@entry_point("dffml.source")
class MysqlSource(BaseSource):

CONTEXT = MysqlSourceContext

async def __aenter__(self) -> "MysqlSource":
self.pool = await aiomysql.create_pool(
host=self.config.host,
port=self.config.port,
user=self.config.user,
password=self.config.password,
db=self.config.db,
)
self.__db = self.pool.acquire()
self.db = await self.__db.__aenter__()
return self

async def __aexit__(self, exc_type, exc_value, traceback):
await self.__db.__aexit__(exc_type, exc_value, traceback)
self.pool.close()
await self.pool.wait_closed()

@classmethod
def args(cls, args, *above) -> Dict[str, Arg]:
cls.config_set(args, above, "host", Arg(default="127.0.0.1"))
cls.config_set(args, above, "port", Arg(type=int, default=3306))
cls.config_set(args, above, "user", Arg(default="user"))
cls.config_set(args, above, "password", Arg(default="pass"))
cls.config_set(args, above, "db", Arg(default="db"))
cls.config_set(
args,
above,
"query",
Arg(
type=str,
help="For repos:"
"SELECT key as src_url, data_1 as feature_1, data_2 as feature_2 FROM list_of_all_repos, "
"For repo:"
"SELECT key as src_url, data_1 as feature_1, data_2 as feature_2 FROM list_of_all_repos WHERE key=%s -> %s = repo.src_url"
"For update:"
"INSERT INTO source_data (src_url, json) VALUES(%s, %s) ON DUPLICATE KEY UPDATE json = %s",
),
)
return args

@classmethod
def config(cls, config, *above):
return MysqlSourceConfig(
host=cls.config_get(config, above, "host"),
port=cls.config_get(config, above, "port"),
user=cls.config_get(config, above, "user"),
password=cls.config_get(config, above, "password"),
db=cls.config_get(config, above, "db"),
query=cls.config_get(config, above, "query"),
)