Skip to content

Commit 16a181d

Browse files
authored
feat(apps): Add Generate App Manifest functionality (#244)
* fix(networking): Update entities _get_url_filtered function fix(networking): Update _append_encoded_parameter function to append the parameters with the %s=%s format, in order to be compliant with the Policy Server API interface * feat(apps): Add function for the /v3/apps/:guid/manifest endpoint * test: Add test for the v3 apps get_manifest function * test: Fix formatting of statements in test_get_manifest function
1 parent 822f185 commit 16a181d

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

cloudfoundry_client/networking/entities.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ def _append_encoded_parameter(parameters: List[str], args: Tuple[str, Any]) -> L
116116
for value in value_list:
117117
parameters.append("%s=%s" % (parameter_name, str(value)))
118118
elif isinstance(parameter_value, (list, tuple)):
119-
parameters.append("q=%s" % quote("%s IN %s" % (parameter_name, ",".join(parameter_value))))
119+
parameters.append("%s=%s" % (parameter_name, quote(",".join(parameter_value))))
120120
else:
121-
parameters.append("q=%s" % quote("%s:%s" % (parameter_name, str(parameter_value))))
121+
parameters.append("%s=%s" % (parameter_name, quote(str(parameter_value))))
122122
return parameters
123123

124124
if len(kwargs) > 0:

cloudfoundry_client/v3/apps.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ def get_env(self, application_guid: str) -> JsonObject:
2424

2525
def get_routes(self, application_guid: str) -> JsonObject:
2626
return super(AppManager, self)._get("%s%s/%s/routes" % (self.target_endpoint, self.entity_uri, application_guid))
27+
28+
def get_manifest(self, application_guid: str) -> str:
29+
return self.client.get(url="%s%s/%s/manifest" % (self.target_endpoint, self.entity_uri, application_guid)).text
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
applications:
3+
- name: my-app
4+
stack: cflinuxfs4
5+
features:
6+
ssh: true
7+
revisions: true
8+
service-binding-k8s: false
9+
file-based-vcap-services: false
10+
services:
11+
- my-service
12+
routes:
13+
- route: my-app.example.com
14+
protocol: http1
15+
processes:
16+
- type: web
17+
instances: 2
18+
memory: 512M
19+
log-rate-limit-per-second: 1KB
20+
disk_quota: 1024M
21+
health-check-type: http
22+
health-check-http-endpoint: /healthy
23+
health-check-invocation-timeout: 10
24+
health-check-interval: 5
25+
readiness-health-check-type: http
26+
readiness-health-check-http-endpoint: /ready
27+
readiness-health-check-invocation-timeout: 20
28+
readiness-health-check-interval: 5

tests/v3/test_apps.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import unittest
2+
import yaml
23
from http import HTTPStatus
4+
from typing import Optional, List, Union
35

46
from abstract_test_case import AbstractTestCase
57
from cloudfoundry_client.common_objects import JsonObject
@@ -132,3 +134,29 @@ def test_list_include_space(self):
132134
self.assertIsInstance(all_spaces[0], Entity)
133135
self.assertEqual(all_spaces[1]["name"], "my_space")
134136
self.assertIsInstance(all_spaces[1], Entity)
137+
138+
def test_get_manifest(self):
139+
self.client.get.return_value = self.mock_response(
140+
"/v3/apps/app_id/manifest", HTTPStatus.OK, {"Content-Type": "application/x-yaml"}, "v3", "apps",
141+
"GET_{id}_manifest_response.yml"
142+
)
143+
manifest_response: str = self.client.v3.apps.get_manifest("app_id")
144+
self.assertIsInstance(manifest_response, str)
145+
manifest: dict = yaml.safe_load(manifest_response)
146+
applications: Optional[list[dict]] = manifest.get("applications")
147+
self.assertIsInstance(applications, list)
148+
self.assertEqual(len(applications), 1)
149+
application: dict = applications[0]
150+
self.assertEqual(application.get("name"), "my-app")
151+
self.assertEqual(application.get("stack"), "cflinuxfs4")
152+
application_services: Optional[list[str]] = application.get("services")
153+
self.assertIsInstance(application_services, list)
154+
self.assertEqual(len(application_services), 1)
155+
self.assertEqual(application_services[0], "my-service")
156+
application_routes: Optional[List[Union[dict, str]]] = application.get("routes")
157+
self.assertIsInstance(application_routes, list)
158+
self.assertEqual(len(application_routes), 1)
159+
application_route: dict = application_routes[0]
160+
self.assertIsInstance(application_route, dict)
161+
self.assertEqual(application_route.get("route"), "my-app.example.com")
162+
self.assertEqual(application_route.get("protocol"), "http1")

0 commit comments

Comments
 (0)