Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Don't merge] Add component yaml configuration definition with connection env renaming guide #1684

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,29 @@ Click the respective tab to view the structure for your current configuration fi
# The path should be relative to the docker context.
schemaFilePath: openapi.yaml

# +optional Outgoing connection details for the component.
dependencies:
# +optional Defines the connection references from the Internal Marketplace.
connectionReferences:
# +required Name of the connection.
- name: hr-connection
# +required service identifer of the dependent component.
resourceRef: service:/HRProject/UserComponent/v1/ad088/PUBLIC

# +optional Outgoing connection details for the component.
dependencies:
# +optional Defines the connection references from the Internal Marketplace.
connectionReferences:
# +required Name of the connection.
- name: hr-connection
# +required service identifer of the dependent component.
resourceRef: service:/HRProject/UserComponent/v1/ad088/PUBLIC
# +optional Defines runtime configurations
configuration:
# +optional List of environment variables to be injected into the component.
env:
# +required Name of the environment variable
- name: HR_SERVICE_URL
# +required value source
# Allowed value sources: connectionRef
valueFrom:
# +required Choreo connection value source
connectionRef:
# +required Choreo connection name to refer the value from
name: hr-connection
# +required Choreo connection configuration key to refer the value from
key: ServiceURL
```

The descriptor-based approach of the `component.yaml` file simplifies and streamlines endpoint and connection configuration management. The use of versioned schemas ensures backward compatibility, providing a seamless transition with future updates.
Expand All @@ -79,6 +93,7 @@ Click the respective tab to view the structure for your current configuration fi
| **schemaVersion** | Required | The version of the `component.yaml` file. Defaults to the latest version.|
| **endpoints** | Optional | The list of endpoint configurations. |
| **dependencies** | Optional | The list of dependency configurations. |
| **configuration** | Optional | The runtime configuration definitions. |

### Endpoint configurations
In the `endpoints` section of the `component.yaml` file, you can define multiple service endpoint configurations. Each endpoint must have a unique name and the required fields specified in the schema overview.
Expand Down Expand Up @@ -114,6 +129,23 @@ Click the respective tab to view the structure for your current configuration fi

To use custom environment variable names instead of Choreo's default ones, add the dependency as a `serviceReference` in your `component.yaml v1.1` file. You can copy the `serviceReference` section from the `component.yaml v1.0` tab and paste it under `dependencies` in your `component.yaml v1.1` file, which maintains backward compatibility with the v1.0 format.

### Runtime configurations
In the `configuration` section of the `component.yaml` file, you can define runtime configurations for the component. Currently, the configurations support env variable injection related to dependencies.
chathuranga95 marked this conversation as resolved.
Show resolved Hide resolved

| Configuration | Required | Description |
|-------------------------------|--------------|----------------------------------------------------------------------------------|
| **env** | Optional | Array of env variable confiuration |
chathuranga95 marked this conversation as resolved.
Show resolved Hide resolved
| ** name** | Required | A unique name starting with a letter or an underscore, containing letters, numbers and underscore for the environment variable name |
chathuranga95 marked this conversation as resolved.
Show resolved Hide resolved
| ** valueFrom** | Required | Value source for the env variable |
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we say "The source of the environment variable value."?

| **  connectionRef** | Required | Connection reference value source definition |
| **   name** | Required | Choreo connection name to refer the value from |
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we say "The name of the Choreo connection to reference the value from."?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I'll update.

| **   key** | Required | Choreo connection configuration key to refer the value from. Refer to [connection configurations](https://wso2.com/choreo/docs/develop-components/sharing-and-reusing/use-a-connection-in-your-service/) or see in-line in-line developer guide displayed during connection creation to discover available keys |
Copy link
Contributor

@Nashaath Nashaath Jan 21, 2025

Choose a reason for hiding this comment

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

Suggestion:
"The Choreo connection configuration key to reference the value from. For details on available keys, see Consume a service through a connection or the inline developer guide."


!!! note
Runtime configurations are supported only from component.yaml v1.1.
chathuranga95 marked this conversation as resolved.
Show resolved Hide resolved

When environment variable value source is specified using `connectionRef`, the connection environment variable will be renamed into the given environment name. For example, in above sample `component.yaml` file, `CHOREO_HR_CONNECTION_SERVICEURL` variable from the `hr-connection` will be renamed to `HR_SERVICE_URL`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion:
When an environment variable value is specified using connectionRef, the connection's environment variable is renamed to the environment variable name defined in the configuration section. For example, in the sample component.yaml file given above, the CHOREO_HR_CONNECTION_SERVICEURL variable in the hr-connection is renamed to HR_SERVICE_URL.


=== "Version 1.0"

``` yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,20 @@ To integrate another service into your application, click the appropriate tab be
| ChoreoAPIKey | CHOREO_<CONNECTION_NAME\>CHOREOAPIKEY |


If you'd like to use custom environment variable names instead of the Choreo-defined ones, add the dependency as a service reference under `dependencies` in the same file. For more details, refer to the instructions under the `component.yaml file (v1.0)` tab.
If you'd like to use custom environment variable names instead of the Choreo-defined ones, add env configurations under `configuration` in the same file.
chathuranga95 marked this conversation as resolved.
Show resolved Hide resolved
The following is a sample snippet:

``` yaml
configuration:
env:
- name: HR_SERVICE_URL
valueFrom:
connectionRef:
name: hr-connection
key: ServiceURL
```

The following table provides details on the configuration keys associated with the connection:
The following table provides details on the configuration keys associated with the connection, which can be used as `env[i].valueFrom.connectionRef.key`.
chathuranga95 marked this conversation as resolved.
Show resolved Hide resolved

| Name | Type | Description |Optional | Sensitive |
|----------------|------------|---------------------------------------|---------------|--------------|
Expand All @@ -61,6 +71,8 @@ To integrate another service into your application, click the appropriate tab be
| TokenURL | string | Token URL of the STS | false | false |
| ChoreoAPIKey | string | API key of the Choreo service | false | true |

For more details, refer to the instructions under the `component.yaml file (v1.1)` tab.
chathuranga95 marked this conversation as resolved.
Show resolved Hide resolved

### Step 2: Read configurations within the application

Once you add the connection configuration snippet, you can proceed to read those configurations within your application. The steps to follow depend on the programming language you are using.
Expand Down