diff --git a/main.go b/main.go index b982835d..4e6730a3 100644 --- a/main.go +++ b/main.go @@ -28,7 +28,7 @@ import ( "log" - "github.com/databus23/goslo.policy" + policy "github.com/databus23/goslo.policy" "github.com/sapcc/hermes/pkg/api" "github.com/sapcc/hermes/pkg/configdb" "github.com/sapcc/hermes/pkg/identity" diff --git a/pkg/api/core.go b/pkg/api/core.go index 62412cf1..5bea8bca 100644 --- a/pkg/api/core.go +++ b/pkg/api/core.go @@ -21,12 +21,13 @@ package api import ( "fmt" + "net/http" + "strings" + "github.com/gorilla/mux" "github.com/sapcc/hermes/pkg/configdb" "github.com/sapcc/hermes/pkg/identity" "github.com/sapcc/hermes/pkg/storage" - "net/http" - "strings" ) type v1Provider struct { diff --git a/pkg/api/events.go b/pkg/api/events.go index 31e24401..abb039d0 100644 --- a/pkg/api/events.go +++ b/pkg/api/events.go @@ -23,14 +23,15 @@ import ( "net/http" "fmt" - "github.com/gorilla/mux" - "github.com/pkg/errors" - "github.com/sapcc/hermes/pkg/hermes" - "github.com/sapcc/hermes/pkg/util" "reflect" "strconv" "strings" "time" + + "github.com/gorilla/mux" + "github.com/pkg/errors" + "github.com/sapcc/hermes/pkg/hermes" + "github.com/sapcc/hermes/pkg/util" ) // EventList is the model for JSON returned by the ListEvents API call @@ -226,7 +227,8 @@ func (p *v1Provider) GetAttributes(res http.ResponseWriter, req *http.Request) { // Handle QueryParams queryName := mux.Vars(req)["attribute_name"] if queryName == "" { - fmt.Errorf("QueryName not found") + util.LogDebug("attribute_name empty") + return } maxdepth, _ := strconv.ParseUint(req.FormValue("max_depth"), 10, 32) limit, _ := strconv.ParseUint(req.FormValue("limit"), 10, 32) diff --git a/pkg/api/token.go b/pkg/api/token.go index 22ed72ff..47bd9193 100644 --- a/pkg/api/token.go +++ b/pkg/api/token.go @@ -21,14 +21,15 @@ package api import ( "errors" + "log" + "net/http" + "os" + policy "github.com/databus23/goslo.policy" "github.com/gophercloud/gophercloud" "github.com/gorilla/mux" "github.com/sapcc/hermes/pkg/util" "github.com/spf13/viper" - "log" - "net/http" - "os" ) //Token represents a user's token, as passed through the X-Auth-Token header of diff --git a/pkg/api/util.go b/pkg/api/util.go index fadc2f09..898e3ebe 100644 --- a/pkg/api/util.go +++ b/pkg/api/util.go @@ -3,9 +3,11 @@ package api import ( "bytes" "encoding/json" + "net/http" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" - "net/http" + "github.com/sapcc/hermes/pkg/util" ) // utility functionality @@ -31,11 +33,14 @@ func ReturnJSON(w http.ResponseWriter, code int, data interface{}) { payload, err := json.MarshalIndent(&data, "", " ") // Replaces & symbols properly in json within urls. payload = bytes.Replace(payload, []byte("\\u0026"), []byte("&"), -1) - if err == nil { - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(code) - w.Write(payload) - } else { + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(code) + _, err = w.Write(payload) + if err != nil { + util.LogDebug("Issue with writing payload when returning Json") http.Error(w, err.Error(), http.StatusInternalServerError) } } diff --git a/pkg/hermes/events.go b/pkg/hermes/events.go index 5f7c6a6b..d5828654 100644 --- a/pkg/hermes/events.go +++ b/pkg/hermes/events.go @@ -21,6 +21,7 @@ package hermes import ( "fmt" + "github.com/jinzhu/copier" "github.com/sapcc/hermes/pkg/identity" "github.com/sapcc/hermes/pkg/storage" diff --git a/pkg/identity/keystone.go b/pkg/identity/keystone.go index 73918e04..10e0a53d 100644 --- a/pkg/identity/keystone.go +++ b/pkg/identity/keystone.go @@ -22,14 +22,15 @@ package identity import ( "fmt" - "github.com/databus23/goslo.policy" + "sync" + + policy "github.com/databus23/goslo.policy" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack" "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens" "github.com/pkg/errors" "github.com/sapcc/hermes/pkg/util" "github.com/spf13/viper" - "sync" ) //Keystone Openstack Keystone implementation diff --git a/pkg/identity/keystone_cache.go b/pkg/identity/keystone_cache.go index 651b620e..de3f6b1a 100644 --- a/pkg/identity/keystone_cache.go +++ b/pkg/identity/keystone_cache.go @@ -2,10 +2,11 @@ package identity import ( "container/list" - "github.com/gophercloud/gophercloud" - "github.com/sapcc/hermes/pkg/util" "sync" "time" + + "github.com/gophercloud/gophercloud" + "github.com/sapcc/hermes/pkg/util" ) // Cache type used for the name caches diff --git a/pkg/identity/mock.go b/pkg/identity/mock.go index 5f7e40ec..679b1c88 100644 --- a/pkg/identity/mock.go +++ b/pkg/identity/mock.go @@ -1,7 +1,7 @@ package identity import ( - "github.com/databus23/goslo.policy" + policy "github.com/databus23/goslo.policy" "github.com/gophercloud/gophercloud" "github.com/spf13/viper" ) diff --git a/pkg/policy/policy_test.go b/pkg/policy/policy_test.go index 868bd8ed..12dc5ff9 100644 --- a/pkg/policy/policy_test.go +++ b/pkg/policy/policy_test.go @@ -6,7 +6,7 @@ import ( "encoding/json" "os" - "github.com/databus23/goslo.policy" + policy "github.com/databus23/goslo.policy" "github.com/sapcc/hermes/pkg/util" "github.com/stretchr/testify/assert" ) diff --git a/pkg/storage/elasticsearch.go b/pkg/storage/elasticsearch.go index fbd3f3b5..e7345d7c 100644 --- a/pkg/storage/elasticsearch.go +++ b/pkg/storage/elasticsearch.go @@ -4,10 +4,11 @@ import ( "context" "encoding/json" "fmt" + "strings" + "github.com/sapcc/hermes/pkg/util" "github.com/spf13/viper" elastic "gopkg.in/olivere/elastic.v5" - "strings" ) //ElasticSearch struct holds esclient diff --git a/pkg/storage/interface.go b/pkg/storage/interface.go index 50e36469..63a21656 100644 --- a/pkg/storage/interface.go +++ b/pkg/storage/interface.go @@ -166,5 +166,5 @@ type AttributeValueList []AttributeValue //AttributeValue contains the attribute, and the number of hits. type AttributeValue struct { Value string `json:"value"` - count int64 `json:"count"` // Removing export due to desire to not include it in JSON return + count int64 // Removing export due to desire to not include it in JSON return } diff --git a/pkg/util/load_policy.go b/pkg/util/load_policy.go index 24e5acfc..a1ab2ba0 100644 --- a/pkg/util/load_policy.go +++ b/pkg/util/load_policy.go @@ -4,7 +4,7 @@ import ( "encoding/json" "io/ioutil" - "github.com/databus23/goslo.policy" + policy "github.com/databus23/goslo.policy" ) // LoadPolicyFile used to Load the hermes policy.json file from disk.