mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Removed unused updating code and bmclib dependency and other minor changes
This commit is contained in:
parent
9b3c21a20a
commit
0922bbf5f9
5 changed files with 33 additions and 149 deletions
|
|
@ -29,9 +29,9 @@ func LoadAccessToken(path string) (string, error) {
|
|||
}
|
||||
|
||||
// TODO: try to load token from config
|
||||
testToken = viper.GetString("access_token")
|
||||
testToken = viper.GetString("access-token")
|
||||
if testToken != "" {
|
||||
return testToken, nil
|
||||
}
|
||||
return "", fmt.Errorf("failed toload token from environment variable, file, or config")
|
||||
return "", fmt.Errorf("failed to load token from environment variable, file, or config")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,22 @@ import (
|
|||
"net/http"
|
||||
)
|
||||
|
||||
// HTTP aliases for readibility
|
||||
type HTTPHeader map[string]string
|
||||
type HTTPBody []byte
|
||||
|
||||
func (h HTTPHeader) Authorization(accessToken string) HTTPHeader {
|
||||
if accessToken != "" {
|
||||
h["Authorization"] = fmt.Sprintf("Bearer %s", accessToken)
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
func (h HTTPHeader) ContentType(contentType string) HTTPHeader {
|
||||
h["Content-Type"] = contentType
|
||||
return h
|
||||
}
|
||||
|
||||
// GetNextIP() returns the next IP address, but does not account
|
||||
// for net masks.
|
||||
func GetNextIP(ip *net.IP, inc uint) *net.IP {
|
||||
|
|
@ -35,7 +51,7 @@ func GetNextIP(ip *net.IP, inc uint) *net.IP {
|
|||
//
|
||||
// Returns a HTTP response object, response body as byte array, and any
|
||||
// error that may have occurred with making the request.
|
||||
func MakeRequest(client *http.Client, url string, httpMethod string, body []byte, headers map[string]string) (*http.Response, []byte, error) {
|
||||
func MakeRequest(client *http.Client, url string, httpMethod string, body HTTPBody, header HTTPHeader) (*http.Response, HTTPBody, error) {
|
||||
// use defaults if no client provided
|
||||
if client == nil {
|
||||
client = http.DefaultClient
|
||||
|
|
@ -48,7 +64,7 @@ func MakeRequest(client *http.Client, url string, httpMethod string, body []byte
|
|||
return nil, nil, fmt.Errorf("failed to create new HTTP request: %v", err)
|
||||
}
|
||||
req.Header.Add("User-Agent", "magellan")
|
||||
for k, v := range headers {
|
||||
for k, v := range header {
|
||||
req.Header.Add(k, v)
|
||||
}
|
||||
res, err := client.Do(req)
|
||||
|
|
|
|||
|
|
@ -40,31 +40,34 @@ func SplitPathForViper(path string) (string, string, string) {
|
|||
}
|
||||
|
||||
// MakeOutputDirectory() creates a new directory at the path argument if
|
||||
// the path does not exist
|
||||
// the path does not exist.
|
||||
//
|
||||
// Returns the final path that was created if no errors occurred. Otherwise,
|
||||
// it returns an empty string with an error.
|
||||
//
|
||||
// TODO: Refactor this function for hive partitioning or possibly move into
|
||||
// the logging package.
|
||||
// TODO: Add an option to force overwriting the path.
|
||||
func MakeOutputDirectory(path string) (string, error) {
|
||||
func MakeOutputDirectory(path string, overwrite bool) (string, error) {
|
||||
// get the current data + time using Go's stupid formatting
|
||||
t := time.Now()
|
||||
dirname := t.Format("2006-01-01 15:04:05")
|
||||
dirname := t.Format("2006-01-01")
|
||||
final := path + "/" + dirname
|
||||
|
||||
// check if path is valid and directory
|
||||
pathExists, err := PathExists(final)
|
||||
if err != nil {
|
||||
return final, fmt.Errorf("failed to check for existing path: %v", err)
|
||||
return "", fmt.Errorf("failed to check for existing path: %v", err)
|
||||
}
|
||||
if pathExists {
|
||||
if pathExists && !overwrite {
|
||||
// make sure it is directory with 0o644 permissions
|
||||
return final, fmt.Errorf("found existing path: %v", final)
|
||||
return "", fmt.Errorf("found existing path: %v", final)
|
||||
}
|
||||
|
||||
// create directory with data + time
|
||||
err = os.MkdirAll(final, 0766)
|
||||
if err != nil {
|
||||
return final, fmt.Errorf("failed to make directory: %v", err)
|
||||
return "", fmt.Errorf("failed to make directory: %v", err)
|
||||
}
|
||||
return final, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue