Skip to content

Commit

Permalink
wca: allow AAP user without organization_id
Browse files Browse the repository at this point in the history
  • Loading branch information
goneri committed May 29, 2024
1 parent a5bfa68 commit 40af362
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
37 changes: 25 additions & 12 deletions ansible_wisdom/ai/api/model_client/tests/test_wca_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,35 +240,48 @@ def test_fatal_exception(self):
b = WCAClient.fatal_exception(exc)
self.assertTrue(b)

def test_playbook_gen(self):

@override_settings(WCA_SECRET_BACKEND_TYPE='dummy')
@override_settings(ANSIBLE_AI_MODEL_MESH_API_KEY=None)
@override_settings(ANSIBLE_AI_MODEL_MESH_MODEL_NAME=None)
class TestWCAClientExpGen(WisdomAppsBackendMocking, WisdomServiceLogAwareTestCase):
def setUp(self):
super().setUp()
wca_client = WCAClient(inference_url='http://example.com/')
wca_client.get_api_key = Mock(return_value="some-key")
wca_client.get_token = Mock(return_value={"access_token": "a-token"})
wca_client.get_model_id = Mock(return_value="a-random-model")
wca_client.session = Mock()
response = Mock
response.text = '{"playbook": "Oh!", "outline": "Ahh!"}'
response.text = '{"playbook": "Oh!", "outline": "Ahh!", "explanation": "!Óh¡"}'
wca_client.session.post.return_value = response
self.wca_client = wca_client

def test_playbook_gen(self):
request = Mock()
playbook, outline = wca_client.generate_playbook(
playbook, outline = self.wca_client.generate_playbook(
request, text="Install Wordpress", create_outline=True
)
self.assertEqual(playbook, "Oh!")
self.assertEqual(outline, "Ahh!")

def test_playbook_exp(self):
wca_client = WCAClient(inference_url='http://example.com/')
wca_client.get_api_key = Mock(return_value="some-key")
wca_client.get_token = Mock(return_value={"access_token": "a-token"})
wca_client.get_model_id = Mock(return_value="a-random-model")
wca_client.session = Mock()
response = Mock
response.text = '{"explanation": "!Óh¡"}'
wca_client.session.post.return_value = response
request = Mock()
explanation = wca_client.explain_playbook(request, content="Some playbook")
explanation = self.wca_client.explain_playbook(request, content="Some playbook")
self.assertEqual(explanation, "!Óh¡")

def test_playbook_gen_no_org(self):
request = Mock()
request.user.organization = None
self.wca_client.generate_playbook(request, text="Install Wordpress")
self.wca_client.get_api_key.assert_called_with(None)

def test_playbook_exp_no_org(self):
request = Mock()
request.user.organization = None
self.wca_client.explain_playbook(request, content="Some playbook")
self.wca_client.get_api_key.assert_called_with(None)


@override_settings(ANSIBLE_WCA_RETRY_COUNT=1)
@override_settings(WCA_SECRET_BACKEND_TYPE="dummy")
Expand Down
10 changes: 6 additions & 4 deletions ansible_wisdom/ai/api/model_client/wca_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,9 @@ def self_test(self) -> HealthCheckSummary:
def generate_playbook(
self, request, text: str = "", create_outline: bool = False, outline: str = ""
) -> tuple[str, str]:
api_key = self.get_api_key(request.user.organization.id)
model_id = self.get_model_id(request.user.organization.id)
organization_id = request.user.organization.id if request.user.organization else None
api_key = self.get_api_key(organization_id)
model_id = self.get_model_id(organization_id)

headers = self._get_base_headers(api_key)
data = {
Expand All @@ -493,8 +494,9 @@ def generate_playbook(
return response["playbook"], response["outline"]

def explain_playbook(self, request, content: str) -> str:
api_key = self.get_api_key(request.user.organization.id)
model_id = self.get_model_id(request.user.organization.id)
organization_id = request.user.organization.id if request.user.organization else None
api_key = self.get_api_key(organization_id)
model_id = self.get_model_id(organization_id)

headers = self._get_base_headers(api_key)
data = {
Expand Down

1 comment on commit 40af362

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ClamAV Virus Definition DB Files:
----
total 228984
-rw-r--r--  1 root root        28 May 29 06:07 whitelist.ign2
-rw-r--r--  1 root root 170479789 May 29 06:08 main.cvd
-rw-r--r--  1 root root        69 May 29 06:08 freshclam.dat
-rw-r--r--  1 root root  63688581 May 29 06:08 daily.cvd
-rw-r--r--  1 root root    289733 May 29 06:08 bytecode.cvd
drwxr-xr-x 16 root root      4096 May 29 14:24 ..
drwxr-xr-x  2 root root      4096 May 29 14:24 .
----
File: /var/lib/clamav/bytecode.cvd
Build time: 27 Feb 2024 10:37 -0500
Version: 335
Signatures: 86
Functionality level: 90
Builder: raynman
MD5: 16d388f042f5c44628a66228df427c20
Digital signature: 7fD3mweaw4tqQH9Dl7ZewBLXZBSrLKX5no/rYN/6NQBmhnWUyTBt3uzd7ZjEnIT5yN1ygLwsDcuzoKRoA+syrfk3PcDHf5/h6Wb/d8uikXSALygH5VYAPo2ksV5Pitn3reECJ90q2m9m0CH2VpT1tDkkcVi05LLV5PwBle2Ufpe
Verification OK.
----
File: /var/lib/clamav/daily.cvd
Build time: 28 May 2024 04:30 -0400
Version: 27289
Signatures: 2061864
Functionality level: 90
Builder: raynman
MD5: 2e0d9e27206996cc72e59f3d2d112b87
Digital signature: +kgsnYvGDO5ZyqXMVLQ3IV9p9QwbXzP2/YfvXZHy9TdrL0XbheAZe4wa5/5pT2DFJtFFCqvVuRuBAtbkIQGE46ZaG1lJSCph3Vw5Tsyyn6T8kWznYWD951Rvh6PDsicJ52KHlhjsNJ5//AJ6fhIaQw8WcdeyrIxJgAO0F8uC4fh
Verification OK.
----
File: /var/lib/clamav/main.cvd
Build time: 16 Sep 2021 08:32 -0400
Version: 62
Signatures: 6647427
Functionality level: 90
Builder: sigmgr
MD5: 137eccce31aacb21b5a98bb8c21cefd6
Digital signature: twaJBls8V5q64R7QY10AatEtPNuPWoVoxTaNO1jpBg7s5jIMMXpitgG1000YLp6rb0TWkEKjRqxneGTxuxWaWm7XBjsgwX2BRWh/y4fhs7uyImdKRLzQ5y8e2EkSChegF/i8clqfn+1qetq9j4gbktJ3JZpOXPoHlyr2Dv9S/Bg
Verification OK.
----
Scanning Results:
ClamAV 1.0.6/27289/Tue May 28 08:30:59 2024
LibClamAV Warning: Max file-size was set to 4194304000 bytes. Unfortunately, scanning files greater than 2147483647 bytes (2 GiB - 1) is not supported.

----------- SCAN SUMMARY -----------
Known viruses: 8693691
Engine version: 1.0.6
Scanned directories: 31444
Scanned files: 194336
Infected files: 0
Data scanned: 6681.91 MB
Data read: 3469.70 MB (ratio 1.93:1)
Time: 1549.186 sec (25 m 49 s)
Start Date: 2024:05:29 14:26:00
End Date:   2024:05:29 14:51:49

Please sign in to comment.