Skip to content

Commit b1ed418

Browse files
slavovojacekSlavo Vojacek
andauthored
feat: self-hosting (#29)
* feat: self-hosting * chore: update readme * chore: update readme * chore: clean deps * chore: update readme Co-authored-by: Slavo Vojacek <[email protected]>
1 parent a433954 commit b1ed418

File tree

8 files changed

+126
-188
lines changed

8 files changed

+126
-188
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
name: Set up Go
2323
uses: actions/setup-go@v2
2424
with:
25-
go-version: 1.16
25+
go-version: 1.17
2626
-
2727
name: Download dependencies
2828
run: go mod download

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
name: Set up Go
1919
uses: actions/setup-go@v2
2020
with:
21-
go-version: 1.16
21+
go-version: 1.17
2222
-
2323
name: Run GoReleaser
2424
uses: goreleaser/goreleaser-action@v2

README.md

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center">
2-
Please upgrade the CLI to <a href="https://github.com/sniptt-official/ots/releases/tag/v0.1.0">version 0.1.0</a>
2+
<b>Looking to self-host? Use <a href="https://github.com/sniptt-official/ots-aws">the official CDK construct</a></b>
33
</p>
44

55
<p align="center">
@@ -34,51 +34,75 @@
3434

3535
The recommended way to install `ots` on macOS is via Homebrew.
3636

37-
```sh
37+
```
3838
brew install ots
3939
```
4040

4141
### Go
4242

43-
```sh
43+
```
4444
go get -u github.com/sniptt-official/ots
4545
```
4646

47-
### Manual
48-
49-
Please refer to the [manual install](./docs/manual-install.md) doc.
50-
5147
## Usage
5248

5349
![render1628628123170](https://user-images.githubusercontent.com/778109/128932301-190388b3-171c-4e41-be5c-88ecf315beda.gif)
5450

5551
### Prompt
5652

57-
```sh
58-
$ ots new -x 2h
53+
```
54+
> ots new -x 2h
5955
Enter your secret:
6056
```
6157

6258
### Pipeline
6359

6460
You can also use pipes, for example
6561

66-
```sh
67-
$ pbpaste | ots new
62+
```
63+
pbpaste | ots new
6864
```
6965

7066
or
7167

72-
```sh
73-
$ cat .env | ots new
68+
```
69+
cat .env | ots new
7470
```
7571

7672
### Data residency
7773

7874
Use `--region` to choose where the secrets reside.
7975

80-
```sh
81-
$ ots new -x 24h --region eu-central-1
76+
```
77+
ots new -x 24h --region eu-central-1
78+
```
79+
80+
### Self-hosting
81+
82+
Please refer to [the official CDK construct](https://github.com/sniptt-official/ots-aws) for detailed instructions.
83+
84+
Grab your API Gateway URL, API key and configure `~/.ots.yaml` (or whatever you provide to `--config`):
85+
86+
```yaml
87+
apiUrl: https://YOUR_API_ID.execute-api.YOUR_REGION.amazonaws.com/prod/secrets
88+
apiKey: YOUR_API_KEY
89+
```
90+
91+
Use `ots` as before:
92+
93+
```
94+
> ots new -x 2h
95+
Using config file: /Users/xxx/.ots.yaml
96+
Enter your secret: ***
97+
Your secret is now available on the below URL.
98+
99+
https://my-ots-web-view.com/burn-secret?id=xxx&ref=ots-cli&region=us-east-1&v=debug#xxx
100+
101+
You should only share this URL with the intended recipient.
102+
103+
Please note that once retrieved, the secret will no longer
104+
be available for viewing. If not viewed, the secret will
105+
automatically expire at approximately xx xxx xxxx xx:xx:xx.
82106
```
83107
84108
## FAQs

api/client/client.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,26 @@ type CreateOtsRes struct {
4242
}
4343

4444
func CreateOts(encryptedBytes []byte, expiresIn time.Duration, region string) (*CreateOtsRes, error) {
45-
baseUrl := viper.GetString("base_url")
45+
defaultApiUrl := fmt.Sprintf("https://ots.%s.api.sniptt.com/secrets", region)
4646

47-
reqUrl := url.URL{
48-
Scheme: "https",
49-
Host: fmt.Sprintf("ots.%s.%s", region, baseUrl),
50-
Path: "secrets",
47+
// Fetch user configuration (for self-hosted)
48+
viper.SetDefault("apiUrl", defaultApiUrl)
49+
apiUrl := viper.GetString("apiUrl")
50+
apiKey := viper.GetString("apiKey")
51+
52+
// Build the request
53+
reqUrl, err := url.Parse(apiUrl)
54+
if err != nil {
55+
return nil, err
5156
}
5257

5358
reqBody := &CreateOtsReq{
5459
EncryptedBytes: base64.StdEncoding.EncodeToString(encryptedBytes),
5560
ExpiresIn: uint32(expiresIn.Seconds()),
5661
}
5762

58-
resBody := &CreateOtsRes{}
59-
6063
payloadBuf := new(bytes.Buffer)
61-
err := json.NewEncoder(payloadBuf).Encode(reqBody)
64+
err = json.NewEncoder(payloadBuf).Encode(reqBody)
6265
if err != nil {
6366
return nil, err
6467
}
@@ -74,12 +77,21 @@ func CreateOts(encryptedBytes []byte, expiresIn time.Duration, region string) (*
7477
req.Header.Add("X-Client-Name", "ots-cli")
7578
req.Header.Add("X-Client-Version", build.Version)
7679

80+
// Add optional authentication (for self-hosted)
81+
if apiKey != "" {
82+
req.Header.Add("X-Api-Key", apiKey)
83+
}
84+
7785
res, err := client.Do(req)
7886
if err != nil {
7987
return nil, err
8088
}
89+
8190
defer res.Body.Close()
8291

92+
// Build the response
93+
resBody := &CreateOtsRes{}
94+
8395
err = decodeJSON(res, resBody)
8496
if err != nil {
8597
return nil, err

build/build.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ package build
1717

1818
// Will be changed at build time via -ldflags
1919
var Version = "debug"
20-
var BaseUrl = "api.sniptt.com"

cmd/root.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ func initConfig() {
6161
viper.AddConfigPath(home)
6262
viper.SetConfigType("yaml")
6363
viper.SetConfigName(".ots")
64-
viper.SetDefault("base_url", build.BaseUrl)
6564
}
6665

6766
// Read in environment variables that match.

go.mod

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
module github.com/sniptt-official/ots
22

3-
go 1.16
3+
go 1.17
44

55
require (
6-
github.com/spf13/cobra v1.2.1
7-
github.com/spf13/viper v1.8.1
8-
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1
6+
github.com/spf13/cobra v1.4.0
7+
github.com/spf13/viper v1.10.1
8+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
9+
)
10+
11+
require (
12+
github.com/fsnotify/fsnotify v1.5.1 // indirect
13+
github.com/hashicorp/hcl v1.0.0 // indirect
14+
github.com/inconshreveable/mousetrap v1.0.0 // indirect
15+
github.com/magiconair/properties v1.8.6 // indirect
16+
github.com/mitchellh/mapstructure v1.4.3 // indirect
17+
github.com/pelletier/go-toml v1.9.4 // indirect
18+
github.com/spf13/afero v1.8.2 // indirect
19+
github.com/spf13/cast v1.4.1 // indirect
20+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
21+
github.com/spf13/pflag v1.0.5 // indirect
22+
github.com/subosito/gotenv v1.2.0 // indirect
23+
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
24+
golang.org/x/text v0.3.7 // indirect
25+
gopkg.in/ini.v1 v1.66.4 // indirect
26+
gopkg.in/yaml.v2 v2.4.0 // indirect
927
)

0 commit comments

Comments
 (0)