diff --git a/src/config/config.go b/src/config/config.go index 2819670..9867271 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -89,6 +89,11 @@ type User struct { Password string `valid:"required"` } +type PrivacyDashboard struct { + Hostname string + Version string +} + // Configuration data type type Configuration struct { DataBase struct { @@ -97,16 +102,17 @@ type Configuration struct { UserName string Password string } - ApplicationMode string - Organization Organization - Type OrgType - User User - ApiSecretKey string - Iam Iam - Twilio Twilio - Firebase Firebase - Smtp SmtpConfig - Webhooks WebhooksConfig + ApplicationMode string + Organization Organization + Type OrgType + User User + ApiSecretKey string + Iam Iam + Twilio Twilio + PrivacyDashboard PrivacyDashboard + Firebase Firebase + Smtp SmtpConfig + Webhooks WebhooksConfig } // Load the config file diff --git a/src/main/main.go b/src/main/main.go index f60be1d..60ddaa6 100644 --- a/src/main/main.go +++ b/src/main/main.go @@ -18,6 +18,7 @@ import ( v2HttpPaths "github.com/bb-consent/api/src/v2/http_path" "github.com/bb-consent/api/src/v2/iam" "github.com/bb-consent/api/src/v2/middleware" + pd "github.com/bb-consent/api/src/v2/privacy_dashboard" "github.com/bb-consent/api/src/v2/sms" v2token "github.com/bb-consent/api/src/v2/token" v2wh "github.com/bb-consent/api/src/v2/webhook" @@ -81,6 +82,10 @@ func startAPICmdHandlerfunc(cmd *cobra.Command, args []string) { firebaseUtils.Init(loadedConfig) log.Println("Firebase initialized") + // Privacy Dashboard + pd.Init(loadedConfig) + log.Println("Privacy Dashboard initialized") + // Application mode middleware.ApplicationModeInit(loadedConfig) log.Println("Application mode initialized") diff --git a/src/v2/handler/privacy_dashboard/config_read_privacy_dashboard.go b/src/v2/handler/privacy_dashboard/config_read_privacy_dashboard.go new file mode 100644 index 0000000..8cb506c --- /dev/null +++ b/src/v2/handler/privacy_dashboard/config_read_privacy_dashboard.go @@ -0,0 +1,40 @@ +package privacydashboard + +import ( + "encoding/json" + "net/http" + + pd "github.com/bb-consent/api/src/v2/privacy_dashboard" +) + +type readPrivacyDashboardResp struct { + HostName string `json:"hostname"` + Version string `json:"version"` + Status int `json:"status"` + StatusStr string `json:"statusStr"` +} + +// ConfigReadPrivacyDashboard Gets the privacy dashboard related info of the organization +func ConfigReadPrivacyDashboard(w http.ResponseWriter, r *http.Request) { + + var resp readPrivacyDashboardResp + if pd.PrivacyDashboard.Hostname == "" { + resp = readPrivacyDashboardResp{ + HostName: pd.PrivacyDashboard.Hostname, + Version: pd.PrivacyDashboard.Version, + Status: pd.DashboardNotConfigured, + StatusStr: pd.DashboardDeploymentStatuses[0].Str, + } + } else { + resp = readPrivacyDashboardResp{ + HostName: pd.PrivacyDashboard.Hostname, + Version: pd.PrivacyDashboard.Version, + Status: pd.DashboardDeployed, + StatusStr: pd.DashboardDeploymentStatuses[2].Str, + } + } + + response, _ := json.Marshal(resp) + w.Header().Set("Content-Type", "application/json") + w.Write(response) +} diff --git a/src/v2/http_path/config_paths.go b/src/v2/http_path/config_paths.go index 23cadc1..42edc46 100644 --- a/src/v2/http_path/config_paths.go +++ b/src/v2/http_path/config_paths.go @@ -60,3 +60,5 @@ const ConfigCreateApiKey = "/v2/config/admin/apikey" const ConfigUpdateApiKey = "/v2/config/admin/apikey/{apiKeyId}" const ConfigDeleteApiKey = "/v2/config/admin/apikey/{apiKeyId}" const ConfigListApiKey = "/v2/config/admin/apikeys" + +const ConfigReadPrivacyDashboard = "/v2/config/privacy-dashboard" diff --git a/src/v2/http_path/routes.go b/src/v2/http_path/routes.go index bace508..4513949 100644 --- a/src/v2/http_path/routes.go +++ b/src/v2/http_path/routes.go @@ -9,6 +9,7 @@ import ( individualHandler "github.com/bb-consent/api/src/v2/handler/individual" onboardHandler "github.com/bb-consent/api/src/v2/handler/onboard" policyHandler "github.com/bb-consent/api/src/v2/handler/policy" + privacyDashboardHandler "github.com/bb-consent/api/src/v2/handler/privacy_dashboard" serviceHandler "github.com/bb-consent/api/src/v2/handler/service" webhookHandler "github.com/bb-consent/api/src/v2/handler/webhook" m "github.com/bb-consent/api/src/v2/middleware" @@ -78,6 +79,8 @@ func SetRoutes(r *mux.Router, e *casbin.Enforcer) { r.Handle(ConfigCreateIndividualsInBulk, m.Chain(individualHandler.ConfigCreateIndividualsInBulk, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate(), m.AddContentType())).Methods("POST") + r.Handle(ConfigReadPrivacyDashboard, m.Chain(privacyDashboardHandler.ConfigReadPrivacyDashboard, m.Logger(), m.Authorize(e), m.SetApplicationMode(), m.Authenticate(), m.AddContentType())).Methods("GET") + // Service api(s) // Data agreements diff --git a/src/v2/privacy_dashboard/privacy_dashboard.go b/src/v2/privacy_dashboard/privacy_dashboard.go new file mode 100644 index 0000000..257fa97 --- /dev/null +++ b/src/v2/privacy_dashboard/privacy_dashboard.go @@ -0,0 +1,30 @@ +package privacydashboard + +import "github.com/bb-consent/api/src/config" + +// DashboardDeploymentStatus id and string of status +type DashboardDeploymentStatus struct { + ID int + Str string +} + +const ( + DashboardNotConfigured = 0 + DashboardRequested = 1 + DashboardDeployed = 2 +) + +var PrivacyDashboard config.PrivacyDashboard + +// Init Initialize the Privacy Dashboard +func Init(config *config.Configuration) { + PrivacyDashboard = config.PrivacyDashboard +} + +// Note: Dont change the ID(s) if new type is needed then add at the end + +// DashboardDeploymentStatuses Array of id and string +var DashboardDeploymentStatuses = []DashboardDeploymentStatus{ + {ID: DashboardNotConfigured, Str: "Not Configured"}, + {ID: DashboardRequested, Str: "Requested"}, + {ID: DashboardDeployed, Str: "Deployed"}}