Added fix to retrieve correct s3 urls (#2465)
* Added fix to retrieve correct s3 urls * Fixes to S3 url * Squashing commits * Fixing if conditions for storagetype in geturl
This commit is contained in:
@@ -61,15 +61,12 @@ func (opts *GetURLSubCommand) do(input cli.Input) error {
|
|||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return fmt.Errorf("Error getting URL. Exited with Status: %v", resp.Status)
|
return fmt.Errorf("Error getting URL. Exited with Status: %s", resp.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
archiveURL, err := url.Parse(resp.Header.Get("X-FISSION-ARCHIVEURL"))
|
storageType := resp.Header.Get("X-FISSION-STORAGETYPE")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if archiveURL.Scheme == "file" {
|
if storageType == "local" {
|
||||||
storageSvc, err := opts.Client().V1().Misc().GetSvcURL("application=fission-storage")
|
storageSvc, err := opts.Client().V1().Misc().GetSvcURL("application=fission-storage")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -77,8 +74,10 @@ func (opts *GetURLSubCommand) do(input cli.Input) error {
|
|||||||
storagesvcURL := "http://" + storageSvc
|
storagesvcURL := "http://" + storageSvc
|
||||||
client := storagesvcClient.MakeClient(storagesvcURL)
|
client := storagesvcClient.MakeClient(storagesvcURL)
|
||||||
fmt.Printf("URL: %s", client.GetUrl(archiveID))
|
fmt.Printf("URL: %s", client.GetUrl(archiveID))
|
||||||
} else {
|
} else if storageType == "s3" {
|
||||||
fmt.Printf("URL: %s", archiveURL.String())
|
storageBucket := resp.Header.Get("X-FISSION-BUCKET")
|
||||||
|
s3url := fmt.Sprintf("https://%s.s3.amazonaws.com/%s", storageBucket, archiveID)
|
||||||
|
fmt.Printf("URL: %s", s3url)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -231,19 +231,23 @@ func (ss *StorageService) downloadHandler(w http.ResponseWriter, r *http.Request
|
|||||||
|
|
||||||
func (ss *StorageService) infoHandler(w http.ResponseWriter, r *http.Request) {
|
func (ss *StorageService) infoHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
fileId, err := ss.getIdFromRequest(r)
|
fileID, err := ss.getIdFromRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
itemURL, err := ss.storageClient.getURL(fileId)
|
_, err = ss.storageClient.container.Item(fileID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusNotFound)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Add("X-FISSION-ARCHIVEURL", itemURL.String())
|
storageType := ss.storageClient.config.storage.getStorageType()
|
||||||
|
if storageType == StorageTypeS3 {
|
||||||
|
w.Header().Add("X-FISSION-BUCKET", ss.storageClient.config.storage.getContainerName())
|
||||||
|
}
|
||||||
|
w.Header().Add("X-FISSION-STORAGETYPE", string(storageType))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *StorageService) healthHandler(w http.ResponseWriter, r *http.Request) {
|
func (ss *StorageService) healthHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/url"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -183,18 +182,6 @@ func (client *StowClient) removeFileByID(itemID string) error {
|
|||||||
return client.container.RemoveItem(itemID)
|
return client.container.RemoveItem(itemID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *StowClient) getURL(itemID string) (*url.URL, error) {
|
|
||||||
item, err := client.container.Item(itemID)
|
|
||||||
if err != nil {
|
|
||||||
if err == stow.ErrNotFound {
|
|
||||||
return nil, ErrNotFound
|
|
||||||
} else {
|
|
||||||
return nil, ErrRetrievingItem
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return item.URL(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (client *StowClient) getFileSize(itemID string) (int64, error) {
|
func (client *StowClient) getFileSize(itemID string) (int64, error) {
|
||||||
item, err := client.container.Item(itemID)
|
item, err := client.container.Item(itemID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user