Skip to content

Commit

Permalink
Merge branch 'main' into fix/yaml-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper authored Aug 26, 2024
2 parents 85c4144 + efd5b04 commit f98f0b5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
12 changes: 10 additions & 2 deletions api/log/get_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
package log

import (
"errors"
"fmt"
"net/http"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"gorm.io/gorm"

"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/build"
Expand Down Expand Up @@ -85,9 +87,15 @@ func GetServiceLog(c *gin.Context) {
// send API call to capture the service logs
sl, err := database.FromContext(c).GetLogForService(ctx, s)
if err != nil {
retErr := fmt.Errorf("unable to get logs for service %s: %w", entry, err)
var status int
if errors.Is(err, gorm.ErrRecordNotFound) {
status = http.StatusNotFound
} else {
status = http.StatusInternalServerError
}

util.HandleError(c, http.StatusInternalServerError, retErr)
retErr := fmt.Errorf("unable to get logs for service %s: %w", entry, err)
util.HandleError(c, status, retErr)

return
}
Expand Down
12 changes: 10 additions & 2 deletions api/log/get_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
package log

import (
"errors"
"fmt"
"net/http"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"gorm.io/gorm"

"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/build"
Expand Down Expand Up @@ -86,9 +88,15 @@ func GetStepLog(c *gin.Context) {
// send API call to capture the step logs
sl, err := database.FromContext(c).GetLogForStep(ctx, s)
if err != nil {
retErr := fmt.Errorf("unable to get logs for step %s: %w", entry, err)
var status int
if errors.Is(err, gorm.ErrRecordNotFound) {
status = http.StatusNotFound
} else {
status = http.StatusInternalServerError
}

util.HandleError(c, http.StatusInternalServerError, retErr)
retErr := fmt.Errorf("unable to get logs for step %s: %w", entry, err)
util.HandleError(c, status, retErr)

return
}
Expand Down
12 changes: 9 additions & 3 deletions database/types/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,15 @@ func (r *Repo) Decrypt(key string) error {
}

// decrypt owner
err = r.Owner.Decrypt(key)
if err != nil {
return err
// Note: In UpdateRepo() (database/repo/update.go), the incoming API repo object
// is cast to a database repo object. The owner object isn't set in this process
// resulting in a zero value for the owner object. A check is performed here
// before decrypting to prevent "unable to decrypt repo..." errors.
if r.Owner.ID.Valid {
err = r.Owner.Decrypt(key)
if err != nil {
return err
}
}

return nil
Expand Down

0 comments on commit f98f0b5

Please sign in to comment.