Skip to content

Commit 04fc067

Browse files
committed
SAMA Addition to client APIs and Updated Docs
1 parent e28e96d commit 04fc067

23 files changed

+333
-372
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ $ appknox reports create 4
133133
3
134134
135135
$ appknox reports download summary-csv 3
136-
Organization ID,Project ID,Application Name,Application Namespace,Platform,Version,Version Code,File ID,Test Case,Scan Type,Severity,Risk Override,CVSS Score,Findings,Description,Noncompliant Code Example,Compliant Solution,Business Implication,OWASP,CWE,MSTG,OWASP MASVS (v2),ASVS,PCI-DSS,GDPR,Created On
136+
Organization ID,Project ID,Application Name,Application Namespace,Platform,Version,Version Code,File ID,Test Case,Scan Type,Severity,Risk Override,CVSS Score,Findings,Description,Noncompliant Code Example,Compliant Solution,Business Implication,OWASP,CWE,MSTG,OWASP MASVS (v2),ASVS,PCI-DSS,GDPR,SAMA,Created On
137137
1,1,MFVA,com.appknox.mfva,Android,1.1,1605631525,51,Broken SSL Trust Manager,Static,High,,6.9,"BluK8lNUoeHkNxZ3GVrKN9BP2
138138
NVWmfbtHDiJBOTbOEpCnsbMhc6T31t...(Truncated)
139139

appknox/client.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from appknox.mapper import Organization
3131
from appknox.mapper import OWASP
3232
from appknox.mapper import PCIDSS
33+
from appknox.mapper import SAMA
3334
from appknox.mapper import PersonalToken
3435
from appknox.mapper import ProfileReportPreference
3536
from appknox.mapper import Project
@@ -436,6 +437,25 @@ def get_pcidss(self, pcidss_id: str) -> PCIDSS:
436437
pcidss = self.drf_api["v2/pcidsses"](pcidss_id).get()
437438
return mapper_drf_api(PCIDSS, pcidss)
438439

440+
@lru_cache(maxsize=1)
441+
def get_samas(self) -> List[SAMA]:
442+
samas_raw = self.drf_api["v2/samas"]().get()
443+
samas = self.paginated_drf_data(samas_raw, SAMA)
444+
return samas
445+
446+
def get_sama(self, sama_id: str) -> SAMA:
447+
"""
448+
Fetch SAMA by ID
449+
450+
:param sama_id: sama ID
451+
"""
452+
samas = self.get_samas()
453+
sama = next((x for x in samas if x.id == sama_id), None)
454+
if sama:
455+
return sama
456+
sama = self.drf_api["v2/samas"](sama_id).get()
457+
return mapper_drf_api(SAMA, sama)
458+
439459
def upload_file(self, file_data: str) -> int:
440460
"""
441461
Upload and scan a package and returns the file_id
@@ -542,6 +562,8 @@ def get_unselected_report_preference(self, file_id: int) -> list:
542562
unselected_report_pref.append(ReportPreferenceMapper["show_hipaa"])
543563
if not profile_report_preference.show_pcidss.value:
544564
unselected_report_pref.append(ReportPreferenceMapper["show_pcidss"])
565+
if not profile_report_preference.show_sama.value:
566+
unselected_report_pref.append(ReportPreferenceMapper["show_sama"])
545567
return unselected_report_pref
546568

547569
def list_reports(self, file_id: int) -> typing.List["Report"]:

appknox/mapper.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def mapper_drf_api(model: type, resource: dict) -> object:
6969
"masvs",
7070
"asvs",
7171
"gdpr",
72+
"sama",
7273
"computed_risk",
7374
"overridden_risk",
7475
],
@@ -93,12 +94,15 @@ def mapper_drf_api(model: type, resource: dict) -> object:
9394

9495
PCIDSS = namedtuple("PCIDSS", ["id", "code", "title", "description"])
9596

97+
SAMA = namedtuple("SAMA", ["id", "code", "title", "description"])
98+
9699
PersonalToken = namedtuple("AccessToken", ["name", "key"])
97100

98101
ReportPreferenceMapper = {
99102
"show_pcidss": "pcidss",
100103
"show_hipaa": "hipaa",
101104
"show_gdpr": "gdpr",
105+
"show_sama": "sama",
102106
}
103107

104108

@@ -112,7 +116,7 @@ class ProfileReportPreference:
112116
show_gdpr: ProfileReportPreferenceConfig
113117
show_hipaa: ProfileReportPreferenceConfig
114118
show_pcidss: ProfileReportPreferenceConfig
115-
119+
show_sama: ProfileReportPreferenceConfig
116120
@classmethod
117121
def from_json(cls, data):
118122
return cls(
@@ -121,6 +125,9 @@ def from_json(cls, data):
121125
show_pcidss=ProfileReportPreferenceConfig(
122126
value=data["show_pcidss"]["value"]
123127
),
128+
show_sama=ProfileReportPreferenceConfig(
129+
value=data["show_sama"]["value"]
130+
)
124131
)
125132

126133

@@ -146,6 +153,7 @@ class ReportPreference:
146153
"show_ignored_analyses",
147154
"show_hipaa",
148155
"show_pcidss",
156+
"show_sama",
149157
]
150158

151159
show_api_scan: bool
@@ -155,6 +163,7 @@ class ReportPreference:
155163
show_ignored_analyses: bool
156164
show_hipaa: InheritedPreference
157165
show_pcidss: InheritedPreference
166+
show_sama: InheritedPreference
158167

159168
@classmethod
160169
def from_json(cls, data: typing.Dict[str, typing.Any]) -> "ReportPreference":
@@ -166,6 +175,7 @@ def from_json(cls, data: typing.Dict[str, typing.Any]) -> "ReportPreference":
166175
show_ignored_analyses=data["show_ignored_analyses"],
167176
show_hipaa=InheritedPreference.from_json(data["show_hipaa"]),
168177
show_pcidss=InheritedPreference.from_json(data["show_pcidss"]),
178+
show_sama=InheritedPreference.from_json(data["show_sama"]),
169179
)
170180

171181

appknox/tests/test_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def setUp(self):
2525
"show_ignored_analyses": True,
2626
"show_hipaa": {"value": True, "is_inherited": True},
2727
"show_pcidss": {"value": True, "is_inherited": True},
28+
"show_sama": {"value":False, "is_inherited": False},
2829
}
2930
with mock.patch.object(Appknox, "get_organizations", self.get_org_list):
3031
self.ap_client = Appknox(

docs/.doctrees/client.doctree

2.63 KB
Binary file not shown.

docs/.doctrees/environment.pickle

16.6 KB
Binary file not shown.

docs/.doctrees/index.doctree

-4.41 KB
Binary file not shown.

docs/.doctrees/mapper.doctree

8.43 KB
Binary file not shown.

0 commit comments

Comments
 (0)