summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-07-21 16:40:55 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-07-21 16:40:55 (GMT)
commitaa31924e2c1b4f66bc975cf185e2868b74a1e89e (patch)
treead2c94b8c3664a9564794869fc3ccedb248ebaa9
parentbb072813ee52a605cc44d424ec1d037cbaee76a8 (diff)
read CBA API Key on startup
-rw-r--r--rhimport/core.go19
-rw-r--r--rhimport/fetcher.go21
2 files changed, 27 insertions, 13 deletions
diff --git a/rhimport/core.go b/rhimport/core.go
index 67d46a4..ec184bb 100644
--- a/rhimport/core.go
+++ b/rhimport/core.go
@@ -25,11 +25,13 @@
package rhimport
import (
+ "bufio"
"fmt"
"io/ioutil"
"log"
"os"
"path"
+ "strings"
"code.helsinki.at/rhrd-go/rddb"
"github.com/andelf/go-curl"
@@ -45,18 +47,29 @@ const (
ARCHIV_HOST = "archiv.helsinki.at"
ARCHIV_USER = "rhimport"
ARCHIV_BASE_PATH = "/srv/archiv"
+
+ CBA_API_KEY_FILE = "/etc/cba-api.key"
)
var (
- bool2str = map[bool]string{false: "0", true: "1"}
- rhl = log.New(os.Stderr, "[rhimport]\t", log.LstdFlags)
- rhdl = log.New(ioutil.Discard, "[rhimport-dbg]\t", log.LstdFlags)
+ bool2str = map[bool]string{false: "0", true: "1"}
+ rhl = log.New(os.Stderr, "[rhimport]\t", log.LstdFlags)
+ rhdl = log.New(ioutil.Discard, "[rhimport-dbg]\t", log.LstdFlags)
+ cba_api_key = ""
)
func init() {
if _, exists := os.LookupEnv("RHIMPORT_DEBUG"); exists {
rhdl.SetOutput(os.Stderr)
}
+
+ key_file, err := os.Open(CBA_API_KEY_FILE)
+ if err == nil {
+ defer key_file.Close()
+ data, _ := bufio.NewReader(key_file).ReadString('\n')
+ cba_api_key = strings.TrimSpace(string(data))
+ }
+
curl.GlobalInit(curl.GLOBAL_ALL)
fetcherInit()
}
diff --git a/rhimport/fetcher.go b/rhimport/fetcher.go
index 9170a86..2264f30 100644
--- a/rhimport/fetcher.go
+++ b/rhimport/fetcher.go
@@ -136,6 +136,7 @@ func checkYoutubeDL(ctx *Context, res *Result, uri *url.URL) *YoutubeDLInfo {
var stderr, stdout bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
+ cmd.Env = append(os.Environ(), "CBA_API_KEY="+cba_api_key)
done := make(chan *YoutubeDLInfo)
go func() {
@@ -208,18 +209,18 @@ func fetchFileCurl(ctx *Context, res *Result, uri *url.URL) (err error) {
} else {
cbdata.remotename = info.Title + "." + info.Ext
}
- }
- switch strings.ToLower(info.Extractor) {
- case "generic":
- case "dropbox":
- default:
- ctx.Title = info.ExtractorKey + ": " + info.Title
- if info.Title == "" {
- ctx.Title += info.ID
+ switch strings.ToLower(info.Extractor) {
+ case "generic":
+ case "dropbox":
+ default:
+ ctx.Title = info.ExtractorKey + ": " + info.Title
+ if info.Title == "" {
+ ctx.Title += info.ID
+ }
+ cbdata.metadata = make(map[string]string)
+ cbdata.metadata["TITLE"] = ctx.Title
}
- cbdata.metadata = make(map[string]string)
- cbdata.metadata["TITLE"] = ctx.Title
}
easy.Setopt(curl.OPT_HEADERFUNCTION, curlHeaderCallback)