|
| 1 | +###################################################################### |
| 2 | +# @author : bidaya0 (bidaya0@$HOSTNAME) |
| 3 | +# @file : api_route |
| 4 | +# @created : Tuesday Aug 17, 2021 17:43:27 CST |
| 5 | +# |
| 6 | +# @description : |
| 7 | +###################################################################### |
| 8 | + |
| 9 | +from django.db import models |
| 10 | +from dongtai.utils.settings import get_managed |
| 11 | +from dongtai.models.agent import IastAgent |
| 12 | + |
| 13 | + |
| 14 | +class HttpMethod(models.Model): |
| 15 | + method = models.CharField(max_length=100, blank=True) |
| 16 | + |
| 17 | + class Meta: |
| 18 | + managed = get_managed() |
| 19 | + db_table = 'iast_http_method' |
| 20 | + |
| 21 | + |
| 22 | +class IastApiMethod(models.Model): |
| 23 | + method = models.CharField(max_length=100, blank=True) |
| 24 | + http_method = models.ManyToManyField( |
| 25 | + HttpMethod, blank=True, through='IastApiMethodHttpMethodRelation') |
| 26 | + |
| 27 | + class Meta: |
| 28 | + managed = get_managed() |
| 29 | + db_table = 'iast_api_methods' |
| 30 | + |
| 31 | + |
| 32 | +class IastApiMethodHttpMethodRelation(models.Model): |
| 33 | + api_method = models.ForeignKey(IastApiMethod, |
| 34 | + on_delete=models.CASCADE, |
| 35 | + db_constraint=False, |
| 36 | + db_column='api_method_id') |
| 37 | + http_method = models.ForeignKey(HttpMethod, |
| 38 | + on_delete=models.CASCADE, |
| 39 | + db_constraint=False, |
| 40 | + db_column='http_method_id') |
| 41 | + |
| 42 | + class Meta: |
| 43 | + managed = get_managed() |
| 44 | + db_table = 'iast_http_method_relation' |
| 45 | + unique_together = ['api_method_id', 'http_method_id'] |
| 46 | + |
| 47 | + |
| 48 | +class IastApiRoute(models.Model): |
| 49 | + path = models.CharField(max_length=255, blank=True) |
| 50 | + code_class = models.CharField(max_length=255, |
| 51 | + blank=True, |
| 52 | + db_column='code_class') |
| 53 | + description = models.CharField(max_length=500, blank=True) |
| 54 | + method = models.ForeignKey(IastApiMethod, |
| 55 | + on_delete=models.DO_NOTHING, |
| 56 | + db_constraint=False, |
| 57 | + db_index=True, |
| 58 | + db_column='method_id') |
| 59 | + code_file = models.CharField(max_length=500, |
| 60 | + blank=True, |
| 61 | + db_column='code_file') |
| 62 | + controller = models.CharField(max_length=100, blank=True) |
| 63 | + agent = models.ForeignKey(IastAgent, |
| 64 | + on_delete=models.CASCADE, |
| 65 | + db_constraint=False, |
| 66 | + db_index=True, |
| 67 | + db_column='agent_id') |
| 68 | + |
| 69 | + class Meta: |
| 70 | + managed = get_managed() |
| 71 | + db_table = 'iast_api_route' |
| 72 | + unique_together = ['path', 'method'] |
| 73 | + |
| 74 | + |
| 75 | +class IastApiParameter(models.Model): |
| 76 | + name = models.CharField(max_length=100, blank=True) |
| 77 | + parameter_type = models.CharField(max_length=100, |
| 78 | + blank=True, |
| 79 | + db_column='type') |
| 80 | + annotation = models.CharField(max_length=500, blank=True) |
| 81 | + route = models.ForeignKey(IastApiRoute, |
| 82 | + on_delete=models.CASCADE, |
| 83 | + db_constraint=False, |
| 84 | + db_index=True, |
| 85 | + db_column='route_id') |
| 86 | + |
| 87 | + class Meta: |
| 88 | + managed = get_managed() |
| 89 | + db_table = 'iast_api_parameter' |
| 90 | + unique_together = ['name', 'route_id'] |
| 91 | + |
| 92 | + |
| 93 | +class IastApiResponse(models.Model): |
| 94 | + return_type = models.CharField(max_length=100, blank=True) |
| 95 | + route = models.ForeignKey(IastApiRoute, |
| 96 | + on_delete=models.CASCADE, |
| 97 | + db_constraint=False, |
| 98 | + db_index=True, |
| 99 | + db_column='route_id') |
| 100 | + |
| 101 | + class Meta: |
| 102 | + managed = get_managed() |
| 103 | + db_table = 'iast_api_response' |
| 104 | + unique_together = ['return_type', 'route_id'] |
0 commit comments