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

Apply suggestions from the API review #51

Merged
merged 27 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
145ffeb
Apply suggestions from the review
Nuvindu Jun 19, 2024
e0587f6
Remove redundant message field from `ErrorDetails`
Nuvindu Jun 19, 2024
90e0d34
Add `Entry` record type to represent entries in directory servers
Nuvindu Jun 19, 2024
29a7edc
Update test cases with the new changes
Nuvindu Jun 19, 2024
dcd14a4
Fix native code with the new updates
Nuvindu Jun 19, 2024
1b79567
Fix API description in the documentation
Nuvindu Jun 20, 2024
de51976
Remove skipping null values from the native code
Nuvindu Jun 20, 2024
7ea661b
Remove additional flags from pr build workflow
Nuvindu Jun 23, 2024
9e8c7e1
Update files to start a ldap server from a docker image
Nuvindu Jun 23, 2024
ba5df71
Support nil values in references field in the `SearchResult` record
Nuvindu Jun 23, 2024
dfdafe2
Update test cases to support the schemas in openldap server
Nuvindu Jun 23, 2024
a11e768
Update gradle file to run ldap server on build
Nuvindu Jun 23, 2024
127a8d8
Fix spot bugs in the code
Nuvindu Jun 23, 2024
7b15b1c
Merge branch 'ballerina-platform:master' into new-apis
Nuvindu Jun 23, 2024
05be8c1
Apply review suggestions
Nuvindu Jun 24, 2024
12fcc9c
Make the `Client` class final
Nuvindu Jun 24, 2024
cac3d9e
[Automated] Update the toml files
Nuvindu Jun 25, 2024
218d5fb
Update variable names in test cases
Nuvindu Jun 25, 2024
6d4fbb4
Apply suggestions from the review
Nuvindu Jun 25, 2024
72b1546
Add overloaded functions for error handling
Nuvindu Jun 25, 2024
6f13840
Change `EntryMember` record type to `AttributeType`
Nuvindu Jun 25, 2024
1828156
Remove unused variables in test cases
Nuvindu Jun 26, 2024
7f9dcef
Add publishing configurations to the Gradle build file
Nuvindu Jun 26, 2024
929c7d1
Bump package version to 1.0.0
Nuvindu Jun 26, 2024
952e942
Modify nullable checks
Nuvindu Jun 26, 2024
528c78d
Update entry not found error message
Nuvindu Jun 26, 2024
0f3fc74
Remove unused catch blocks
Nuvindu Jun 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@ jobs:
uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@main
secrets: inherit
with:
additional-ubuntu-build-flags: "-x test"
additional-ubuntu-test-flags: "-x test"
additional-windows-build-flags: "-x test"
additional-windows-test-flags: "-x test"
Nuvindu marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function main() returns error? {

#### `modifyDN` API

Updates information of an entry.
Renames an entry in a directory server.

```ballerina
import ballerina/ldap;
Expand Down
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
org = "ballerina"
name = "ldap"
version = "0.9.0"
version = "0.9.1"
authors = ["Ballerina"]
export=["ldap"]
keywords = ["ldap"]
Expand All @@ -15,8 +15,8 @@ graalvmCompatible = true
[[platform.java17.dependency]]
groupId = "io.ballerina.lib"
artifactId = "ldap-native"
version = "0.9.0"
path = "../native/build/libs/ldap-native-0.9.0.jar"
version = "0.9.1-SNAPSHOT"
path = "../native/build/libs/ldap-native-0.9.1-SNAPSHOT.jar"

[[platform.java17.dependency]]
groupId = "com.unboundid"
Expand Down
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "ldap"
version = "0.9.0"
version = "0.9.1"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "test"}
Expand Down
2 changes: 1 addition & 1 deletion ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function main() returns error? {

#### `modifyDN` API

Updates information of an entry.
Renames an entry in a directory server.

```ballerina
import ballerina/ldap;
Expand Down
2 changes: 1 addition & 1 deletion ballerina/Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function main() returns error? {

#### `modifyDN` API

Updates information of an entry.
Renames an entry in a directory server.

```ballerina
import ballerina/ldap;
Expand Down
69 changes: 69 additions & 0 deletions ballerina/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,80 @@ clean {
delete 'build'
}

task startLdapServer() {
doLast {
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
Nuvindu marked this conversation as resolved.
Show resolved Hide resolved
def stdOut = new ByteArrayOutputStream()
exec {
commandLine 'sh', '-c', "docker ps --filter name=openldap-server"
standardOutput = stdOut
}
if (!stdOut.toString().contains("openldap-server")) {
println "Starting LDAP server."
exec {
commandLine 'sh', '-c', "docker-compose -f $project.projectDir/tests/resources/openldap/docker-compose.yml up -d"
standardOutput = stdOut
}
println stdOut.toString()
println "Waiting 15s until the LDAP server get initiated."
sleep(15 * 1000)
} else {
println "LDAP server is already started."
}
}
}
}

task stopLdapServer() {
doLast {
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
def stdOut = new ByteArrayOutputStream()
exec {
commandLine 'sh', '-c', "docker ps --filter name=openldap-server"
standardOutput = stdOut
}
if (stdOut.toString().contains("openldap-server")) {
println "Stopping LDAP server."
exec {
commandLine 'sh', '-c', "docker stop openldap-server"
standardOutput = stdOut
}
println stdOut.toString()
println "Waiting 5s until the LDAP server get stopped."
sleep(5 * 1000)
} else {
println "LDAP server is not started."
}
}
}
}

publishing {
publications {
maven(MavenPublication) {
artifact source: createArtifactZip, extension: 'zip'
}
}

repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/ballerina-platform/module-ballerina-ldap")
credentials {
username = System.getenv("publishUser")
password = System.getenv("publishPAT")
}
}
}
}

updateTomlFiles.dependsOn copyStdlibs
build.dependsOn copyToLib

test.dependsOn ":${packageName}-native:build"
build.dependsOn ":${packageName}-native:build"
build.dependsOn startLdapServer
build.finalizedBy stopLdapServer

publishToMavenLocal.dependsOn build
publish.dependsOn build
70 changes: 34 additions & 36 deletions ballerina/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -28,103 +28,101 @@ public isolated client class Client {
}

private isolated function initLdapConnection(ConnectionConfig config) returns Error? = @java:Method {
'class: "io.ballerina.lib.ldap.Ldap"
'class: "io.ballerina.lib.ldap.Client"
} external;

# Creates an entry in a directory server.
#
# + distinguishedName - The distinguished name of the entry
# + dN - The distinguished name of the entry
# + entry - The information to add
# + return - A `ldap:Error` if the operation fails or `ldap:LdapResponse` if successfully created
remote isolated function add(string distinguishedName, record {|anydata...;|} entry)
returns LdapResponse|Error = @java:Method {
'class: "io.ballerina.lib.ldap.Ldap"
remote isolated function add(string dN, Entry entry) returns LdapResponse|Error = @java:Method {
'class: "io.ballerina.lib.ldap.Client"
} external;

# Removes an entry in a directory server.
#
# + distinguishedName - The distinguished name of the entry to remove
# + dN - The distinguished name of the entry to remove
# + return - A `ldap:Error` if the operation fails or `ldap:LdapResponse` if successfully removed
remote isolated function delete(string distinguishedName) returns LdapResponse|Error = @java:Method {
'class: "io.ballerina.lib.ldap.Ldap"
remote isolated function delete(string dN) returns LdapResponse|Error = @java:Method {
'class: "io.ballerina.lib.ldap.Client"
} external;

# Updates information of an entry.
#
# + distinguishedName - The distinguished name of the entry
# + dN - The distinguished name of the entry
# + entry - The information to update
# + return - A `ldap:Error` if the operation fails or `LdapResponse` if successfully updated
remote isolated function modify(string distinguishedName, record {|anydata...;|} entry)
returns LdapResponse|Error = @java:Method {
'class: "io.ballerina.lib.ldap.Ldap"
remote isolated function modify(string dN, Entry entry) returns LdapResponse|Error = @java:Method {
'class: "io.ballerina.lib.ldap.Client"
} external;

# Renames an entry in a directory server.
#
# + currentDN - The current distinguished name of the entry
# + newRDN - The new relative distinguished name
# + deleteOldRDN - A boolean value to determine whether to delete the old RDN
# + currentDn - The current distinguished name of the entry
# + newRdn - The new relative distinguished name
# + deleteOldRdn - A boolean value to determine whether to delete the old RDN
# + return - A `ldap:Error` if the operation fails or `ldap:LdapResponse` if successfully renamed
remote isolated function modifyDN(string currentDN, string newRDN, boolean deleteOldRDN = true)
remote isolated function modifyDn(string currentDn, string newRdn, boolean deleteOldRdn = false)
returns LdapResponse|Error = @java:Method {
'class: "io.ballerina.lib.ldap.Ldap"
'class: "io.ballerina.lib.ldap.Client"
} external;

# Determines whether a given entry has a specified attribute value.
#
# + distinguishedName - The distinguished name of the entry
# + attribiteName - The name of the target attribute for which the comparison is to be performed
# + dN - The distinguished name of the entry
# + attributeName - The name of the target attribute for which the comparison is to be performed
# + assertionValue - The assertion value to verify within the entry
# + return - A `ldap:Error` if the operation fails or `ldap:LdapResponse` if successfully executed
remote isolated function compare(string distinguishedName, string attribiteName, string assertionValue)
returns LdapResponse|Error = @java:Method {
'class: "io.ballerina.lib.ldap.Ldap"
# + return - A `boolean` value indicating whether the values match, or an `ldap:Error` if the operation fails
remote isolated function compare(string dN, string attributeName, string assertionValue)
returns boolean|Error = @java:Method {
'class: "io.ballerina.lib.ldap.Client"
} external;

# Gets information of an entry.
#
# + distinguishedName - The distinguished name of the entry
# + dN - The distinguished name of the entry
# + targetType - Default parameter use to infer the user specified type
# + return - An entry result with the given type or else `ldap:Error`
remote isolated function getEntry(string distinguishedName, typedesc<anydata> targetType = <>)
remote isolated function getEntry(string dN, typedesc<anydata> targetType = <>)
returns targetType|Error = @java:Method {
'class: "io.ballerina.lib.ldap.Ldap"
'class: "io.ballerina.lib.ldap.Client"
} external;

# Returns a list of entries that match the given search parameters.
#
# + baseDN - The base distinguished name of the entry
#
# + baseDn - The base distinguished name of the entry
# + filter - The filter to be used in the search
# + scope - The scope of the search
# + targetType - Default parameter use to infer the user specified type
# + return - An array of entries with the given type or else `ldap:Error`
remote isolated function searchWithType(string baseDN, string filter,
SearchScope scope, typedesc<anydata[]> targetType = <>)
remote isolated function searchWithType(string baseDn, string filter,
SearchScope scope, typedesc<record{}[]> targetType = <>)
returns targetType|Error = @java:Method {
'class: "io.ballerina.lib.ldap.Ldap"
'class: "io.ballerina.lib.ldap.Client"
} external;

# Returns a record containing search result entries and references that match the given search parameters.
#
# + baseDN - The base distinguished name of the entry
# + baseDn - The base distinguished name of the entry
# + filter - The filter to be used in the search
# + scope - The scope of the search
# + return - An `ldap:SearchResult` if successful, or else `ldap:Error`
remote isolated function search(string baseDN, string filter, SearchScope scope)
remote isolated function search(string baseDn, string filter, SearchScope scope)
returns SearchResult|Error = @java:Method {
'class: "io.ballerina.lib.ldap.Ldap"
'class: "io.ballerina.lib.ldap.Client"
} external;

# Unbinds from the server and closes the LDAP connection.
#
remote isolated function close() = @java:Method {
'class: "io.ballerina.lib.ldap.Ldap"
'class: "io.ballerina.lib.ldap.Client"
} external;

# Determines whether the client is connected to the server.
#
# + return - A boolean value indicating the connection status
remote isolated function isConnected() returns boolean = @java:Method {
'class: "io.ballerina.lib.ldap.Ldap"
'class: "io.ballerina.lib.ldap.Client"
} external;
}
2 changes: 0 additions & 2 deletions ballerina/error.bal
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public type Error distinct error<ErrorDetails>;
# The error details type for the Ballerina LDAP module.
#
# + resultCode - The status of the error
# + message - The error message
public type ErrorDetails record {|
string resultCode?;
string message?;
|};
8 changes: 4 additions & 4 deletions ballerina/tests/Config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
hostName = "host-name"
hostName = "localhost"
port = 389
domainName = "domain@ad.com"
password = "password"
userDN = "CN=User,OU=People,DC=ad,DC=com"
domainName = "cn=admin,dc=mycompany,dc=com"
password = "adminpassword"
userDN = "CN=User,dc=mycompany,dc=com"
44 changes: 44 additions & 0 deletions ballerina/tests/resources/openldap/bootstrap.ldif
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
dn: ou=Users,dc=mycompany,dc=com
changetype: add
objectClass: organizationalUnit
ou: Users

dn: ou=Groups,dc=mycompany,dc=com
changetype: add
objectClass: organizationalUnit
ou: Groups

dn: uid=ldclakmal,ou=Users,dc=mycompany,dc=com
changetype: add
objectClass: inetOrgPerson
cn: John
givenName: John
sn: John
uid: john
displayName: John Doe
mail: [email protected]
userpassword: johndoe@123

dn: uid=alice,ou=Users,dc=mycompany,dc=com
changetype: add
objectClass: inetOrgPerson
cn: Test Developer
givenName: Alice
sn: Parker
uid: alice
displayName: Alice Parker
mail: [email protected]
userpassword: alice@123

dn: cn=admin,ou=Groups,dc=mycompany,dc=com
changetype: add
cn: admin
objectClass: groupOfNames
member: uid=johndoe,ou=Users,dc=mycompany,dc=com

dn: cn=developer,ou=Groups,dc=mycompany,dc=com
changetype: add
cn: developer
objectClass: groupOfNames
member: uid=johndoe,ou=Users,dc=mycompany,dc=com
member: uid=alice,ou=Users,dc=mycompany,dc=com
14 changes: 14 additions & 0 deletions ballerina/tests/resources/openldap/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.7'

services:
ldap_server:
image: osixia/openldap:latest
container_name: my-openldap-container
environment:
LDAP_ORGANISATION: "My Company"
LDAP_DOMAIN: "mycompany.com"
LDAP_ADMIN_PASSWORD: "adminpassword"
ports:
- "389:389"
- "636:636"
command: --copy-service
Loading
Loading