Skip to content

Commit

Permalink
first try kinda confused about this
Browse files Browse the repository at this point in the history
  • Loading branch information
kayra1 committed Jun 4, 2024
1 parent edf0c74 commit a25facc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build-rock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ jobs:
run: |
sleep 30
curl -k https://localhost:3000 2>&1 | grep GoCert
- name: Test if pebble notify fires correctly
id: notify_test
run : |
echo placeholder
- uses: actions/upload-artifact@v4
if: steps.test_image.outcome == 'success'
Expand Down
21 changes: 15 additions & 6 deletions internal/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,12 @@ func PostCertificate(env *Environment) http.HandlerFunc {
strings.Contains(err.Error(), "cert validation failed") {
logErrorAndWriteResponse(err.Error(), http.StatusBadRequest, w)
return
}else if strings.HasPrefix(err.Error(), "couldn't execute a pebble notify"){
log.Println("pebble notify failed. Silently continuing.")
}else {
logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w)
return
}
logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w)
return
}
w.WriteHeader(http.StatusCreated)
if _, err := w.Write([]byte(strconv.FormatInt(insertId, 10))); err != nil {
Expand All @@ -187,9 +190,12 @@ func RejectCertificate(env *Environment) http.HandlerFunc {
if err.Error() == "csr id not found" {
logErrorAndWriteResponse(err.Error(), http.StatusBadRequest, w)
return
}else if strings.HasPrefix(err.Error(), "couldn't execute a pebble notify"){
log.Println("pebble notify failed. Silently continuing.")
} else {
logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w)
return
}
logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w)
return
}
w.WriteHeader(http.StatusAccepted)
if _, err := w.Write([]byte(strconv.FormatInt(insertId, 10))); err != nil {
Expand All @@ -208,9 +214,12 @@ func DeleteCertificate(env *Environment) http.HandlerFunc {
if err.Error() == "csr id not found" {
logErrorAndWriteResponse(err.Error(), http.StatusBadRequest, w)
return
}else if strings.HasPrefix(err.Error(), "couldn't execute a pebble notify"){
log.Println("pebble notify failed. Silently continuing.")
}else{
logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w)
return
}
logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w)
return
}
w.WriteHeader(http.StatusAccepted)
if _, err := w.Write([]byte(strconv.FormatInt(insertId, 10))); err != nil {
Expand Down
7 changes: 7 additions & 0 deletions internal/certdb/certdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"errors"
"fmt"
"os/exec"

_ "github.com/mattn/go-sqlite3"
)
Expand Down Expand Up @@ -106,6 +107,12 @@ func (db *CertificateRequestsRepository) Update(id string, cert string) (int64,
if err != nil {
return 0, err
}
if insertId != 0{
cmd := exec.Command("pebble", "notify", "gocert/certificate/create", fmt.Sprintf("request_id=%d", insertId))
if err := cmd.Run(); err != nil {
return insertId, errors.Join(errors.New("couldn't execute a pebble notify: "), err)
}
}
return insertId, nil
}

Expand Down

0 comments on commit a25facc

Please sign in to comment.