Skip to content
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 @@ -547,6 +547,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 @@ -122,3 +122,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 @@ -34,6 +34,7 @@
from django.utils.module_loading import import_string
storage_class = SilkyConfig().SILKY_STORAGE_CLASS or settings.DEFAULT_FILE_STORAGE
silk_storage = import_string(storage_class)()
silk_db_tables = SilkyConfig().SILKY_DATABASE_TABLES


# Seperated out so can use in tests w/o models
Expand Down Expand Up @@ -195,6 +196,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 @@ -223,6 +227,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 @@ -333,6 +340,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 @@ -380,3 +390,6 @@ def time_spent_on_sql_queries(self):
total_time=Sum('time_taken', output_field=FloatField())
)
return result['total_time'] or 0.0

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