Skip to content

Commit

Permalink
Switch to using API key from env
Browse files Browse the repository at this point in the history
  • Loading branch information
tomczoink committed Aug 3, 2021
1 parent 0927997 commit 896d466
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
26 changes: 18 additions & 8 deletions README.md
Expand Up @@ -9,19 +9,29 @@ Firstly you need to get an Ably API key. You can sign up for an account with [Ab
Now all you need to do is run the main go file, passing in the command line command you want to be run as a parameter! For example, to use a bash file `count.sh`, which is included in this repo's `examples` folder, just run:

```bash
~ $ ./ablyD --apikey=YOUR_API_KEY ./examples/bash/count.sh
~ $ ./ablyD ./examples/bash/count.sh
```

The program is now running, waiting for a message in the `command` channel in Ably to be sent. The message's data field should match the structure, with the value `start` for the message's name:
Make sure you've specified your [your API key](https://www.ably.com/accounts/any/apps/any/app_keys) in your environment, or by passing it in as `ABLYD_API_KEY=ABC123 ./ablyD ./examples/bash/count.sh`.

```json
{
"MessageID": "unique string value",
"Args": [ "some", "additional", "args", "for", "the", "programs" ]
}
The program is now running, waiting for a message in the `ablyd:command` channel in Ably to be sent. For example, to start a process with curl, you would send:

```bash
curl -X POST https://rest.ably.io/channels/ablyd:command/messages \
-u "${API_KEY}" \
-H 'Content-Type: application/json' \
--data \
'{
"name": "start",
"data": {
"MessageID": "unique string value",
"Args": [ "some", "additional", "args", "for", "the", "programs" ]
},
"format":"json"
}'
```

Once the server receives a message in the `command` channel, it will start up an instance of the program, using the `Args` you specify in the message as well. Once the program has started up, the server will send a message onto the `command` channel of structure:
Once the server receives a message in the `ablyd:command` channel, it will start up an instance of the program, using the `Args` you specify in the message as well. Once the program has started up, the server will send a message onto the `command` channel of structure:

```json
{
Expand Down
9 changes: 0 additions & 9 deletions config.go
Expand Up @@ -18,7 +18,6 @@ import (
type Config struct {
MaxForks int // Number of allowable concurrent forks
LogLevel libablyd.LogLevel
AblyAPIKey string
ServerID string
ChannelNamespace string
ChannelPrefix string // Ably channel prefix to use
Expand All @@ -36,7 +35,6 @@ func parseCommandLine() *Config {
versionFlag := flag.Bool("version", false, "Print version and exit")
logLevelFlag := flag.String("loglevel", "access", "Log level, one of: debug, trace, access, info, error, fatal")
maxForksFlag := flag.Int("maxforks", 20, "Max forks, zero means unlimited")
ablyApiKey := flag.String("apikey", "INSERT_API_KEY", "Ably API key")
channelNamespace := flag.String("namespace", "ablyd", "Ably Channel Namespace")
serverID := flag.String("serverid", xid.New().String(), "Unique ID for the server")

Expand All @@ -51,7 +49,6 @@ func parseCommandLine() *Config {
}
}

mainConfig.AblyAPIKey = *ablyApiKey
mainConfig.ServerID = *serverID
mainConfig.ChannelNamespace= *channelNamespace
mainConfig.ChannelPrefix = *channelNamespace + ":" + *serverID + ":"
Expand All @@ -75,12 +72,6 @@ func parseCommandLine() *Config {
os.Exit(0)
}

if mainConfig.AblyAPIKey == "INSERT_API_KEY" {
fmt.Printf("Please provide your Ably API key with -apikey=API_KEY\n")
ShortHelp()
os.Exit(1)
}

args := flag.Args()

if len(args) < 1 {
Expand Down
2 changes: 1 addition & 1 deletion examples/webhook/README.md
Expand Up @@ -12,7 +12,7 @@ Once you're done using the Rule, you can close it by closing this program with `

A simple series of steps to try this out would be:

* Start up an instance of AblyD from the base of the directory with `./ablyD --apikey=YOUR_ABLY_API _KEY./examples/bash/count.sh`. Replace `YOUR_ABLY_API_KEY` with [your API key](https://www.ably.com/accounts/any/apps/any/app_keys) from the Ably App Dashboard.
* Start up an instance of AblyD from the base of the directory with `./ablyD ./examples/bash/count.sh`. Make sure you've specified your [your API key](https://www.ably.com/accounts/any/apps/any/app_keys) in your environment, or by passing it in as `ABLYD_API_KEY=ABC123 ./ablyD ./examples/bash/count.sh`.
* Create a .env file in this folder with the required details
* [Create a requestbin endpoint](https://requestbin.com/) as a test endpoint, and add that to the .env file
* Run `npm install` then `node webhook.js`, and the above process should occur!
2 changes: 0 additions & 2 deletions help.go
Expand Up @@ -35,8 +35,6 @@ Options:
From most to least verbose:
debug, trace, access, info, error, fatal
--apikey=APIKEY Ably API key to use. REQUIRED
BSD license: Run '{{binary}} --license' for details.
`
short = `
Expand Down
3 changes: 2 additions & 1 deletion main.go
Expand Up @@ -8,6 +8,7 @@ package main
import (
"ablyD/libablyd"
"sync"
"os"

"github.com/ably/ably-go/ably"
"github.com/joho/godotenv"
Expand All @@ -21,7 +22,7 @@ func main() {
godotenv.Load()

client, err := ably.NewRealtime(
ably.WithKey(config.AblyAPIKey),
ably.WithKey(os.Getenv("ABLYD_API_KEY")),
ably.WithEchoMessages(false),
ably.WithClientID(config.ServerID))

Expand Down

0 comments on commit 896d466

Please sign in to comment.