Skip to content

Commit

Permalink
Merge pull request #51 from Nuvindu/new-apis
Browse files Browse the repository at this point in the history
Apply suggestions from the API review
  • Loading branch information
Nuvindu authored Jun 26, 2024
2 parents 58288e0 + 0f3fc74 commit b170c10
Show file tree
Hide file tree
Showing 23 changed files with 529 additions and 448 deletions.
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"
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)) {
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

0 comments on commit b170c10

Please sign in to comment.