Skip to content

Commit

Permalink
Add support for API keys
Browse files Browse the repository at this point in the history
  • Loading branch information
mutantmonkey committed Dec 18, 2018
1 parent 4874122 commit a54182d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions linx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

type Config struct {
Server string
ApiKey string
Proxy string
UploadLog string
}
Expand Down Expand Up @@ -94,6 +95,9 @@ func linx(config *Config, filename string, size int64, f io.Reader, ttl int, del
req.Header.Add("Linx-Expiry", strconv.Itoa(ttl))
req.Header.Add("Linx-Randomize", "yes")

if config.ApiKey != "" {
req.Header.Set("Linx-Api-Key", config.ApiKey)
}
if deleteKey != "" {
req.Header.Add("Linx-Delete-Key", deleteKey)
}
Expand Down Expand Up @@ -162,6 +166,10 @@ func unlinx(config *Config, url string, deleteKey string) bool {
req.Header.Add("User-Agent", "golinx")
req.Header.Add("Linx-Delete-Key", deleteKey)

if config.ApiKey != "" {
req.Header.Set("Linx-Api-Key", config.ApiKey)
}

resp, err := client.Do(req)
if err != nil {
log.Fatalf("Failed to issue request: %v\n", err)
Expand All @@ -180,6 +188,7 @@ func unlinx(config *Config, url string, deleteKey string) bool {
func main() {
config := &Config{}
var flags struct {
apiKey string
deleteKey string
deleteMode bool
ttl int
Expand All @@ -196,6 +205,8 @@ func main() {
defaultConfigPath = ""
}

flag.StringVar(&flags.apiKey, "apikey", "",
"The API key to use to access the Linx instance (optional)")
flag.StringVar(&flags.deleteKey, "deletekey", "",
"The delete key to use for uploading or deleting a file")
flag.BoolVar(&flags.deleteMode, "d", false,
Expand Down Expand Up @@ -227,6 +238,10 @@ func main() {
config.Server = flags.server
}

if flags.apiKey != "" {
config.ApiKey = flags.apiKey
}

if flags.proxy != "" {
config.Proxy = flags.proxy
}
Expand Down

0 comments on commit a54182d

Please sign in to comment.