Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pgporada committed Aug 14, 2024
1 parent 46859a2 commit 063b5a1
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cmd/admin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ func main() {

// This is the registry of all subcommands that the admin tool can run.
subcommands := map[string]subcommand{
"revoke-cert": &subcommandRevokeCert{},
"block-key": &subcommandBlockKey{},
"update-email": &subcommandUpdateEmail{},
"revoke-cert": &subcommandRevokeCert{},
"block-key": &subcommandBlockKey{},
"update-email": &subcommandUpdateEmail{},
"pause-batch": &subcommandPauseBatch{},
"unpause-batch": &subcommandUnpauseBatch{},
}

defaultUsage := flag.Usage
Expand Down
125 changes: 125 additions & 0 deletions cmd/admin/pause.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package main

import (
"context"
"encoding/csv"
"errors"
"flag"
"fmt"
"io"
"os"
"strconv"

"github.com/letsencrypt/boulder/identifier"
)

// subcommandPauseBatch encapsulates the "admin pause-batch" commands.
type subcommandPauseBatch struct {
file string
}

var _ subcommand = (*subcommandPauseBatch)(nil)

func (p *subcommandPauseBatch) Desc() string {
return "Batch pause a CSV containing (account, identifier type, list of identifier strings)"
}

func (p *subcommandPauseBatch) Flags(flag *flag.FlagSet) {
flag.StringVar(&p.file, "file", "", "Path to CSV file containing (account, identifier type, list of identifier strings)")
}

func (p *subcommandPauseBatch) Run(ctx context.Context, a *admin) error {
if p.file == "" {
return errors.New("the -file flag is required")
}

_, err := a.readPausedAccountFile(p.file)
if err != nil {
return err
}

// TODO: Fix
return errors.New("no action to perform on the given CSV file was specified")
}

// subcommandUnpauseBatch encapsulates the "admin unpause-batch" commands.
type subcommandUnpauseBatch struct {
file string
}

var _ subcommand = (*subcommandUnpauseBatch)(nil)

func (u *subcommandUnpauseBatch) Desc() string {
return "Batch unpause a CSV containing (account, identifier type, list of identifier strings)"
}

func (u *subcommandUnpauseBatch) Flags(flag *flag.FlagSet) {
flag.StringVar(&u.file, "file", "", "Path to CSV file containing (account, identifier type, list of identifier strings)")
}

func (u *subcommandUnpauseBatch) Run(ctx context.Context, a *admin) error {
if u.file == "" {
return errors.New("the -file flag is required")
}

_, err := a.readPausedAccountFile(u.file)
if err != nil {
return err
}

// TODO: Fix
return errors.New("no action to perform on the given CSV file was specified")
}

// pauseData contains
type pauseData struct {
accountID int64
identifierType identifier.IdentifierType
identifierValue []string
}

// readPausedAccountFile parses the contents of a CSV into a slice of
// `pauseData` objects. It will return an error if an individual record is
// malformed.
func (a *admin) readPausedAccountFile(filePath string) ([]pauseData, error) {
fp, err := os.Open(filePath)
if err != nil {
return nil, fmt.Errorf("opening paused account data file: %w", err)
}
defer fp.Close()

reader := csv.NewReader(fp)

// identifierValue can have 1 or more entries
reader.FieldsPerRecord = -1
reader.TrimLeadingSpace = true

var data []pauseData

// Parse file contents
for {
record, err := reader.Read()
if errors.Is(err, io.EOF) {
// Finished parsing the file.
if len(record) == 0 {
return nil, errors.New("no records found")
}
// TODO: return valid data or something
return data, nil
} else if err != nil {
return nil, err
}

// Ensure the first column of each record can be parsed as a valid
// accountID.
recordID := record[0]
accountID, err := strconv.ParseInt(recordID, 10, 64)
if err != nil {
return nil, fmt.Errorf("%q couldn't be parsed as an accountID due to: %s", recordID, err)
}
identifierType := identifier.IdentifierType(record[1])
identifierValue := record[2:]

fmt.Printf("Loaded: %d,%s,%s", accountID, identifierType, identifierValue[:])
}
}

0 comments on commit 063b5a1

Please sign in to comment.