Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dockerfiles + pretty output #23

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM golang:1.8.5-alpine3.6

RUN apk update && apk upgrade && \
apk add --no-cache bash git

WORKDIR /go/src/gauth

COPY src/* .

RUN go-wrapper download # "go get -d -v ./..."
RUN go-wrapper install # "go install -v ./..."

CMD ["go-wrapper", "run"] # ["app"]
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Build container
build:
@bash -x scripts/build.sh

## Push container
push:
@bash -x scripts/push.sh

## Run container locally
run:
@bash -x scripts/run.sh

help:
@printf "Available targets:\n\n"
@awk '/^[a-zA-Z\-\_0-9%:\\]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = $$1; \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
gsub("\\\\", "", helpCommand); \
gsub(":+$$", "", helpCommand); \
printf " \x1b[32;01m%-35s\x1b[0m %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST) | sort -u
@printf "\n"
39 changes: 0 additions & 39 deletions PKGBUILD

This file was deleted.

4 changes: 4 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -ex

docker build -t stevemcquaid/gauth:latest .
4 changes: 4 additions & 0 deletions scripts/push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -ex

docker push stevemcquaid/gauth:latest
5 changes: 5 additions & 0 deletions scripts/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -ex

docker run -it --rm stevemcquaid/gauth:latest /bin/sh

41 changes: 38 additions & 3 deletions gauth.go → src/gauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"crypto/sha256"
"encoding/base32"
"encoding/csv"
"flag"
"fmt"
"golang.org/x/crypto/ssh/terminal"
"io/ioutil"
Expand Down Expand Up @@ -74,8 +75,15 @@ func main() {
if e != nil {
log.Fatal(e)
}
cfgPath := path.Join(user.HomeDir, ".config/gauth.csv")

var configPtr string
flag.StringVar(&configPtr, "config", path.Join(user.HomeDir, ".config/gauth.csv"), "Absolute path to config file to use")

flag.Parse()
sArgs := flag.Args()

cfgPath := path.Join("", configPtr)

cfgContent, e := ioutil.ReadFile(cfgPath)
if e != nil {
log.Fatal(e)
Expand Down Expand Up @@ -125,14 +133,41 @@ func main() {
prevTS := currentTS - 1
nextTS := currentTS + 1

fmt.Println(" prev curr next")
wordSize := 0
for _, record := range cfg {
// Only include the ones that are provided in the search result
var actualSize int
if len(sArgs) == 0 {
actualSize = len([]rune(record[0]))
} else if strings.Contains(strings.ToLower(record[0]), strings.ToLower(sArgs[0])) == true {
actualSize = len([]rune(record[0]))
}

if actualSize > wordSize {
wordSize = actualSize
}
}

var header = "prev curr next"
fmt.Println(leftPad(header, " ", wordSize+1))
for _, record := range cfg {
name := record[0]
secret := normalizeSecret(record[1])
prevToken := authCodeOrDie(secret, prevTS)
currentToken := authCodeOrDie(secret, currentTS)
nextToken := authCodeOrDie(secret, nextTS)
fmt.Printf("%-10s %s %s %s\n", name, prevToken, currentToken, nextToken)

if len(sArgs) == 0 {
fmt.Printf("%-*s %s %s %s\n", wordSize, name, prevToken, currentToken, nextToken)
} else if strings.Contains(strings.ToLower(name), strings.ToLower(sArgs[0])) == true {
fmt.Printf("%-*s %s %s %s\n", wordSize, name, prevToken, currentToken, nextToken)
}
// fmt.Printf("%-*s %s %s %s\n", wordSize, name, prevToken, currentToken, nextToken)
}
fmt.Printf("[%-29s]\n", strings.Repeat("=", progress))
}

func leftPad(s string, padStr string, pLen int) string {
return strings.Repeat(padStr, pLen) + s
}