Skip to content

Instantly share code, notes, and snippets.

@boutros
Last active May 28, 2020 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boutros/25827d96e5ccf806225981a57bc80f9e to your computer and use it in GitHub Desktop.
Save boutros/25827d96e5ccf806225981a57bc80f9e to your computer and use it in GitHub Desktop.
ldif navn og epost
package main
import (
"fmt"
"io/ioutil"
"log"
"github.com/go-ldap/ldif"
)
const q = `
SPARQL
PREFIX : <https://persons.deichman.no/ontology/>
WITH <https://persons.deichman.no>
DELETE { ?p :name ?name }
INSERT {
?p :name "%s" ;
:email "%s" .
}
WHERE {
?p :username "deb%s"
OPTIONAL { ?p :name ?name }
}
;`
func main() {
b, err := ioutil.ReadFile("fullExport.ldif")
if err != nil {
log.Fatal(err)
}
data, err := ldif.Parse(string(b))
if err != nil {
log.Fatal(err)
}
for _, e := range data.AllEntries() {
surname := e.GetAttributeValue("sn")
givenName := e.GetAttributeValue("givenName")
name := fmt.Sprintf("%s %s", givenName, surname)
debid := e.GetAttributeValue("uid")
email := e.GetAttributeValue("mail")
if name != "" && debid != "" {
fmt.Printf(q, name, email, debid)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment