hookdeck-cli 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/.github/workflows/publish-npm.yml +19 -0
  2. package/.github/workflows/release.yml +85 -0
  3. package/.goreleaser/linux.yml +68 -0
  4. package/.goreleaser/mac.yml +69 -0
  5. package/.goreleaser/windows.yml +52 -0
  6. package/.tool-versions +1 -0
  7. package/Dockerfile +5 -0
  8. package/LICENSE +202 -0
  9. package/README.md +223 -0
  10. package/docs/cli-demo.gif +0 -0
  11. package/go.mod +58 -0
  12. package/go.sum +444 -0
  13. package/main.go +22 -0
  14. package/package.json +30 -0
  15. package/pkg/ansi/ansi.go +208 -0
  16. package/pkg/ansi/init_windows.go +23 -0
  17. package/pkg/cmd/completion.go +128 -0
  18. package/pkg/cmd/listen.go +114 -0
  19. package/pkg/cmd/login.go +37 -0
  20. package/pkg/cmd/logout.go +35 -0
  21. package/pkg/cmd/root.go +112 -0
  22. package/pkg/cmd/version.go +25 -0
  23. package/pkg/cmd/whoami.go +50 -0
  24. package/pkg/config/config.go +326 -0
  25. package/pkg/config/config_test.go +20 -0
  26. package/pkg/config/profile.go +296 -0
  27. package/pkg/config/profile_test.go +109 -0
  28. package/pkg/hookdeck/client.go +210 -0
  29. package/pkg/hookdeck/client_test.go +203 -0
  30. package/pkg/hookdeck/connections.go +61 -0
  31. package/pkg/hookdeck/destinations.go +14 -0
  32. package/pkg/hookdeck/guest.go +37 -0
  33. package/pkg/hookdeck/session.go +37 -0
  34. package/pkg/hookdeck/sources.go +73 -0
  35. package/pkg/hookdeck/telemetry.go +84 -0
  36. package/pkg/hookdeck/telemetry_test.go +35 -0
  37. package/pkg/hookdeck/verbosetransport.go +82 -0
  38. package/pkg/hookdeck/verbosetransport_test.go +47 -0
  39. package/pkg/listen/connection.go +91 -0
  40. package/pkg/listen/listen.go +140 -0
  41. package/pkg/listen/source.go +84 -0
  42. package/pkg/login/client_login.go +209 -0
  43. package/pkg/login/interactive_login.go +180 -0
  44. package/pkg/login/login_message.go +24 -0
  45. package/pkg/login/poll.go +78 -0
  46. package/pkg/login/validate.go +52 -0
  47. package/pkg/logout/logout.go +48 -0
  48. package/pkg/open/open.go +50 -0
  49. package/pkg/proxy/proxy.go +433 -0
  50. package/pkg/useragent/uname_unix.go +25 -0
  51. package/pkg/useragent/uname_unix_test.go +24 -0
  52. package/pkg/useragent/uname_windows.go +9 -0
  53. package/pkg/useragent/useragent.go +74 -0
  54. package/pkg/validators/cmds.go +71 -0
  55. package/pkg/validators/validate.go +144 -0
  56. package/pkg/version/version.go +58 -0
  57. package/pkg/version/version_test.go +15 -0
  58. package/pkg/websocket/attempt_messages.go +47 -0
  59. package/pkg/websocket/client.go +525 -0
  60. package/pkg/websocket/connection_messages.go +11 -0
  61. package/pkg/websocket/messages.go +64 -0
package/README.md ADDED
@@ -0,0 +1,223 @@
1
+ # Hookdeck CLI
2
+
3
+ [slack-badge]: https://img.shields.io/badge/Slack-Hookdeck%20Developers-blue?logo=slack
4
+
5
+ [![slack-badge]](https://join.slack.com/t/hookdeckdevelopers/shared_invite/zt-yw7hlyzp-EQuO3QvdiBlH9Tz2KZg5MQ)
6
+
7
+ Using the Hookdeck CLI, you can forward your webhooks to your local webserver. We offer unlimited **free** and **permanent** webhook URLs. Your webhook history is preserved between session and can be viewed, replayed or used for testing by you and your teammates.
8
+
9
+ Hookdeck CLI is compatible with most of Hookdeck features such as filtering and fan-out delivery. You can use Hookdeck CLI to develop or test your webhook integration code locally.
10
+
11
+ Although it uses a different approach and philosophy, it's a replacement for ngrok and alternative HTTP tunnel solutions.
12
+
13
+ Hookdeck for development is completely free, and we monetize the platform with our Production offering.
14
+
15
+ For a complete reference, see the [CLI reference](https://hookdeck.com/cli)
16
+
17
+ ![demo](docs/cli-demo.gif)
18
+
19
+ ## Installation
20
+
21
+ Hookdeck CLI is available for macOS, Windows, and Linux for distros like Ubuntu, Debian, RedHat and CentOS.
22
+
23
+ ### macOS
24
+
25
+ Hookdeck CLI is available on macOS via [Homebrew](https://brew.sh/):
26
+
27
+ ```sh
28
+ brew install hookdeck/hookdeck/hookdeck
29
+ ```
30
+
31
+ ### Windows
32
+
33
+ Hookdeck CLI is available on Windows via the [Scoop](https://scoop.sh/) package manager:
34
+
35
+ ```sh
36
+ scoop bucket add hookdeck https://github.com/hookdeck/scoop-hookdeck-cli.git
37
+ scoop install hookdeck
38
+ ```
39
+
40
+ ### Linux Or Without package managers
41
+
42
+ To install the Hookdeck CLI on Linux without a package manager:
43
+
44
+ 1. Download the latest linux tar.gz file from https://github.com/hookdeck/hookdeck-cli/releases/latest
45
+ 2. Unzip the file: tar -xvf stripe_X.X.X_linux_x86_64.tar.gz
46
+ 3. Run the executable: ./hookdeck
47
+
48
+ ### Docker
49
+
50
+ The CLI is also available as a Docker image: [`hookdeck/hookdeck-cli`](https://hub.docker.com/r/hookdeck/hookdeck-cli).
51
+
52
+ ```sh
53
+ docker run --rm -it hookdeck/hookdeck-cli version
54
+ hookdeck version x.y.z (beta)
55
+ ```
56
+
57
+ If you want to login to your Hookdeck account with the CLI and persist
58
+ credentials, you can bind mount the `~/.config/hookdeck` directory:
59
+
60
+ ```sh
61
+ docker run --rm -it -v $HOME/.config/hookdeck:/root/.config/hookdeck hookdeck/hookdeck-cli login
62
+ ```
63
+
64
+ Then you can listen on any of your sources. Don't forget to use
65
+ `host.docker.internal` to reach a port on your host machine, otherwise
66
+ that port will not be accessible from `localhost` inside the container.
67
+
68
+ ```sh
69
+ docker run --rm -it -v $HOME/.config/hookdeck:/root/.config/hookdeck hookdeck/hookdeck-cli listen http://host.docker.internal:1234
70
+ ```
71
+
72
+ ## Usage
73
+
74
+ Installing the CLI provides access to the `hookdeck` command.
75
+
76
+ ```sh-session
77
+ hookdeck [command]
78
+
79
+ # Run `--help` for detailed information about CLI commands
80
+ hookdeck [command] help
81
+ ```
82
+
83
+ ## Commands
84
+
85
+ ### Login
86
+
87
+ Login with your Hookdeck account.
88
+
89
+ ```sh-session
90
+ hookdeck login
91
+ ```
92
+
93
+ > Login is optional, if you do not login a temporary guest account will be created for you when you run other commands.
94
+
95
+ ### Listen
96
+
97
+ Start a session to forward your webhooks to an HTTP server.
98
+
99
+ ```sh-session
100
+ hookdeck listen <port-or-URL> <source-alias?> <connection-query?>
101
+ ```
102
+
103
+ Hookdeck works by routing webhooks receive for a given `source` (ie: Shopify, Github, etc.) to its defined `destination` by connecting them with a `connection` to a `destination`. The CLI allows you to receive webhooks for any given connection and forward them to your localhost at the specified port or any valid URL.
104
+
105
+ Each `source` is assigned a Webhook URL, which you can use to receive webhooks. When starting with a fresh account, the CLI will prompt you to create your first source. Each CLI process can listen to one source at a time.
106
+
107
+ Contrarily to ngrok, **Hookdeck does not allow to append a path to your Webhook URL**. Instead, the routing is done within Hookdeck configuration. This means you will also be prompted to specify your `destination` path, and you can have as many as you want per `source`.
108
+
109
+ > The `port-or-URL` param is mandatory, webhooks will be forwarded to http://localhost:$PORT/$DESTINATION_PATH when inputing a valid port or your provided URL.
110
+
111
+ #### Listen to all your connections for a given source
112
+
113
+ The second param, `source-alias` is used to select a specific source to listen on. By default, the CLI will start listening on all eligible connections for that source.
114
+
115
+ ```sh-session
116
+ $ hookdeck listen 3000 shopify
117
+
118
+ 👉 Inspect and replay webhooks: https://dashboard.hookdeck.com/cli/events
119
+
120
+ Shopify Source
121
+ 🔌 Webhook URL: https://events.hookdeck.com/e/src_DAjaFWyyZXsFdZrTOKpuHnOH
122
+
123
+ Connections
124
+ Inventory Service forwarding to /webhooks/shopify/inventory
125
+ Orders Service forwarding to /webhooks/shopify/orders
126
+
127
+
128
+ ⣾ Getting ready...
129
+
130
+ ```
131
+
132
+ #### Listen to a subset of connection
133
+
134
+ The 3rd param, `connection-query` can be used to filter the list of connections the CLI will listen to. The connection query can either be the `connection` `alias` or the `path`
135
+
136
+ ```sh-session
137
+ $ hookdeck listen 3000 shopify orders
138
+
139
+ 👉 Inspect and replay webhooks: https://dashboard.hookdeck.com/cli/events
140
+
141
+ Shopify Source
142
+ 🔌 Webhook URL: https://events.hookdeck.com/e/src_DAjaFWyyZXsFdZrTOKpuHnOH
143
+
144
+ Connections
145
+ Inventory Service forwarding to /webhooks/shopify/inventory
146
+
147
+
148
+ ⣾ Getting ready...
149
+
150
+ ```
151
+
152
+ #### Viewing and interacting with your webhooks
153
+
154
+ Webhooks logs for your CLI can be found at https://dashboard.hookdeck.com/cli/events. Events can be replayed or saved at any time.
155
+
156
+ ### Logout
157
+
158
+ Logout of your Hookdeck account and clear your stored credentials.
159
+
160
+ ```sh-session
161
+ hookdeck logout
162
+ ```
163
+
164
+ ### Skip SSL validation
165
+
166
+ If you are developing on an SSL destination, and are using a self-signed certificate, you can skip the SSL validation by using the flag `--insecure`.
167
+ You have to specify the full URL with the protocol when using this flag.
168
+
169
+ **This is dangerous, and should only be used in development scenarios, and for desitnations that you trust.**
170
+
171
+ ```sh-session
172
+ hookdeck --insecure listen https://<url-or-url:port>/
173
+ ```
174
+
175
+ ### Version
176
+
177
+ Print your CLI version and whether or not a new version is available.
178
+
179
+ ```sh-session
180
+ hookdeck version
181
+ ```
182
+
183
+ ### Completion
184
+
185
+ Configure auto-completion for Hookdeck CLI. It is run on install when using Homebrew or Scoop. You can optionally run this command when using the binaries directly or without a package manager.
186
+
187
+ ```sh-session
188
+ hookdeck completion
189
+ ```
190
+
191
+ ## Developing
192
+
193
+ Build from source by running:
194
+
195
+ ```sh
196
+ go build
197
+ ```
198
+
199
+ ### Testing against a local API
200
+
201
+ When testing against a non-production Hookdeck API, you can use the
202
+ `--api-base` and `--ws-base` flags, e.g.:
203
+
204
+ ```sh
205
+ ./hookdeck-cli --api-base http://localhost:9000 --ws-base ws://localhost:3003 listen 1234
206
+ ```
207
+
208
+ Also if running in Docker, the equivalent command would be:
209
+
210
+ ```sh
211
+ docker run --rm -it \
212
+ -v $HOME/.config/hookdeck:/root/.config/hookdeck hookdeck/hookdeck-cli \
213
+ --api-base http://host.docker.internal:9000 \
214
+ --ws-base ws://host.docker.internal:3003 \
215
+ listen \
216
+ http://host.docker.internal:1234
217
+ ```
218
+
219
+ ## License
220
+
221
+ Copyright (c) Hookdeck. All rights reserved.
222
+
223
+ Licensed under the [Apache License 2.0 license](blob/master/LICENSE).
Binary file
package/go.mod ADDED
@@ -0,0 +1,58 @@
1
+ module github.com/hookdeck/hookdeck-cli
2
+
3
+ go 1.18
4
+
5
+ require (
6
+ github.com/AlecAivazis/survey/v2 v2.2.9
7
+ github.com/BurntSushi/toml v0.3.1
8
+ github.com/briandowns/spinner v1.11.1
9
+ github.com/google/go-github/v28 v28.1.1
10
+ github.com/gorilla/websocket v1.4.2
11
+ github.com/gosimple/slug v1.9.0
12
+ github.com/logrusorgru/aurora v2.0.3+incompatible
13
+ github.com/mitchellh/go-homedir v1.1.0
14
+ github.com/sirupsen/logrus v1.8.0
15
+ github.com/spf13/cobra v1.0.0
16
+ github.com/spf13/viper v1.7.1
17
+ github.com/stretchr/testify v1.7.0
18
+ github.com/tidwall/pretty v1.0.2
19
+ github.com/x-cray/logrus-prefixed-formatter v0.5.2
20
+ golang.org/x/sys v0.0.0-20201223074533-0d417f636930
21
+ golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d
22
+ )
23
+
24
+ require (
25
+ github.com/creack/pty v1.1.9 // indirect
26
+ github.com/davecgh/go-spew v1.1.1 // indirect
27
+ github.com/fatih/color v1.9.0 // indirect
28
+ github.com/fsnotify/fsnotify v1.4.9 // indirect
29
+ github.com/google/go-querystring v1.0.0 // indirect
30
+ github.com/hashicorp/hcl v1.0.0 // indirect
31
+ github.com/inconshreveable/mousetrap v1.0.0 // indirect
32
+ github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
33
+ github.com/kr/pty v1.1.8 // indirect
34
+ github.com/kr/text v0.2.0 // indirect
35
+ github.com/magefile/mage v1.10.0 // indirect
36
+ github.com/magiconair/properties v1.8.3 // indirect
37
+ github.com/mattn/go-colorable v0.1.7 // indirect
38
+ github.com/mattn/go-isatty v0.0.12 // indirect
39
+ github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
40
+ github.com/mitchellh/mapstructure v1.3.3 // indirect
41
+ github.com/onsi/ginkgo v1.14.1 // indirect
42
+ github.com/onsi/gomega v1.10.1 // indirect
43
+ github.com/pelletier/go-toml v1.8.1 // indirect
44
+ github.com/pmezard/go-difflib v1.0.0 // indirect
45
+ github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be // indirect
46
+ github.com/spf13/afero v1.4.0 // indirect
47
+ github.com/spf13/cast v1.3.1 // indirect
48
+ github.com/spf13/jwalterweatherman v1.1.0 // indirect
49
+ github.com/spf13/pflag v1.0.5 // indirect
50
+ github.com/subosito/gotenv v1.2.0 // indirect
51
+ golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
52
+ golang.org/x/net v0.0.0-20200904194848-62affa334b73 // indirect
53
+ golang.org/x/text v0.3.3 // indirect
54
+ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
55
+ gopkg.in/ini.v1 v1.61.0 // indirect
56
+ gopkg.in/yaml.v2 v2.3.0 // indirect
57
+ gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
58
+ )