-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* structure to be usable as a Go dependency * support release * add linting, testing * update key to be hex encoded when used via CLI * add cobra for CLI
- Loading branch information
1 parent
a0748b7
commit 06a50a5
Showing
19 changed files
with
369 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Lint | ||
|
||
on: | ||
push: | ||
pull_request: | ||
types: [opened, reopened] | ||
jobs: | ||
golangci: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.21' | ||
cache: false | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: v1.54 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: goreleaser | ||
|
||
on: | ||
push: | ||
tags: | ||
- '*' | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
go-release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- run: git fetch --force --tags | ||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version: stable | ||
- name: Make Build | ||
run: make build | ||
- uses: goreleaser/goreleaser-action@v4 | ||
with: | ||
distribution: goreleaser | ||
version: latest | ||
args: release --clean | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
pull_request: | ||
types: [opened, reopened] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 2 | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: '1.21' | ||
- name: Run tests | ||
run: go test -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
/node_modules | ||
/dist | ||
/.idea | ||
/precrypt | ||
/index.html | ||
/index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package cmd | ||
|
||
import ( | ||
"crypto/rand" | ||
"encoding/hex" | ||
"fmt" | ||
"github.com/richardjennings/precrypt/pkg/precrypt" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
var htmlFiles []string | ||
var cssFiles []string | ||
var jsFiles []string | ||
var key string | ||
|
||
var build = &cobra.Command{ | ||
Use: "", | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
var err error | ||
out := args[0] | ||
fh, err := os.OpenFile(out, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) | ||
defer func() { _ = fh.Close() }() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
opts := precrypt.RenderOptions{ | ||
HtmlFiles: htmlFiles, | ||
CssFiles: cssFiles, | ||
JsFiles: jsFiles, | ||
Out: fh, | ||
} | ||
if len(key) > 0 { | ||
opts.Key, err = hex.DecodeString(key) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} | ||
if len(key) == 0 { | ||
// generate key | ||
bytes := make([]byte, 32) | ||
if _, err := rand.Read(bytes); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
opts.Key = make([]byte, hex.EncodedLen(len(bytes))) | ||
hex.Encode(opts.Key, bytes) | ||
fmt.Println(string(opts.Key)) | ||
} | ||
if err := precrypt.Render(opts); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
build.Flags().StringArrayVar(&htmlFiles, "html", []string{}, "--html <file1.html>,<file2.html>") | ||
build.Flags().StringArrayVar(&cssFiles, "css", []string{}, "--css <file1.css>,<file2.css>") | ||
build.Flags().StringArrayVar(&jsFiles, "js", []string{}, "--js <file1.js>,<file2.js>") | ||
build.Flags().StringVar(&key, "key", "", "--key 32byteslong") | ||
} | ||
|
||
func Execute() { | ||
err := build.Execute() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
module github.com/richardjennings/precrypt | ||
|
||
go 1.21 | ||
|
||
require ( | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/spf13/cobra v1.8.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= | ||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= | ||
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= | ||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= | ||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,9 @@ | ||
package main | ||
|
||
import ( | ||
_ "embed" | ||
"encoding/json" | ||
"fmt" | ||
"github.com/richardjennings/precrypt/internal/precrypt" | ||
"os" | ||
"text/template" | ||
"github.com/richardjennings/precrypt/cmd" | ||
) | ||
|
||
//go:embed template/index.html | ||
var indexTemplate string | ||
|
||
//go:embed dist/main.js | ||
var loaderJs string | ||
|
||
//go:embed dist/style.css | ||
var loaderCss string | ||
|
||
//go:embed example/index.html | ||
var exampleHtml []byte | ||
|
||
//go:embed example/style.css | ||
var exampleCss []byte | ||
|
||
//go:embed example/index.js | ||
var exampleJs []byte | ||
|
||
func main() { | ||
key := os.Args[1] | ||
htmlEnc, err := precrypt.Encrypt(exampleHtml, []byte(key)) | ||
e(err) | ||
cssEnc, err := precrypt.Encrypt(exampleCss, []byte(key)) | ||
e(err) | ||
jsEnc, err := precrypt.Encrypt(exampleJs, []byte(key)) | ||
e(err) | ||
tmpl := template.Must(template.New("page").Parse(indexTemplate)) | ||
data, err := json.Marshal(map[string]interface{}{ | ||
"a": []string{string(htmlEnc)}, | ||
"b": []string{string(cssEnc)}, | ||
"c": []string{string(jsEnc)}, | ||
}) | ||
e(err) | ||
err = tmpl.Execute(os.Stdout, map[string]interface{}{"data": string(data), "js": loaderJs, "css": loaderCss}) | ||
e(err) | ||
} | ||
|
||
func e(err error) { | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
cmd.Execute() | ||
} |
File renamed without changes.
Oops, something went wrong.