Methods
(async) WLdap(input, optopt) → {Promise}
- Description:
呼叫LDAP服務進行登入或取得使用者清單,係呼叫Net程式呼叫LDAP取得資料,故會有Net Framework版本與作業系統限制
輸入(含帳密)經子程序之stdin交給Net程式,不出現在程序之命令列;只轉交mode、account、password、ldappath,不改動呼叫端之input
Net程式(connLDAP.net4.x.exe與其相鄰之Newtonsoft.Json.dll)不隨npm包發布:首次使用時經ensureBins依bin/manifest.json下載、逐檔校驗並整組放入快取,之後自快取取用;環境變數W_BIN_CACHE、W_BIN_MIRROR、W_BIN_OFFLINE見README〈External executables〉。輸出檔寫在作業系統暫存夾(跨磁碟機時寫在Net程式所在之快取夾),用畢即刪
- Source:
Example
import WLdap from 'w-ldap'
async function test() {
let inp
let r
let account = '{account}'
let password = '{password}'
let ldappath = 'LDAP://{PATH}'
inp = {
mode: 'logIn',
account,
password,
ldappath,
}
r = await WLdap(inp)
console.log('logIn', r)
w.fsWriteText('logIn.txt', w.o2j(r, true))
inp = {
mode: 'listUsers',
account,
password,
ldappath,
}
r = await WLdap(inp)
w.fsWriteText('listUsers.txt', w.o2j(r, true))
}
test()
.catch((err) => {
console.log('catch', err)
})
Parameters:
| Name | Type | Attributes | Default | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
input |
Object | 輸入呼叫資料物件 Properties
|
|||||||||||||||||
opt |
Object |
<optional> |
{}
|
輸入設定物件,預設{} Properties
|
Returns:
回傳Promise。resolve回傳成功資料:logIn為該帳號之LDAP條目,帳密驗證成功但以samaccountname查無該帳號條目時回傳{success:null};listUsers為使用者條目陣列。reject一律回傳錯誤訊息字串:輸入檢查失敗為說明字串;取得Net程式失敗(首次使用時下載、校驗或離線缺檔)以'ensureBins[錯誤碼]:'開頭;LDAP回報之錯誤為其原始訊息;Net程式啟動失敗以'spawn['開頭;Net程式以非0結束以'code['開頭;逾時以'timeout['開頭;Net程式結束但未產生輸出檔為'connLDAP exited without output file';輸出內容不合格式以'invalid output from connLDAP:'開頭
- Type
- Promise
ensureBins(optopt) → {Promise}
- Description:
取得本套件之外部執行檔組connLDAP(connLDAP.net4.5.exe、connLDAP.net4.6.exe、connLDAP.net4.7.2.exe、connLDAP.net4.8.exe與其相鄰之Newtonsoft.Json.dll): 首次使用時下載(或自鏡像取得)並以bin/manifest.json之SHA-256與大小逐檔校驗,整組發布於同一資料夾,之後自快取取得(亦校驗)
規格: 外部執行檔之存放下載校驗與離線(制式規格)§6(檔案組M6);實作為wsemi之fsEnsureBins,本套件不另寫下載、快取、鏡像、校驗 環境變數: W_BIN_CACHE(共用快取資料夾)、W_BIN_MIRROR(鏡像,本地資料夾或http(s)網址)、W_BIN_OFFLINE(1為離線),見README〈External executables〉
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
opt |
Object |
<optional> |
{}
|
輸入設定物件,交wsemi之fsEnsureBins(names、cacheDir、mirror、offline、onProgress等),pkgRoot固定為本套件根 |
Returns:
回傳Promise,resolve回傳{ connLDAP: 組資料夾絕對路徑 },另有不可列舉之bundles:bundles.connLDAP.files['connLDAP.net4.8.exe']為該exe之絕對路徑;reject回傳帶code之Error(E_OFFLINE_MISSING等)
- Type
- Promise