Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
- Don't add a new struct in the interface just for local usage, use unnamed struct instead
- Check error code
- Apply gofmt

Co-authored-by: alexzorin <alex@zorin.au>
  • Loading branch information
cyril42e and alexzorin committed Jan 16, 2023
1 parent f4bcb86 commit 87e4524
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
16 changes: 11 additions & 5 deletions cmd/authy-export/authy-export.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"encoding/json"
"errors"
"flag"
"fmt"
"log"
"net/url"
Expand All @@ -12,7 +13,6 @@ import (
"strconv"
"strings"
"time"
"flag"

"github.com/alexzorin/authy"
"golang.org/x/crypto/ssh/terminal"
Expand All @@ -28,11 +28,14 @@ type deviceRegistration struct {
}

func main() {
savePtr := flag.String("save", "", "Save encrypted tokens and apps to this json file")
loadPtr := flag.String("load", "", "Load tokens from this json file instead of the server")
savePtr := flag.String("save", "", "Save encrypted tokens to this JSON file")
loadPtr := flag.String("load", "", "Load tokens from this JSON file instead of the server")
flag.Parse()

var resp authy.AuthenticatorResponse
var resp struct {
Tokens authy.AuthenticatorTokensResponse `json:"tokens"`
Apps authy.AuthenticatorAppsResponse `json:"apps"`
}
if *loadPtr != "" {
// Get tokens from the json file
f, err := os.Open(*loadPtr)
Expand All @@ -41,7 +44,10 @@ func main() {
}
defer f.Close()

json.NewDecoder(f).Decode(&resp)
err = json.NewDecoder(f).Decode(&resp)
if err != nil {
log.Fatalf("Failed to decode the file: %v", err)
}
} else {
// Get tokens from the server
// If we don't already have a registered device, prompt the user for one
Expand Down
7 changes: 0 additions & 7 deletions objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,3 @@ func (a AuthenticatorApp) Token() (string, error) {
encoder := base32.StdEncoding.WithPadding(base32.NoPadding)
return encoder.EncodeToString(decoded), nil
}

type AuthenticatorResponse struct {
Tokens AuthenticatorTokensResponse `json:"tokens"`

Apps AuthenticatorAppsResponse `json:"apps"`
}

0 comments on commit 87e4524

Please sign in to comment.