From aa31924e2c1b4f66bc975cf185e2868b74a1e89e Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 21 Jul 2016 18:40:55 +0200 Subject: read CBA API Key on startup 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) -- cgit v0.10.2