|
2 | 2 | created: '2024-12-01' |
3 | 3 | title: Connector API |
4 | 4 | weight: 50 |
5 | | -sourceSHA: 787a9663c2b07bba63b2648088abf865fb2f475cfe27d1f24fd23a68b9cca2fd |
6 | 5 | --- |
7 | 6 |
|
8 | 7 | # Connector API |
9 | 8 |
|
10 | 9 | ## Overview |
11 | 10 |
|
12 | | -After integrating access tools within the cluster, a RESTful API can be provided for the current ConnectorClass to conveniently acquire resources within the tool. These APIs will be uniformly exposed through the Connector API, allowing users to obtain resources from the tool pointed to by the current Connector. |
| 11 | +After integrating tools within the cluster, a RESTful API can be provided for the current Connector to conveniently acquire resources from the tool. These APIs are uniformly exposed through the Connector API, allowing users to obtain resources from the tool pointed to by the current Connector. |
13 | 12 |
|
14 | | -The Connectors system provides a complete set of extension mechanisms, making it easier for developers to extend the API capabilities of ConnectorClass. |
| 13 | +The Connectors system supports two ways to access tool resources through the API: |
15 | 14 |
|
16 | | -The Connectors API offers a unified request entry point. When a client initiates a resource request for the tool pointed to by a specific Connector, the system will forward the request to the corresponding API address of the ConnectorClass, which in turn will forward the request to the tool's API address to retrieve resources within the tool. |
| 15 | +- **Original Tool API**: Access the tool's original API through the Proxy Service |
| 16 | +- **Custom API**: Use a custom API provided for the ConnectorClass |
17 | 17 |
|
18 | | -For example: |
| 18 | +When using the Connectors API, clients do not need to manage the tool's original authentication credentials. They only need to have permissions to access the Connector. The permissions for API requests to the tool are determined by the permissions of the credentials (Secret) configured in the Connector. |
| 19 | + |
| 20 | +## Connector API Address and Authentication |
19 | 21 |
|
20 | | -- Retrieve the Reference list of a specific repository under the Git Connector. |
21 | | -- Retrieve the Tag list of a specific artifact repository under the OIC Connector. |
| 22 | +### API Address |
22 | 23 |
|
23 | | -## API Definition |
| 24 | +The Connector API address consists of three parts: |
24 | 25 |
|
25 | | -**API Address** |
| 26 | +- Platform API or cluster ingress access entry point |
| 27 | +- Connector API relative path |
| 28 | +- Requested tool's original API path or custom API path |
26 | 29 |
|
27 | | -`/connectors/v1alpha1/namespaces/{namespace}/connectors/{name}/resources/{resource-name}` |
| 30 | +After creating a Connector in the cluster, the Connector automatically records the current Connector's API path in `<connector>.status.api.path`. Note that this path is a relative path to the cluster access entry point. |
28 | 31 |
|
29 | | -- `namespace`: The namespace where the current Connector resides. |
30 | | -- `name`: The name of the current Connector. |
31 | | -- `resource-name`: The name of the resource being requested, which can be understood by consulting the documentation of the corresponding ConnectorClass. |
| 32 | +The final Connector API address is: `{platform_api_address}/{<connector>.status.api.path}/{api-path}` |
32 | 33 |
|
33 | | -**Authentication and Authorization** |
| 34 | +::: info |
| 35 | +In Alauda Container Platform, the API access entry point is typically `{platform_address}/clusters-rewrite/{cluster_name}`. |
| 36 | +::: |
34 | 37 |
|
35 | | -Authentication complies with Kubernetes authentication standards, completed through Kubernetes' authentication and authorization mechanisms. The requesting user must have read permissions for the corresponding `connector`. |
| 38 | +### Authentication and Authorization |
| 39 | + |
| 40 | +Authentication complies with Kubernetes authentication standards and is completed through Kubernetes' authentication and authorization mechanisms. The requesting user must have read permissions for the corresponding `Connector`. Currently, only Bearer Token authentication is supported. |
36 | 41 |
|
37 | 42 | When making the final request to the tool, the Secret information specified by the Connector will be used for authentication. |
38 | 43 |
|
39 | | -**Query Parameters** |
| 44 | +For more information about Kubernetes API authentication, refer to the [Kubernetes Authentication documentation](https://kubernetes.io/docs/reference/access-authn-authz/authentication). |
| 45 | + |
| 46 | +## Accessing Original Tool API |
| 47 | + |
| 48 | +When your ConnectorClass provides Proxy Service capabilities, you can directly access the tool's original API through the Connector API. |
| 49 | + |
| 50 | +For example, if the tool's original API address is `/api/v4/projects`, you can access it through the Connector API. Assuming you have a Connector named `gitlab-connector` in the `default` namespace, and the Connector's API path is `/connectors/v1alpha1/default/gitlab-connector/path`, the request would be: |
| 51 | + |
| 52 | +```bash |
| 53 | +K8S_TOKEN=xxxx |
| 54 | + |
| 55 | +curl -H "Authorization: Bearer ${K8S_TOKEN}" "https://platform.example.com/connectors/v1alpha1/default/gitlab-connector/path/api/v4/projects" |
| 56 | +``` |
| 57 | + |
| 58 | +The Proxy Service capabilities can be configured through the `ConnectorClass` specification. For configuration details, refer to [ConnectorClass Proxy](./connectorclass.mdx#connectorclass_proxy). For a deeper understanding of the `Connectors Proxy` concept, refer to [Connectors Proxy](./connectors_proxy.mdx). |
| 59 | + |
| 60 | +## Custom API |
| 61 | + |
| 62 | +When the tool's original API cannot meet your requirements or the ConnectorClass does not provide Proxy Service capabilities, you can provide a custom API service for the current ConnectorClass to meet your needs. |
| 63 | + |
| 64 | +The custom API service can be configured through the `spec.api` field of the ConnectorClass, allowing the Connectors system to discover and use it. For configuration details, refer to [ConnectorClass API](./connectorclass.mdx#connectorclass_api). |
| 65 | + |
| 66 | +Additionally, to enable the system to identify that the API is a custom API, you need to configure the OpenAPI description through the `spec.api.openapi` field. |
| 67 | + |
| 68 | +### API Definition |
40 | 69 |
|
41 | | -Determined by the specific ConnectorClass API. |
| 70 | +#### API Path |
42 | 71 |
|
43 | | -**Pagination Information** |
| 72 | +The API path provided by the custom API can be freely defined in the extended API service. The recommended format is `/<connectorclass-name>/xxx`. |
44 | 73 |
|
45 | | -Indicated by query parameters. |
| 74 | +Combined with the API address and authentication described above, here is a request example. Assuming you have a Connector named `git-connector` in the `default` namespace, and the custom API path is `/git/gitrefs`, the request would be: |
46 | 75 |
|
47 | | -| Parameter Name | Type | Required | Description | |
48 | | -| ------------------ | ----- | -------- | ------------ | |
49 | | -| page | int | false | Page number | |
50 | | -| itemsPerPage | int | false | Number of items per page | |
| 76 | +```bash |
| 77 | +K8S_TOKEN=xxxx |
51 | 78 |
|
52 | | -**Response Information** |
| 79 | +curl -H "Authorization: Bearer ${K8S_TOKEN}" "https://platform.example.com/connectors/v1alpha1/default/git-connector/git/gitrefs" |
| 80 | +``` |
| 81 | + |
| 82 | +#### Query Parameters |
| 83 | + |
| 84 | +Query parameters are determined by the specific [ConnectorClass API Specification](./connectorclass_api_spec.mdx). |
| 85 | + |
| 86 | +#### Pagination |
53 | 87 |
|
54 | | -When returning a list, the structure will be as follows: |
| 88 | +Pagination information is indicated by query parameters: |
55 | 89 |
|
56 | | -| Field Name | Type | Required | Description | |
57 | | -| -------------------| ---------- | -------- | ------------------------------------------ | |
58 | | -| listMeta | ListMeta | true | Metadata of the list | |
| 90 | +| Parameter Name | Type | Required | Description | |
| 91 | +| -------------- | ---- | -------- | -------------------------- | |
| 92 | +| page | int | false | Page number | |
| 93 | +| itemsPerPage | int | false | Number of items per page | |
| 94 | + |
| 95 | +#### Response Format |
| 96 | + |
| 97 | +When returning a list, the response structure is as follows: |
| 98 | + |
| 99 | +| Field Name | Type | Required | Description | |
| 100 | +| ------------------ | --------- | -------- | --------------------------------------------------------------------------- | |
| 101 | +| listMeta | ListMeta | true | Metadata of the list | |
59 | 102 | | listMeta.totalItems| int | true | Total number of requested resources, usable by the client to analyze pagination information | |
60 | | -| items | \[] | true | Data items in the list; the data structure is determined by the ConnectorClass API | |
| 103 | +| items | [] | true | Data items in the list; the data structure is determined by the ConnectorClass API | |
61 | 104 |
|
62 | 105 | ```json |
63 | 106 | { |
@@ -88,8 +131,50 @@ For example: |
88 | 131 |
|
89 | 132 | Field definitions and enumeration values are consistent with [k8s status ](https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/meta/v1#Status). |
90 | 133 |
|
91 | | -## ConnectorClass API Extension Specification |
| 134 | +### OpenAPI Description |
| 135 | + |
| 136 | +In addition to providing a custom API service, you need to configure the OpenAPI description information in the `spec.api.openapi` field of the ConnectorClass to enable the system to identify that the API is a custom API. |
| 137 | + |
| 138 | +Example: |
| 139 | + |
| 140 | +```yaml |
| 141 | +kind: ConnectorClass |
| 142 | +metadata: |
| 143 | + name: gitlab |
| 144 | +spec: |
| 145 | + api: |
| 146 | + ref: # Reference to the custom API service |
| 147 | + name: connectors-gitlab-api |
| 148 | + namespace: connectors-system |
| 149 | + openapi: |
| 150 | + openapi: "3.0.1" |
| 151 | + info: |
| 152 | + title: GitLab Custom API |
| 153 | + version: "1.0.0" |
| 154 | + paths: |
| 155 | + /gitlab/custom-api: # Custom API defined in the connectors-gitlab-api service |
| 156 | + get: |
| 157 | + x-provider-type: api # Indicates this API is a custom API |
| 158 | + summary: Request custom API |
| 159 | + responses: |
| 160 | + "200": |
| 161 | + description: Custom API response |
| 162 | +``` |
| 163 | +
|
| 164 | +The system will automatically forward the custom API to the [ConnectorClass API Address](./connectorclass.mdx#connectorclass_api_address) based on the `spec.api.openapi` description. |
| 165 | + |
| 166 | +For configuration details about `spec.api.openapi`, refer to [ConnectorClass OpenAPI Description](./connectorclass.mdx#api_openapi). For more usage examples, refer to [Using Connectors API in Dynamic Forms](#dynamic-form-using-connectors-api). |
| 167 | + |
| 168 | +### ConnectorClass API Extension Specification |
92 | 169 |
|
93 | 170 | Developers can extend the API capabilities for ConnectorClass to provide users with richer resource retrieval capabilities. |
94 | 171 |
|
95 | 172 | Refer to the [ConnectorClass API Extension Specification](./connectorclass_api_spec.mdx). |
| 173 | + |
| 174 | +## Using Connectors API in Dynamic Forms \{#dynamic-form-using-connectors-api} |
| 175 | + |
| 176 | +The Connector API can be provided to UI clients, especially for dynamic form scenarios where UI clients can flexibly configure the API requests to be called. |
| 177 | + |
| 178 | +To enable this, you need to configure the OpenAPI description information through the `spec.api.openapi` field of the ConnectorClass, which works together with the dynamic form DSL to implement frontend dynamic form rendering. |
| 179 | + |
| 180 | +The dynamic form description is typically provided in the [Resource Interface](./resource_interface.mdx). For more details, refer to [Resource Interface](./resource_interface.mdx). |
0 commit comments