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

Custom Database Tables #670

Open
wants to merge 4 commits 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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,14 @@ But sometimes, you might want to have your own sensitive keywords, then above co
SILKY_SENSITIVE_KEYS = {'custom-password'}
```

### Custom Database Tables

By default, Silk is using below-mentioned table name (they are case insensitive)

```python
SILKY_DATABASE_TABLES = {'REQUEST': 'silk_request', 'RESPONSE': 'silk_response',
'SQLQUERY': 'silk_sqlquery', 'PROFILE': 'silk_profile'}
```

### Clearing logged data

Expand Down
2 changes: 2 additions & 0 deletions project/project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,5 @@
SILKY_MAX_RECORDED_REQUESTS_CHECK_PERCENT = 0
# SILKY_AUTHENTICATION = True
# SILKY_AUTHORISATION = True
# SILKY_DATABASE_TABLES = {'REQUEST': 'test_silk_request', 'RESPONSE': 'silk_response',
# 'SQLQUERY': 'silk_sqlquery', 'PROFILE': 'silk_profile'}
4 changes: 3 additions & 1 deletion silk/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class SilkyConfig(metaclass=Singleton):
'SILKY_ANALYZE_QUERIES': False,
'SILKY_EXPLAIN_FLAGS': None,
'SILKY_SENSITIVE_KEYS': {'username', 'api', 'token', 'key', 'secret', 'password', 'signature'},
'SILKY_DELETE_PROFILES': False
'SILKY_DELETE_PROFILES': False,
'SILKY_DATABASE_TABLES': {'REQUEST': 'silk_request', 'RESPONSE': 'silk_response',
'SQLQUERY': 'silk_sqlquery', 'PROFILE': 'silk_profile'}
}

def _setup(self):
Expand Down
13 changes: 13 additions & 0 deletions silk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from silk.utils.profile_parser import parse_profile

silk_storage = get_storage_class(SilkyConfig().SILKY_STORAGE_CLASS)()
silk_db_tables = SilkyConfig().SILKY_DATABASE_TABLES


# Seperated out so can use in tests w/o models
Expand Down Expand Up @@ -190,6 +191,9 @@ def save(self, *args, **kwargs):
super().save(*args, **kwargs)
Request.garbage_collect(force=False)

class Meta:
db_table = silk_db_tables['REQUEST']


class Response(models.Model):
id = CharField(max_length=36, default=uuid4, primary_key=True)
Expand Down Expand Up @@ -218,6 +222,9 @@ def headers(self):
def raw_body_decoded(self):
return base64.b64decode(self.raw_body)

class Meta:
db_table = silk_db_tables['RESPONSE']


# TODO rewrite docstring
class SQLQueryManager(models.Manager):
Expand Down Expand Up @@ -323,6 +330,9 @@ def delete(self, *args, **kwargs):
self.request.save()
super().delete(*args, **kwargs)

class Meta:
db_table = silk_db_tables['SQLQUERY']


class BaseProfile(models.Model):
name = CharField(max_length=300, blank=True, default='')
Expand Down Expand Up @@ -364,3 +374,6 @@ def is_context_profile(self):
@property
def time_spent_on_sql_queries(self):
return sum(x.time_taken for x in self.queries.all())

class Meta:
db_table = silk_db_tables['PROFILE']
Loading