Skip to content

Commit 74409ff

Browse files
authored
Merge pull request #17 from swaroopar/feature/addClientGenerator
add xpanse client generation
2 parents 8ace5df + 8bf196e commit 74409ff

File tree

15 files changed

+942
-40
lines changed

15 files changed

+942
-40
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,11 @@ Use "xpanse-agent [command] --help" for more information about a command.
4141
4242
All arguments can also be read from environment variables.
4343
Variables in environment variables must be all in uppercase and
44-
must be prefixed with `XPANSE_AGENT_`.
44+
must be prefixed with `XPANSE_AGENT_`.
45+
46+
## Generate Client
47+
48+
To generate xpanse API client, copy the xpanse openapi JSON file to `clientgen` folder.
49+
50+
After that execute the [generate.go](clientgen/generate.go) file to generate the new client file.
51+
This will replace the existing [client go file](pkg/xpanseclient/xpanseclient.go).

clientgen/api.json

Lines changed: 297 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,297 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "XpanseAPI",
5+
"description": "RESTful Services to interact with Xpanse runtime.",
6+
"version": "1.0.20-SNAPSHOT"
7+
},
8+
"servers": [
9+
{
10+
"url": "http://localhost:8080",
11+
"description": "Generated server url"
12+
}
13+
],
14+
"tags": [
15+
{
16+
"name": "Agent Api",
17+
"description": "APIs for agent to poll pending configuration change requests."
18+
}
19+
],
20+
"paths": {
21+
"/xpanse/agent/poll/{serviceId}/{resourceName}": {
22+
"get": {
23+
"tags": [
24+
"Agent Api"
25+
],
26+
"description": "Get pending configuration change request for agents to poll.",
27+
"operationId": "getPendingConfigurationChangeRequest",
28+
"parameters": [
29+
{
30+
"name": "serviceId",
31+
"in": "path",
32+
"description": "The id of the deployed service",
33+
"required": true,
34+
"schema": {
35+
"type": "string"
36+
}
37+
},
38+
{
39+
"name": "resourceName",
40+
"in": "path",
41+
"description": "The name of the resource of deployed service",
42+
"required": true,
43+
"schema": {
44+
"type": "string"
45+
}
46+
}
47+
],
48+
"responses": {
49+
"500": {
50+
"description": "Internal Server Error",
51+
"content": {
52+
"application/json": {
53+
"schema": {
54+
"$ref": "#/components/schemas/Response"
55+
}
56+
}
57+
}
58+
},
59+
"422": {
60+
"description": "Unprocessable Entity",
61+
"content": {
62+
"application/json": {
63+
"schema": {
64+
"$ref": "#/components/schemas/Response"
65+
}
66+
}
67+
}
68+
},
69+
"400": {
70+
"description": "Bad Request",
71+
"content": {
72+
"application/json": {
73+
"schema": {
74+
"$ref": "#/components/schemas/Response"
75+
}
76+
}
77+
}
78+
},
79+
"403": {
80+
"description": "Forbidden",
81+
"content": {
82+
"application/json": {
83+
"schema": {
84+
"$ref": "#/components/schemas/Response"
85+
}
86+
}
87+
}
88+
},
89+
"401": {
90+
"description": "Unauthorized",
91+
"content": {
92+
"application/json": {
93+
"schema": {
94+
"$ref": "#/components/schemas/Response"
95+
}
96+
}
97+
}
98+
},
99+
"502": {
100+
"description": "Bad Gateway",
101+
"content": {
102+
"application/json": {
103+
"schema": {
104+
"$ref": "#/components/schemas/Response"
105+
}
106+
}
107+
}
108+
},
109+
"408": {
110+
"description": "Request Timeout",
111+
"content": {
112+
"application/json": {
113+
"schema": {
114+
"$ref": "#/components/schemas/Response"
115+
}
116+
}
117+
}
118+
},
119+
"200": {
120+
"description": "OK",
121+
"content": {
122+
"application/json": {
123+
"schema": {
124+
"$ref": "#/components/schemas/ServiceConfigurationChangeRequest"
125+
}
126+
}
127+
}
128+
}
129+
}
130+
}
131+
}
132+
},
133+
"components": {
134+
"schemas": {
135+
"Response": {
136+
"required": [
137+
"details",
138+
"resultType",
139+
"success"
140+
],
141+
"type": "object",
142+
"properties": {
143+
"resultType": {
144+
"type": "string",
145+
"description": "The result code of response.",
146+
"enum": [
147+
"Success",
148+
"Runtime Error",
149+
"Parameters Invalid",
150+
"Terraform Script Invalid",
151+
"Unprocessable Entity",
152+
"Response Not Valid",
153+
"Failure while connecting to backend",
154+
"Credential Capability Not Found",
155+
"Credentials Not Found",
156+
"Credential Variables Not Complete",
157+
"Flavor Invalid",
158+
"Terraform Execution Failed",
159+
"Plugin Not Found",
160+
"Deployer Not Found",
161+
"No Credential Definition Available",
162+
"Invalid Service State",
163+
"Resource Invalid For Monitoring",
164+
"Unhandled Exception",
165+
"Service Template Already Registered",
166+
"Icon Processing Failed",
167+
"Service Template Not Registered",
168+
"Service Template Not Approved",
169+
"Service Template Already Reviewed",
170+
"Invalid Service Version",
171+
"Invalid Service Flavors",
172+
"Invalid Billing Config",
173+
"Unavailable Service Regions",
174+
"Service Deployment Not Found",
175+
"Resource Not Found",
176+
"Deployment Variable Invalid",
177+
"Service Template Update Not Allowed",
178+
"Service Template Still In Use",
179+
"Unauthorized",
180+
"Access Denied",
181+
"Sensitive Field Encryption Or Decryption Failed Exception",
182+
"Unsupported Enum Value",
183+
"Terraform Boot Request Failed",
184+
"Tofu Maker Request Failed",
185+
"Metrics Data Not Ready",
186+
"Variable Validation Failed",
187+
"Variable Schema Definition Invalid",
188+
"Policy Not Found",
189+
"Duplicate Policy",
190+
"Policy Validation Failed",
191+
"Policy Evaluation Failed",
192+
"Current Login User No Found",
193+
"Service Details No Accessible",
194+
"Migrating activiti Task Not Found",
195+
"Service Migration Failed Exception",
196+
"Service Migration Not Found",
197+
"Service Locked",
198+
"Eula Not Accepted",
199+
"Service Flavor Downgrade Not Allowed",
200+
"Billing Mode Not Supported",
201+
"Service State Management Task Not Found",
202+
"Service Order Not Found",
203+
"Service Price Calculation Failed",
204+
"Invalid Git Repo Details",
205+
"File Locked",
206+
"Service Configuration Invalid"
207+
]
208+
},
209+
"details": {
210+
"type": "array",
211+
"description": "Details of the errors occurred",
212+
"items": {
213+
"type": "string",
214+
"description": "Details of the errors occurred"
215+
}
216+
},
217+
"success": {
218+
"type": "boolean",
219+
"description": "Describes if the request is successful"
220+
}
221+
}
222+
},
223+
"AnsibleScriptConfig": {
224+
"required": [
225+
"branch",
226+
"galaxyFile",
227+
"isPrepareAnsibleEnvironment",
228+
"playbookName",
229+
"pythonVersion",
230+
"repoUrl",
231+
"requirementsFile",
232+
"virtualEnv"
233+
],
234+
"type": "object",
235+
"properties": {
236+
"playbookName": {
237+
"type": "string",
238+
"description": "name of the ansible playbook. Should be the fully qualified file name (including the directory path) in the repo.Eg.,'playbook-name.yml'"
239+
},
240+
"virtualEnv": {
241+
"type": "string",
242+
"description": "Path where the virtualenv is created."
243+
},
244+
"pythonVersion": {
245+
"type": "number",
246+
"description": "Version of the python. This version of python must be available in node which is acting as the configManager.",
247+
"format": "float"
248+
},
249+
"isPrepareAnsibleEnvironment": {
250+
"type": "boolean",
251+
"description": "The agent will prepare the virtual environment if this true.Otherwise it is assumed that the environment is already prepared as part of the resource creation."
252+
},
253+
"repoUrl": {
254+
"type": "string",
255+
"description": "Url of the script repo."
256+
},
257+
"branch": {
258+
"type": "string",
259+
"description": "Branch of the git repo."
260+
},
261+
"requirementsFile": {
262+
"type": "string",
263+
"description": "the python module requirements file in GIT repo. Should be the fully qualified file name (including the directory path). E.g modules/requirements.txt"
264+
},
265+
"galaxyFile": {
266+
"type": "string",
267+
"description": "Full path of the roles and collections requirements file in GIT repo."
268+
},
269+
"ansibleInventoryRequired": {
270+
"type": "boolean",
271+
"description": "Defines if the complete service inventory is necessary for running the ansible job."
272+
}
273+
}
274+
},
275+
"ServiceConfigurationChangeRequest": {
276+
"type": "object",
277+
"properties": {
278+
"orderId": {
279+
"type": "string",
280+
"format": "uuid"
281+
},
282+
"configParameters": {
283+
"type": "object",
284+
"additionalProperties": true
285+
},
286+
"ansibleScriptConfig": {
287+
"$ref": "#/components/schemas/AnsibleScriptConfig"
288+
},
289+
"ansibleInventory": {
290+
"type": "object",
291+
"additionalProperties": true
292+
}
293+
}
294+
}
295+
}
296+
}
297+
}

clientgen/cfg.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package: xpanseclient
2+
output: ../pkg/xpanseclient/xpanseclient.go
3+
generate:
4+
models: true
5+
client: true

clientgen/generate.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* SPDX-FileCopyrightText: Huawei Inc.
4+
*/
5+
6+
package clientgen
7+
8+
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen -config cfg.yml api.json

go.mod

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/apenella/go-ansible/v2 v2.0.1
77
github.com/go-co-op/gocron/v2 v2.12.0
88
github.com/go-git/go-git/v5 v5.12.0
9+
github.com/oapi-codegen/runtime v1.1.1
910
github.com/spf13/cobra v1.8.1
1011
github.com/spf13/viper v1.19.0
1112
github.com/stretchr/testify v1.9.0
@@ -15,29 +16,40 @@ require (
1516
dario.cat/mergo v1.0.0 // indirect
1617
github.com/Microsoft/go-winio v0.6.1 // indirect
1718
github.com/ProtonMail/go-crypto v1.0.0 // indirect
19+
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
1820
github.com/apenella/go-common-utils/data v0.0.0-20220913191136-86daaa87e7df // indirect
1921
github.com/apenella/go-common-utils/error v0.0.0-20220913191136-86daaa87e7df // indirect
2022
github.com/cloudflare/circl v1.3.7 // indirect
2123
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
2224
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
2325
github.com/emirpasic/gods v1.18.1 // indirect
2426
github.com/fsnotify/fsnotify v1.7.0 // indirect
27+
github.com/getkin/kin-openapi v0.124.0 // indirect
2528
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
2629
github.com/go-git/go-billy/v5 v5.5.0 // indirect
30+
github.com/go-openapi/jsonpointer v0.20.2 // indirect
31+
github.com/go-openapi/swag v0.22.8 // indirect
2732
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
2833
github.com/google/uuid v1.6.0 // indirect
2934
github.com/hashicorp/hcl v1.0.0 // indirect
3035
github.com/inconshreveable/mousetrap v1.1.0 // indirect
36+
github.com/invopop/yaml v0.2.0 // indirect
3137
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
3238
github.com/jonboulle/clockwork v0.4.0 // indirect
39+
github.com/josharian/intern v1.0.0 // indirect
3340
github.com/kevinburke/ssh_config v1.2.0 // indirect
3441
github.com/magiconair/properties v1.8.7 // indirect
42+
github.com/mailru/easyjson v0.7.7 // indirect
3543
github.com/mitchellh/mapstructure v1.5.0 // indirect
44+
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
45+
github.com/oapi-codegen/oapi-codegen/v2 v2.3.0 // indirect
3646
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
47+
github.com/perimeterx/marshmallow v1.1.5 // indirect
3748
github.com/pjbgf/sha1cd v0.3.0 // indirect
3849
github.com/pkg/errors v0.9.1 // indirect
3950
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
4051
github.com/robfig/cron/v3 v3.0.1 // indirect
52+
github.com/rogpeppe/go-internal v1.12.0 // indirect
4153
github.com/sagikazarmark/locafero v0.4.0 // indirect
4254
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
4355
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect

0 commit comments

Comments
 (0)