Skip to content

Commit

Permalink
updates including Go 1.16.7 (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanericky authored Aug 12, 2021
1 parent cb0a98e commit 8153a99
Show file tree
Hide file tree
Showing 17 changed files with 738 additions and 131 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/builder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
on: [push, pull_request]
name: Build
jobs:
test:
strategy:
matrix:
go-version: [1.16.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Code format
run: diff -u <(echo -n) <(gofmt -d -s .)
- name: Vet
run: go vet ./...
- name: Unit tests
run: go test -race -coverprofile=coverage.out ./...
- name: Function coverage
run: go tool cover "-func=coverage.out"
- name: Upload coverage report
uses: codecov/codecov-action@v2
with:
file: ./coverage.out
- name: Build and Execute
run: |
go build -o totp-test -ldflags "-X main.version=$(./scripts/get-version.sh)" ./totp/...
./totp-test --help
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Release

on:
push:
tags:
- '*'

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50 changes: 50 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
release:
draft: true
before:
hooks:
- go mod tidy
builds:
- main: ./totp
binary: totp
ldflags:
- -s -w -X github.com/arcanericky/totp/cmd.versionText={{.Version}}
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
ignore:
- goos: linux
goarch: 386
- goos: linux
goarch: arm64
- goos: windows
goarch: 386
- goos: darwin
goarch: 386
- goos: darwin
goarch: arm64
archives:
- name_template: "totp_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
format_overrides:
- goos: windows
format: zip
replacements:
darwin: darwin
linux: linux
windows: windows
386: 386
amd64: amd64
files:
- README.md
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Ricky Pike
Copyright (c) 2021 Ricky Pike

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
95 changes: 48 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A time-based one-time password (TOTP) code generator written in Go. Basically a command-line interface that's [Google Authenticator](https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&hl=en_US) or [Authy](https://authy.com/) for your Windows, macOS, or Linux machine.

[![Build Status](https://travis-ci.com/arcanericky/totp.svg?branch=master)](https://travis-ci.com/arcanericky/totp)
[![Build](https://github.com/arcanericky/totp/actions/workflows/builder.yml/badge.svg?branch=master)](https://github.com/arcanericky/totp/actions/workflows/builder.yml)
[![codecov](https://codecov.io/gh/arcanericky/totp/branch/master/graph/badge.svg)](https://codecov.io/gh/arcanericky/totp)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com)

Expand All @@ -17,69 +17,69 @@ Every copy of your two-factor credentials increases your risk profile. Using thi

**Add TOTP secrets** to the TOTP configuration file with the `config add` option, specifying the name and secret value. Note the secret names are **case sensitive**.

```
$ totp config add mysecretname seed
```sh
totp config add mysecretname seed
```

**Generate TOTP codes** using the `totp` command to specify the secret name. Note that because `totp` reserves the use of the words `config` and `version`, don't use them to name a secret.

```
$ totp mysecretname
```sh
totp mysecretname
```

**List the secret entries** with the `config list` command.

```
$ totp config list
```sh
totp config list
```

**Update secret entries** using the `config update` command. Note that `config update` and `config add` are actually the same command and can be used interchangeably.

```
$ totp config update mysecretname newseed
```sh
totp config update mysecretname newseed
```

**Rename the secret entries** with the `config rename` command

```
$ totp config rename mysecretname mynewname
```sh
totp config rename mysecretname mynewname
```

**Delete secret entries** with the `config delete` command

```
$ totp config delete mynewname
```sh
totp config delete mynewname
```

**Remove all the secrets** and start over using the `config reset` command

```
$ totp config reset
```sh
totp config reset
```

**Use an ad-hoc secret** to generate a code by using the `--secret` option

```
$ totp --secret seed
```sh
totp --secret seed
```

**Continuous code output** can be generated with the `--follow` option.

```
$ totp --follow mysecretname
```sh
totp --follow mysecretname
```

**For help** on any of the above, use the `--help` option. Examples are

```
$ totp --help
$ totp config --help
```sh
totp --help
totp config --help
```

**Bash completion** can be enabled by using `config completion`.

```
$ . <(totp config completion)
```sh
. <(totp config completion)
```

## Using the Time Machine
Expand All @@ -90,7 +90,7 @@ The `--time` option takes an [RFC3339 formatted time string](https://tools.ietf.

Examples with `--time`:

```
```sh
$ date '+%FT%T%:z'
2019-06-01T19:58:47-05:00
$ totp --time $(date '+%FT%T%:z') --secret seed
Expand All @@ -103,7 +103,7 @@ The `--forward` and `--backward` options move the current time forward and backw

Examples with `--forward` and `--backward`

```
```sh
$ totp --time 2019-06-01T20:00:00-05:00 --backward 3m --secret seed
222296
$ totp --time 2019-06-01T20:00:00-05:00 --forward 30s --secret seed
Expand All @@ -112,8 +112,8 @@ $ totp --time 2019-06-01T20:00:00-05:00 --forward 30s --secret seed

The `--follow` option is also compatible with the time machine.

```
$ totp --time 2001-10-31T20:00:00-05:00 --follow --secret seed
```sh
totp --time 2001-10-31T20:00:00-05:00 --follow --secret seed
```

## Using the Stdio Option
Expand All @@ -129,19 +129,19 @@ Note the `--file` option can achieve the same results as this example. This is m

Create a collection

```
```sh
totp config add --stdio secretname myvalue < /dev/null > totp.json
```

View the collection

```
```sh
totp config list --stdio < totp.json
```

Generate a TOTP code

```
```sh
totp secretname --stdio < totp.json
```

Expand All @@ -150,36 +150,37 @@ totp secretname --stdio < totp.json
Using what was learned above, a contrived example for encrypting data with [GnuPG](https://gnupg.org/) follows.

Create an encrypted collection
```

```sh
totp config add --stdio secretname myvalue < /dev/null | \
gpg --batch --yes --passphrase mypassphrase --output totp-collection.gpg --symmetric
```

View the collection

```
```sh
gpg --quiet --batch --passphrase mypassphrase --decrypt totp-collection.gpg | \
totp config list --stdio
```

Add another secret

```
```sh
gpg --quiet --batch --passphrase mypassphrase --decrypt totp-collection.gpg | \
totp config add --stdio newname newvalue | \
gpg --batch --yes --passphrase mypassphrase --output totp-collection.gpg --symmetric
```

View the modified collection

```
```sh
gpg --quiet --batch --passphrase mypassphrase --decrypt totp-collection.gpg | \
totp config list --stdio
```

Generate a TOTP code

```
```sh
gpg --quiet --batch --passphrase mypassphrase --decrypt totp-collection.gpg | totp --stdio secretname
```

Expand All @@ -189,28 +190,28 @@ gpg --quiet --batch --passphrase mypassphrase --decrypt totp-collection.gpg | to

To build everything:

```
$ git clone https://github.com/arcanericky/totp.git
$ cd totp
$ make
```sh
git clone https://github.com/arcanericky/totp.git
cd totp
make
```

For unit tests and code coverage reports:

```
$ make test
```sh
make test
```

The coverage is output to `coverage.html`. Load it in browser for review. For example:

```
$ /opt/google/chrome/chrome file://$PWD/coverage.html
```sh
/opt/google/chrome/chrome file://$PWD/coverage.html
```

To build for a single platform (see the `Makefile` for the different targets)

```
$ make linux-amd64
```sh
make linux-amd64
```

See the `Makefile` for how to use the `go` command natively.
Expand All @@ -227,4 +228,4 @@ My [ga-cmd project](https://github.com/arcanericky/ga-cmd) is more popular than

## Credits

This utility uses the [otp package by pquerna](https://github.com/pquerna/otp). Without this library, I probably woudn't have bothered creating this.
This utility uses the [otp package by pquerna](https://github.com/pquerna/otp). Without this library, I probably wouldn't have bothered creating this.
2 changes: 1 addition & 1 deletion cmd/configdelete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestConfigDelete(t *testing.T) {
collectionFile.filename = "testcollection"
collectionFile.filename = "testcollection.json"

secretList := createTestData(t)

Expand Down
Loading

0 comments on commit 8153a99

Please sign in to comment.