Add agent
This commit is contained in:
@@ -44,10 +44,9 @@ func (r Registrar) HandleRegistration(resp http.ResponseWriter, req *http.Reques
|
||||
cert := req.TLS.PeerCertificates[0]
|
||||
|
||||
name := cert.DNSNames[0]
|
||||
if r.repo.IsRegistered(name) {
|
||||
resp.WriteHeader(http.StatusOK)
|
||||
resp.Write([]byte(`{"status": "registered"}`))
|
||||
} else {
|
||||
app, err := r.repo.GetApp(name)
|
||||
switch err {
|
||||
case svc.ErrApplicationNotFound:
|
||||
id := r.repo.StartAppRegistration(name)
|
||||
event := map[string]string{
|
||||
"id": id.String(),
|
||||
@@ -59,6 +58,12 @@ func (r Registrar) HandleRegistration(resp http.ResponseWriter, req *http.Reques
|
||||
|
||||
resp.WriteHeader(http.StatusCreated)
|
||||
fmt.Fprintf(resp, `{"status": "pending_approval"}`)
|
||||
case nil:
|
||||
resp.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintf(resp, `{"status": "%s"}`, app.State)
|
||||
default:
|
||||
resp.WriteHeader(http.StatusInternalServerError)
|
||||
fmt.Fprintf(resp, `{"errors": ["%s"]}`, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user