-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5610 from ballerina-platform/2201.10.0-stage
Sync 2201.10.0-stage and 2201.10.x branch
- Loading branch information
Showing
29 changed files
with
1,084 additions
and
264 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
swan-lake-latest-version=swan-lake-2201.10.0 | ||
swan-lake-latest-spec-version=2024R1 | ||
swan-lake-latest-version-display-text=2201.10.0 | ||
swan-lake-latest-tool-version=1.4.2 | ||
latest-tool-version=1.4.2 | ||
swan-lake-latest-tool-version=1.4.3 | ||
latest-tool-version=1.4.3 | ||
1-x-channel-latest-version=1.2.13 | ||
1-x-channel-latest-spec-version=2020R1 |
Large diffs are not rendered by default.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
examples/anydata-to-yaml-string/anydata_to_yaml_string.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import ballerina/data.yaml; | ||
import ballerina/io; | ||
|
||
type ServerConfig record {| | ||
string host; | ||
int port; | ||
DatabaseConfig database; | ||
|}; | ||
|
||
type DatabaseConfig record {| | ||
string dbName; | ||
string username; | ||
|}; | ||
|
||
public function main() returns error? { | ||
|
||
ServerConfig serverConfig = { | ||
database: { | ||
dbName: "userDB", | ||
username: "testUser" | ||
}, | ||
port: 3000, | ||
host: "localhost" | ||
}; | ||
|
||
// Serialize a Ballerina value to a string in YAML format. | ||
string serverConfigYamlStr = check yaml:toYamlString(serverConfig); | ||
io:println(serverConfigYamlStr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Serialize a Ballerina value to a string in YAML format | ||
|
||
The `data.yaml` library provides the `toYamlString` function to serialize a value belonging to `anydata` to a string in YAML format. | ||
|
||
For more information on the underlying module, see the [`data.yaml` module](https://lib.ballerina.io/ballerina/data.yaml/latest/). | ||
|
||
::: code anydata_to_yaml_string.bal ::: | ||
|
||
::: out anydata_to_yaml_string.out ::: |
2 changes: 2 additions & 0 deletions
2
examples/anydata-to-yaml-string/anydata_to_yaml_string.metatags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
description: This BBE demonstrates how to serialize a value belonging to `anydata` to a string in YAML format. | ||
keywords: ballerina, ballerina by example, BBE, yaml, yaml to string, record to yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
$ bal run anydata_to_yaml_string.bal | ||
host: localhost | ||
port: 3000 | ||
database: | ||
dbName: userDB | ||
username: testUser |
2 changes: 1 addition & 1 deletion
2
examples/graphql-service-query-complexity/graphql_service_query_complexity.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import ballerina/io; | ||
import ballerina/ldap; | ||
|
||
public function main() returns error? { | ||
// Initializes a new LDAP client with credentials. | ||
ldap:Client ldapClient = check new ( | ||
hostName = "localhost", | ||
port = 389, | ||
domainName = "cn=admin,dc=example,dc=com", | ||
password = "adminpassword" | ||
); | ||
|
||
// Creates an `ldap:Entry` record for the new entry. | ||
ldap:Entry addEntry = { | ||
"objectClass": ["top", "person"], | ||
"sn": "user", | ||
"cn": "user" | ||
}; | ||
|
||
// Adds an entry to the directory server. | ||
ldap:LdapResponse addResponse = check ldapClient->add("cn=user,dc=example,dc=com", addEntry); | ||
io:println("Add Response: ", addResponse.resultCode); | ||
|
||
// Deletes an entry from the directory server. | ||
ldap:LdapResponse deleteResponse = check ldapClient->delete("cn=user,dc=example,dc=com"); | ||
io:println("Delete Response: ", deleteResponse.resultCode); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# LDAP client - Add/Remove entries | ||
|
||
The `ldap:Client` connects to a directory server and performs various operations on directories. Currently, it supports the generic LDAP operations; `add`, `modify`, `modifyDN`, `compare`, `search`, `searchWithType`, `delete`, and `close`. | ||
|
||
The `add` operation creates a new entry in a directory server. It requires a `DN` (Distinguished Name) for the entry and the attributes to be included. The `objectClass` attribute must be specified to define the object classes for the entry, and any attributes required by these object classes should also be included. | ||
|
||
The `delete` operation removes an entry from a directory server. It requires a `DN` (Distinguished Name) of the entry to be deleted. | ||
|
||
::: code ldap_add_remove_entry.bal ::: | ||
|
||
## Prerequisites | ||
- Ensure that an LDAP server is up and running locally on port 389 while running the example. | ||
|
||
- Run the example by executing the command below. | ||
|
||
::: out ldap_add_remove_entry.server.out ::: | ||
|
||
## Related links | ||
- [`ldap:Client` `add` operation - API documentation](https://central.ballerina.io/ballerina/ldap/latest#Client-add) | ||
- [`ldap:Client` `delete` operation - API documentation](https://central.ballerina.io/ballerina/ldap/latest#Client-delete) | ||
- [`ldap` module - API documentation](https://lib.ballerina.io/ballerina/ldap/latest/) | ||
- [`ldap:Client` - Specification](/spec/ldap/#2-ldap-client) |
2 changes: 2 additions & 0 deletions
2
examples/ldap-add-remove-entry/ldap_add_remove_entry.metatags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
description: This example is on how to create/delete entries in a directory server using LDAP in Ballerina. | ||
keywords: ballerina, ballerina by example, bbe, ldap, add |
3 changes: 3 additions & 0 deletions
3
examples/ldap-add-remove-entry/ldap_add_remove_entry.server.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
$ bal run ldap_add_remove_entry.bal | ||
Add Response: SUCCESS | ||
Delete Response: SUCCESS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import ballerina/io; | ||
import ballerina/ldap; | ||
|
||
public function main() returns error? { | ||
// Initializes a new LDAP client with credentials. | ||
ldap:Client ldapClient = check new ( | ||
hostName = "localhost", | ||
port = 389, | ||
domainName = "cn=admin,dc=example,dc=com", | ||
password = "adminpassword" | ||
); | ||
|
||
// Searches for an entry in the directory server. | ||
ldap:SearchResult searchResult = check ldapClient->search( | ||
"cn=user,dc=example,dc=com", | ||
"(sn=user)", | ||
ldap:SUB | ||
); | ||
io:println("Search Response: ", searchResult.resultCode); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# LDAP client - Seacrh for an entry | ||
|
||
The `ldap:Client` connects to a directory server and performs various operations on directories. Currently, it supports the main LDAP operations; `add`, `modify`, `modifyDN`, `compare`, `search`, `searchWithType`, `delete`, and `close`. | ||
|
||
The `search` operation is used to retrieve entries that match specified criteria. The components of an LDAP search request include: | ||
|
||
- `baseDN`: Defines the base of the subtree for the search. | ||
- `filter`: Specifies the criteria that entries must meet. | ||
- `scope`: Determines extent of the the search coverage within the subtree. | ||
|
||
When a directory server processes a valid search request, it finds entries within the defined scope that meet the filter criteria. The matching entries are then returned to the client in a `ldap:SearchResult` record. | ||
|
||
::: code ldap_search_entry.bal ::: | ||
|
||
## Prerequisites | ||
- Ensure that an LDAP server is up and running locally on port 389 while running the example. | ||
|
||
- Run the example by executing the command below. | ||
|
||
::: out ldap_search_entry.server.out ::: | ||
|
||
## Related links | ||
- [`ldap:Client` `search` operation - API documentation](https://central.ballerina.io/ballerina/ldap/latest#Client-search) | ||
- [`ldap` module - API documentation](https://lib.ballerina.io/ballerina/ldap/latest/) | ||
- [`ldap:Client` - Specification](/spec/ldap/#2-ldap-client) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
description: This example is on how to search for an entry in a directory server using LDAP in Ballerina. | ||
keywords: ballerina, ballerina by example, bbe, ldap, search |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
$ bal run ldap_search_entry.bal | ||
Search Response: SUCCESS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
examples/yaml-to-anydata-with-projection/yaml_to_anydata_with_projection.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import ballerina/data.yaml; | ||
import ballerina/io; | ||
|
||
type ServerConfig record {| | ||
string host; | ||
int port; | ||
int[2] remotePorts; | ||
DatabaseConfig database; | ||
|}; | ||
|
||
type DatabaseConfig record {| | ||
string dbName; | ||
string username; | ||
|}; | ||
|
||
public function main() returns error? { | ||
// Similar to content read from a YAML file. | ||
string yamlString = string ` | ||
host: "localhost" | ||
port: 8080 | ||
remotePorts: [9000, 9001, 9002, 9003] | ||
protocol: "http" | ||
database: | ||
dbName: "testdb" | ||
username: "dbuser" | ||
password: "dbpassword"`; | ||
|
||
// Based on the expected type, this function selectively constructs the record from the YAML string. | ||
ServerConfig serverConfig = check yaml:parseString(yamlString); | ||
// The `password` field is excluded in the created record value. | ||
// Only the first two elements from the source are used to create the `remotePorts` array. | ||
io:println(serverConfig); | ||
} |
11 changes: 11 additions & 0 deletions
11
examples/yaml-to-anydata-with-projection/yaml_to_anydata_with_projection.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# YAML to anydata conversion with projection | ||
|
||
The `data.yaml` library provides multiple APIs to selectively parse elements and attributes from a YAML source, in the form of a string, byte array, or byte block stream, into a Ballerina record. Using projection, users can selectively add fields to records and limit the sizes of arrays. | ||
|
||
In this example, the `password` attribute is excluded when creating the `DatabaseConfig` record, and only the first two elements from the source are used to create the `remotePorts` array. | ||
|
||
For more information on the underlying module, see the [`data.yaml` module](https://lib.ballerina.io/ballerina/data.yaml/latest/). | ||
|
||
::: code yaml_to_anydata_with_projection.bal ::: | ||
|
||
::: out yaml_to_anydata_with_projection.out ::: |
2 changes: 2 additions & 0 deletions
2
examples/yaml-to-anydata-with-projection/yaml_to_anydata_with_projection.metatags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
description: This BBE demonstrates how to selectively convert fields from a YAML source, which can be provided as a string, byte array, or byte block stream, into a Ballerina record with projection. | ||
keywords: ballerina, ballerina by example, BBE, yaml, record, data projection |
2 changes: 2 additions & 0 deletions
2
examples/yaml-to-anydata-with-projection/yaml_to_anydata_with_projection.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
$ bal run yaml_to_anydata_with_projection.bal | ||
{"host":"localhost","port":8080,"remotePorts":[9000,9001],"database":{"dbName":"testdb","username":"dbuser"}} |
Oops, something went wrong.