Skip to content

Commit

Permalink
add support for auth keys
Browse files Browse the repository at this point in the history
  • Loading branch information
mutantmonkey committed Oct 12, 2015
1 parent 24f071f commit 9a5b672
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 @@ -2,6 +2,7 @@ package main

import (
"bufio"
"encoding/base64"
"encoding/json"
"flag"
"fmt"
Expand All @@ -22,6 +23,7 @@ import (
type Config struct {
Server string
Proxy string
AuthKey string
UploadLog string
}

Expand All @@ -33,6 +35,11 @@ type LinxJSON struct {
Size string
}

func createAuthHeader(authKey string) string {
const authPrefix = "Linx "
return authPrefix + base64.StdEncoding.EncodeToString([]byte(authKey))
}

func getDeleteKeys(config *Config) (keys map[string]string) {
keys = make(map[string]string)

Expand Down Expand Up @@ -108,6 +115,10 @@ func linx(config *Config, filepath string, ttl int, deleteKey string) {
req.Header.Add("Linx-Delete-Key", deleteKey)
}

if config.AuthKey != "" {
req.Header.Add("Authorization", createAuthHeader(config.AuthKey))
}

resp, err := client.Do(req)
if err != nil {
log.Fatalf("Failed to issue request: %v\n", err)
Expand Down Expand Up @@ -161,6 +172,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.AuthKey != "" {
req.Header.Add("Authorization", createAuthHeader(config.AuthKey))
}

resp, err := client.Do(req)
if err != nil {
log.Fatalf("Failed to issue request: %v\n", err)
Expand Down

0 comments on commit 9a5b672

Please sign in to comment.