Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions api/RestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,23 @@ import (
"strconv"
)

const (
TelemetryApiKeyEndpoint string = "aHR0cHM6Ly90ZWxlbWV0cnkuZGV2dHJvbi5haS9kZXZ0cm9uL3RlbGVtZXRyeS9hcGlrZXk="
TelemetryOptOutApiBaseUrl string = "aHR0cHM6Ly90ZWxlbWV0cnkuZGV2dHJvbi5haS9kZXZ0cm9uL3RlbGVtZXRyeS9vcHQtb3V0"
PosthogEndpointUrl string = "https://app.posthog.com"
)

type PosthogConfig struct {
PosthogEndpoint string `json:"posthogEndpoint,omitempty"`
TelemetryApiKeyEndpoint string `json:"telemetryApiKeyEndpoint,omitempty"`
}

type RestHandler interface {
GetReleases(w http.ResponseWriter, r *http.Request)
ReleaseWebhookHandler(w http.ResponseWriter, r *http.Request)
GetModules(w http.ResponseWriter, r *http.Request)
GetPostHogInfo(w http.ResponseWriter, r *http.Request)
GetPostHogOptOutApiBaseUrl(w http.ResponseWriter, r *http.Request)
}

func NewRestHandlerImpl(logger *zap.SugaredLogger, releaseNoteService pkg.ReleaseNoteService,
Expand Down Expand Up @@ -158,3 +171,21 @@ func (impl *RestHandlerImpl) ReleaseWebhookHandler(w http.ResponseWriter, r *htt
impl.WriteJsonResp(w, err, flag, http.StatusOK)
return
}

func (impl *RestHandlerImpl) GetPostHogInfo(w http.ResponseWriter, r *http.Request) {
impl.logger.Debug("Get PostHog Info")
setupResponse(&w, r)
posthogConfig := &PosthogConfig{
PosthogEndpoint: PosthogEndpointUrl,
TelemetryApiKeyEndpoint: TelemetryApiKeyEndpoint,
}
impl.WriteJsonResp(w, nil, posthogConfig, http.StatusOK)
return
}

func (impl *RestHandlerImpl) GetPostHogOptOutApiBaseUrl(w http.ResponseWriter, r *http.Request) {
impl.logger.Debug("Get PostHog Opt-out Base Url")
setupResponse(&w, r)
impl.WriteJsonResp(w, nil, TelemetryOptOutApiBaseUrl, http.StatusOK)
return
}
3 changes: 2 additions & 1 deletion api/Router.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ func (r MuxRouter) Init() {
r.Router.Path("/release/notes").HandlerFunc(r.restHandler.GetReleases).Methods("GET")
r.Router.Path("/release/webhook").HandlerFunc(r.restHandler.ReleaseWebhookHandler).Methods("POST")
r.Router.Path("/modules").HandlerFunc(r.restHandler.GetModules).Methods("GET")

r.Router.Path("/telemetry").HandlerFunc(r.restHandler.GetPostHogInfo).Methods("GET")
r.Router.Path("/telemetry/optouturl").HandlerFunc(r.restHandler.GetPostHogOptOutApiBaseUrl).Methods("GET")
}