Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: send full public-key file to htsget #9

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 9 additions & 26 deletions storage/htsget.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package storage

import (
"bufio"
"bytes"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -128,36 +128,24 @@ func htsgetUrl(url, useProtocol string) (updatedUrl string, token string) {
return
}

func htsgetHeader() string {
func htsgetHeaderJson() string {
ensureKeyFiles()

file, err := os.Open(publicKeyFile)
b, err := os.ReadFile(publicKeyFile)
if err != nil {
fmt.Println("Could not read", publicKeyFile, "file, which should exist:", err)
fmt.Println("[ERROR] Could not read", publicKeyFile,
"file, which should exist:", err)
panic(1)
}

publicKey := ""
scanner := bufio.NewScanner(file)
if scanner.Scan() { // Skip one header line.
if scanner.Scan() {
publicKey = scanner.Text() // The key is on the second line.
}
}
file.Close()

// HTTP headers to be encoded as JSON:
headers := make(map[string]string)

if publicKey == "" {
fmt.Println("[WARN] Could not read public key (second line) from", publicKeyFile, "file.")
} else {
headers["client-public-key"] = publicKey
}
headers["client-public-key"] = base64.StdEncoding.EncodeToString(b)

headersJson, err := json.Marshal(&headers)
if err != nil {
fmt.Println("Failed to format JSON-header for passing client-public-key:", err)
fmt.Println("[ERROR] Failed to format JSON-header for passing",
"client-public-key:", err)
panic(1)
}

Expand All @@ -173,7 +161,7 @@ func htsgetArgs(url, useProtocol string, decrypt bool) []string {
}

if decrypt {
cmdArgs = append(cmdArgs, "--headers", htsgetHeader())
cmdArgs = append(cmdArgs, "--headers", htsgetHeaderJson())
}

cmdArgs = append(cmdArgs, httpsUrl)
Expand Down Expand Up @@ -261,11 +249,6 @@ func cmdPipe(cmd1, cmd2 *exec.Cmd, destFilePath string) {
stderr2 := new(bytes.Buffer)
r, w := io.Pipe()

if err != nil {
fmt.Printf("[ERROR] failed to create OS pipe: %v", err)
return
}

cmd1.Stdout = w
cmd1.Stderr = stderr1

Expand Down