Skip to content

Commit

Permalink
Contacts Export (#1152)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbengfort authored Jan 23, 2024
1 parent 81d6f71 commit 47d1541
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions cmd/gdsutil/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"crypto/sha256"
"crypto/x509"
"encoding/base64"
"encoding/csv"
"encoding/json"
"encoding/pem"
"errors"
Expand Down Expand Up @@ -197,6 +198,15 @@ func main() {
After: closeDB,
Flags: []cli.Flag{},
},
{
Name: "contact:export",
Usage: "export the VASP contacts in the current database",
Category: "contact",
Action: contactExport,
Before: connectDB,
After: closeDB,
Flags: []cli.Flag{},
},
{
Name: "contact:detail",
Usage: "get the detail for a contact record",
Expand Down Expand Up @@ -742,6 +752,51 @@ func contactList(c *cli.Context) (err error) {
return nil
}

func contactExport(c *cli.Context) (err error) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

vasps := db.ListVASPs(ctx)

w := csv.NewWriter(os.Stdout)
defer w.Flush()

w.Write([]string{"ID", "VASP", "Administrative", "Technical", "Legal", "Billing"})

for vasps.Next() {
vasp, err := vasps.VASP()
if err != nil {
continue
}

row := make([]string, 6)
row[0] = vasp.Id
row[1], _ = vasp.Name()

contacts := vasp.Contacts

if contacts.Administrative != nil {
row[2] = fmt.Sprintf("%q <%s>", contacts.Administrative.Name, contacts.Administrative.Email)
}

if contacts.Technical != nil {
row[3] = fmt.Sprintf("%q <%s>", contacts.Technical.Name, contacts.Technical.Email)
}

if contacts.Legal != nil {
row[4] = fmt.Sprintf("%q <%s>", contacts.Legal.Name, contacts.Legal.Email)
}

if contacts.Billing != nil {
row[5] = fmt.Sprintf("%q <%s>", contacts.Billing.Name, contacts.Billing.Email)
}

w.Write(row)
}

return nil
}

func contactDetail(c *cli.Context) (err error) {
if c.NArg() == 0 {
return cli.Exit("specify at least one email address", 1)
Expand Down

0 comments on commit 47d1541

Please sign in to comment.