forked from kyma-project/kyma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
managementinfohandler.go
48 lines (38 loc) · 1.62 KB
/
managementinfohandler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package externalapi
import (
"fmt"
"net/http"
"github.com/kyma-project/kyma/components/connector-service/internal/clientcontext"
"github.com/kyma-project/kyma/components/connector-service/internal/httphelpers"
)
const (
RenewCertURLFormat = "%s/certificates/renewals"
RevocationCertURLFormat = "%s/certificates/revocations"
)
type managementInfoHandler struct {
connectorClientExtractor clientcontext.ConnectorClientExtractor
certificateProtectedBaseURL string
}
func NewManagementInfoHandler(connectorClientExtractor clientcontext.ConnectorClientExtractor, certProtectedBaseURL string) *managementInfoHandler {
return &managementInfoHandler{
connectorClientExtractor: connectorClientExtractor,
certificateProtectedBaseURL: certProtectedBaseURL,
}
}
func (ih *managementInfoHandler) GetManagementInfo(w http.ResponseWriter, r *http.Request) {
clientContextService, err := ih.connectorClientExtractor(r.Context())
if err != nil {
httphelpers.RespondWithErrorAndLog(w, err)
return
}
urls := ih.buildURLs(clientContextService)
certInfo := makeCertInfo(clientContextService.GetSubject().ToString())
httphelpers.RespondWithBody(w, http.StatusOK, mgmtInfoReponse{URLs: urls, ClientIdentity: clientContextService.ClientContext(), CertificateInfo: certInfo})
}
func (ih *managementInfoHandler) buildURLs(clientContextService clientcontext.ClientCertContextService) mgmtURLs {
return mgmtURLs{
RuntimeURLs: clientContextService.GetRuntimeUrls(),
RenewCertURL: fmt.Sprintf(RenewCertURLFormat, ih.certificateProtectedBaseURL),
RevokeCertURL: fmt.Sprintf(RevocationCertURLFormat, ih.certificateProtectedBaseURL),
}
}