diff --git a/demo/cmd/admin/admin.go b/demo/cmd/admin/admin.go index ce96813..9f012d4 100644 --- a/demo/cmd/admin/admin.go +++ b/demo/cmd/admin/admin.go @@ -2,11 +2,13 @@ package main import ( "fmt" - "log" "net" "net/http" "os" + "github.com/hexa-org/policy-orchestrator/demo/pkg/hexaConstants" + log "golang.org/x/exp/slog" + "github.com/hexa-org/policy-orchestrator/demo/internal/admin" "github.com/hexa-org/policy-mapper/pkg/websupport" @@ -24,7 +26,7 @@ func newApp(addr string) (*http.Server, net.Listener) { host, _, _ := net.SplitHostPort(addr) addr = fmt.Sprintf("%v:%v", host, found) } - log.Printf("Found server address %v", addr) + log.Debug("Found server address %v", addr) orchestratorUrl := os.Getenv("ORCHESTRATOR_URL") @@ -33,5 +35,6 @@ func newApp(addr string) (*http.Server, net.Listener) { } func main() { + log.Info("Hexa Orchestrator Admin UI Server starting...", "version", hexaConstants.HexaOrchestratorVersion) websupport.Start(newApp("0.0.0.0:8884")) } diff --git a/demo/cmd/orchestrator/orchestrator.go b/demo/cmd/orchestrator/orchestrator.go index a8f27ce..4e27686 100644 --- a/demo/cmd/orchestrator/orchestrator.go +++ b/demo/cmd/orchestrator/orchestrator.go @@ -9,6 +9,7 @@ import ( "github.com/hexa-org/policy-mapper/pkg/keysupport" "github.com/hexa-org/policy-orchestrator/demo/internal/orchestrator" "github.com/hexa-org/policy-orchestrator/demo/pkg/dataConfigGateway" + "github.com/hexa-org/policy-orchestrator/demo/pkg/hexaConstants" log "golang.org/x/exp/slog" @@ -47,14 +48,14 @@ func newApp(addr string) (*http.Server, net.Listener) { host, _, _ := net.SplitHostPort(addr) addr = fmt.Sprintf("%v:%v", host, found) } - log.Info("Orchestrator Start", "Found server address", addr) + log.Debug("Orchestrator Start", "Found server address", addr) if found := os.Getenv("HOST"); found != "" { _, port, _ := net.SplitHostPort(addr) addr = fmt.Sprintf("%v:%v", found, port) } - log.Info("Orchestrator Start", "Found server host", addr) + log.Debug("Orchestrator Start", "Found server host", addr) key := os.Getenv("ORCHESTRATOR_KEY") hostPort := os.Getenv("ORCHESTRATOR_HOSTPORT") @@ -76,6 +77,8 @@ func newApp(addr string) (*http.Server, net.Listener) { } func main() { + log.Info("Hexa Orchestrator API Server starting...", "version", hexaConstants.HexaOrchestratorVersion) + app, listener := newApp("0.0.0.0:8885") websupport.Start(app, listener) diff --git a/demo/internal/admin/orchestrator_client.go b/demo/internal/admin/orchestrator_client.go index d0865ce..d82f4ec 100644 --- a/demo/internal/admin/orchestrator_client.go +++ b/demo/internal/admin/orchestrator_client.go @@ -6,10 +6,11 @@ import ( "errors" "fmt" "io" - "log" "net/http" "strings" + log "golang.org/x/exp/slog" + "github.com/hexa-org/policy-mapper/pkg/hexapolicy" "github.com/hexa-org/policy-mapper/pkg/oauth2support" ) @@ -45,7 +46,7 @@ func NewOrchestratorClient(client HTTPClient, url string) Client { func (c orchestratorClient) Health() (string, error) { resp, err := c.client.Get(fmt.Sprintf("%v/health", c.url)) if err != nil { - log.Println(err) + log.Error(err.Error()) return "[{\"name\":\"Unreachable\",\"pass\":\"fail\"}]", err } body, err := io.ReadAll(resp.Body) @@ -79,7 +80,7 @@ func (c orchestratorClient) Applications(refresh bool) (applications []Applicati var jsonResponse applicationList if err = json.NewDecoder(resp.Body).Decode(&jsonResponse); err != nil { - log.Printf("unable to parse found json: %s\n", err.Error()) + log.Error(fmt.Sprintf("unable to parse found json: %s\n", err.Error())) return applications, err } @@ -107,7 +108,7 @@ func (c orchestratorClient) Application(id string) (Application, error) { var jsonResponse application if err := json.NewDecoder(resp.Body).Decode(&jsonResponse); err != nil { - log.Printf("unable to parse found json: %s\n", err.Error()) + log.Error(fmt.Sprintf("unable to parse found json: %s\n", err.Error())) return Application{}, err } app := Application{ @@ -141,7 +142,7 @@ func (c orchestratorClient) Integrations() (integrations []Integration, err erro var jsonResponse integrationList if err = json.NewDecoder(resp.Body).Decode(&jsonResponse); err != nil { - log.Printf("unable to parse found json: %s\n", err.Error()) + log.Error(fmt.Sprintf("unable to parse found json: %s\n", err.Error())) return integrations, err } @@ -179,7 +180,7 @@ func (c orchestratorClient) GetPolicies(id string) ([]hexapolicy.PolicyInfo, str var jsonResponse hexapolicy.Policies if err := json.NewDecoder(bytes.NewReader(jsonBody)).Decode(&jsonResponse); err != nil { - log.Println(err) + log.Error(err.Error()) return []hexapolicy.PolicyInfo{}, string(jsonBody), err } @@ -208,18 +209,18 @@ func (c orchestratorClient) Orchestration(from string, to string) error { func errorOrBadResponse(response *http.Response, status int, err error) error { if err != nil { - log.Println(err) + log.Error(err.Error()) return err } if response.StatusCode != status { err := checkTokenError(response) if err != nil { - log.Println(err.Error()) + log.Error(err.Error()) return err } all, _ := io.ReadAll(response.Body) message := string(all) - log.Println(message) + log.Error(message) return errors.New(message) } return err diff --git a/demo/internal/orchestrator/applications_handler.go b/demo/internal/orchestrator/applications_handler.go index c0e7da1..c7dae32 100644 --- a/demo/internal/orchestrator/applications_handler.go +++ b/demo/internal/orchestrator/applications_handler.go @@ -2,11 +2,13 @@ package orchestrator import ( "encoding/json" - "log" + "fmt" "net/http" "sort" "strings" + log "golang.org/x/exp/slog" + "github.com/hexa-org/policy-mapper/pkg/hexapolicy" "github.com/hexa-org/policy-orchestrator/demo/pkg/dataConfigGateway" @@ -49,7 +51,7 @@ func (handler ApplicationsHandler) List(w http.ResponseWriter, r *http.Request) records, applicationErr := handler.applicationsGateway.Find(doRefresh) if applicationErr != nil { - log.Println("Error accessing database: " + applicationErr.Error()) + log.Error("Error accessing database: " + applicationErr.Error()) http.Error(w, applicationErr.Error(), http.StatusInternalServerError) return } @@ -143,7 +145,7 @@ func (handler ApplicationsHandler) SetPolicies(w http.ResponseWriter, r *http.Re } status, setErr := provider.SetPolicyInfo(integration, application, policies.Policies) if setErr != nil { - log.Printf("unable to update policy: %s", setErr.Error()) + log.Error(fmt.Sprintf("unable to update policy: %s", setErr.Error())) // todo - should we return the error msg here. http.Error(w, "unable to update policy.", http.StatusInternalServerError) return diff --git a/demo/pkg/hexaConstants/hexaConstants.go b/demo/pkg/hexaConstants/hexaConstants.go new file mode 100644 index 0000000..65a8c9e --- /dev/null +++ b/demo/pkg/hexaConstants/hexaConstants.go @@ -0,0 +1,5 @@ +package hexaConstants + +const ( + HexaOrchestratorVersion string = "v0.6.0" +)