VelaUX OpenAPI

This section will introduce how to integrate VelaUX OpenAPI, please make sure you have enabled the velaux addon. Let’s use port-forward to expose the endpoint for the following demo.

  1. vela port-forward addon-velaux -n vela-system 8000:80

VelaUX has introduced Json Web Token for authorization. As a result, you need to call the login API to complete the authentication and get the token. The following example is with the default admin account.

  1. curl -H Content-Type:application/json -X POST -d '{"username": "admin", "password":"VelaUX12345"}' http://127.0.0.1:8000/api/v1/auth/login

http://127.0.0.1:8000 This is demo address, you should replace it with the real address. If you changed the password, replace it with the real password.

The expected output should be like this:

  1. {
  2. "user": {
  3. "createTime": "0001-01-01T00:00:00Z",
  4. "lastLoginTime": "0001-01-01T00:00:00Z",
  5. "name": "admin",
  6. "email": "barnett.zqg@gmail.com",
  7. "disabled": false
  8. },
  9. "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiZ3JhbnRUeXBlIjoiYWNjZXNzIiwiZXhwIjoxNjU2NTE0ODcyLCJpc3MiOiJ2ZWxhLWlzc3VlciIsIm5iZiI6MTY1NjUxMTI3Mn0.IqRWglW5cYMn8KJcbkoG55os9g-YTo_9UWFvbpZBKiY",
  10. "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiZ3JhbnRUeXBlIjoicmVmcmVzaCIsImV4cCI6MTY1NjU5NzY3MiwiaXNzIjoidmVsYS1pc3N1ZXIiLCJuYmYiOjE2NTY1MTEyNzJ9.mUjXj1BQ2c3MaVyYnMYefgH2g8Y-swgjyCAzH-GbZu8"
  11. }
  • accessToken: This is the token to request other APIs, which will expire in an hour.
  • refreshToken: This is the token to refresh the access token.

  • Create an application

  1. curl -H Content-Type:application/json -H "Authorization: Bearer <accessToken>" -X POST -d '{"name":"first-vela-app", "project": "default", "alias": "Demo App", "envBinding": [{"name": "default"}], "component": {"name":"express-server","componentType":"webservice", "properties": "{\"image\":\"oamdev/hello-world\"}"}}' http://127.0.0.1:8000/api/v1/applications

Please replace <accessToken> with the response from the previous step.

The expected output should be like this:

  1. {
  2. "name": "first-vela-app",
  3. "alias": "Demo App",
  4. "project": {
  5. "name": "default",
  6. "alias": "Default",
  7. "description": "Default project is created by velaux system automatically.",
  8. "createTime": "2022-06-24T14:41:42.237565+08:00",
  9. "updateTime": "2022-06-24T14:41:42.237565+08:00",
  10. "owner": {
  11. "name": "admin",
  12. "alias": "Administrator"
  13. }
  14. },
  15. "description": "",
  16. "createTime": "2022-06-29T22:18:53.699216+08:00",
  17. "updateTime": "2022-06-29T22:18:53.699217+08:00",
  18. "icon": ""
  19. }
  • Deploy an application
  1. curl -H Content-Type:application/json -H "Authorization: Bearer <accessToken>" -X POST -d '{"workflowName":"workflow-default","triggerType":"api"}' http://127.0.0.1:8000/api/v1/applications/first-vela-app/deploy

The expected output should be like this:

  1. {
  2. "createTime": "2022-06-29T22:24:25.735085+08:00",
  3. "version": "20220629222425586",
  4. "status": "running",
  5. "deployUser": {
  6. "name": "admin",
  7. "alias": "Administrator"
  8. },
  9. "note": "",
  10. "envName": "default",
  11. "triggerType": "api"
  12. }
  • Using VelaQL to Query the application pod list
  1. curl -H "Authorization: Bearer <accessToken>" -G \
  2. "http://127.0.0.1:8000/api/v1/query" \
  3. --data-urlencode 'velaql=component-pod-view{appNs=default,appName=first-vela-app}.status'

The expected output should be like this:

  1. {
  2. "podList": [
  3. {
  4. "cluster": "local",
  5. "component": "express-server",
  6. "metadata": {
  7. "creationTime": "2022-06-29T14:24:26Z",
  8. "name": "express-server-6f58ff895b-4gqvs",
  9. "namespace": "default",
  10. "version": {
  11. "deployVersion": "20220629222425586",
  12. "publishVersion": "workflow-default-20220629222425602"
  13. }
  14. },
  15. "status": {
  16. "hostIP": "172.18.0.2",
  17. "nodeName": "cloudshell-control-plane",
  18. "phase": "Running",
  19. "podIP": "10.244.0.25"
  20. },
  21. "workload": {
  22. "apiVersion": "apps/v1",
  23. "kind": "Deployment",
  24. "name": "express-server",
  25. "namespace": "default"
  26. }
  27. }
  28. ]
  29. }

For more use cases about VelaQL, Please refer to VelaQL

  1. curl -H Content-Type:application/json -X GET -H RefreshToken:<refreshToken> http://127.0.0.1:8000/api/v1/auth/refresh_token

The expected output should be like this:

  1. {
  2. "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiZ3JhbnRUeXBlIjoiYWNjZXNzIiwiZXhwIjoxNjU2NTE2OTExLCJpc3MiOiJ2ZWxhLWlzc3VlciIsIm5iZiI6MTY1NjUxMzMxMX0.zsUW_ME5mxTQxP-UFxQa4F8QDI-69RWpcfIFkn_WFSg",
  3. "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiZ3JhbnRUeXBlIjoicmVmcmVzaCIsImV4cCI6MTY1NjU5NzY3MiwiaXNzIjoidmVsYS1pc3N1ZXIiLCJuYmYiOjE2NTY1MTEyNzJ9.mUjXj1BQ2c3MaVyYnMYefgH2g8Y-swgjyCAzH-GbZu8"
  4. }

There is the latest swagger config file: https://github.com/kubevela/kubevela/blob/master/docs/apidoc/swagger.json

Refer to Kubevela API 1.7

Refer to KubeVela API 1.6

Refer to KubeVela API 1.5

Refer to Kubevela API 1.4

Refer to Kubevela API 1.3

Last updated on Aug 4, 2023 by Daniel Higuero