Skip to content

Commit

Permalink
Merge branch 'main' into fix/es_indexed_param
Browse files Browse the repository at this point in the history
  • Loading branch information
Dav-14 authored Nov 10, 2023
2 parents a4eb6f6 + 94d1617 commit 5572255
Show file tree
Hide file tree
Showing 308 changed files with 8,578 additions and 1,927 deletions.
4 changes: 2 additions & 2 deletions components/fctl/cmd/webhooks/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func (c *ActivateWebhookController) Run(cmd *cobra.Command, args []string) (fctl
return nil, errors.Wrap(err, "activating config")
}

if response.ErrorResponse != nil {
return nil, fmt.Errorf("%s: %s", response.ErrorResponse.ErrorCode, response.ErrorResponse.ErrorMessage)
if response.WebhooksErrorResponse != nil {
return nil, fmt.Errorf("%s: %s", response.WebhooksErrorResponse.ErrorCode, response.WebhooksErrorResponse.ErrorMessage)
}

if response.StatusCode >= 300 {
Expand Down
4 changes: 2 additions & 2 deletions components/fctl/cmd/webhooks/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func (c *CreateWebhookController) Run(cmd *cobra.Command, args []string) (fctl.R
return nil, errors.Wrap(err, "creating config")
}

if response.ErrorResponse != nil {
return nil, fmt.Errorf("%s: %s", response.ErrorResponse.ErrorCode, response.ErrorResponse.ErrorMessage)
if response.WebhooksErrorResponse != nil {
return nil, fmt.Errorf("%s: %s", response.WebhooksErrorResponse.ErrorCode, response.WebhooksErrorResponse.ErrorMessage)
}

if response.StatusCode >= 300 {
Expand Down
4 changes: 2 additions & 2 deletions components/fctl/cmd/webhooks/deactivate.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func (c *DesactivateWebhookController) Run(cmd *cobra.Command, args []string) (f
c.store.Success = !response.ConfigResponse.Data.Active

// Check if there is an error
if response.ErrorResponse != nil {
return nil, fmt.Errorf("%s: %s", response.ErrorResponse.ErrorCode, response.ErrorResponse.ErrorMessage)
if response.WebhooksErrorResponse != nil {
return nil, fmt.Errorf("%s: %s", response.WebhooksErrorResponse.ErrorCode, response.WebhooksErrorResponse.ErrorMessage)
}

// Check if the status code is >= 300
Expand Down
12 changes: 6 additions & 6 deletions components/fctl/cmd/webhooks/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
)

type DeleteWebhookStore struct {
ErrorResponse *shared.ErrorResponse `json:"error"`
Success bool `json:"success"`
ErrorResponse *shared.WebhooksErrorResponse `json:"error"`
Success bool `json:"success"`
}

type DeleteWebhookController struct {
Expand Down Expand Up @@ -74,13 +74,13 @@ func (c *DeleteWebhookController) Run(cmd *cobra.Command, args []string) (fctl.R
return nil, errors.Wrap(err, "deleting config")
}

if response.ErrorResponse != nil {
if response.ErrorResponse.ErrorCode == "NOT_FOUND" {
c.store.ErrorResponse = response.ErrorResponse
if response.WebhooksErrorResponse != nil {
if response.WebhooksErrorResponse.ErrorCode == "NOT_FOUND" {
c.store.ErrorResponse = response.WebhooksErrorResponse
c.store.Success = false
return c, nil
}
return nil, fmt.Errorf("%s: %s", response.ErrorResponse.ErrorCode, response.ErrorResponse.ErrorMessage)
return nil, fmt.Errorf("%s: %s", response.WebhooksErrorResponse.ErrorCode, response.WebhooksErrorResponse.ErrorMessage)
}

if response.StatusCode >= 300 {
Expand Down
4 changes: 2 additions & 2 deletions components/fctl/cmd/webhooks/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func (c *ListWebhookController) Run(cmd *cobra.Command, args []string) (fctl.Ren
return nil, errors.Wrap(err, "listing all config")
}

if response.ErrorResponse != nil {
return nil, fmt.Errorf("%s: %s", response.ErrorResponse.ErrorCode, response.ErrorResponse.ErrorMessage)
if response.WebhooksErrorResponse != nil {
return nil, fmt.Errorf("%s: %s", response.WebhooksErrorResponse.ErrorCode, response.WebhooksErrorResponse.ErrorMessage)
}

if response.StatusCode >= 300 {
Expand Down
4 changes: 2 additions & 2 deletions components/fctl/cmd/webhooks/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func (c *ChangeSecretWebhookController) Run(cmd *cobra.Command, args []string) (
return nil, errors.Wrap(err, "changing secret")
}

if response.ErrorResponse != nil {
return nil, fmt.Errorf("%s: %s", response.ErrorResponse.ErrorCode, response.ErrorResponse.ErrorMessage)
if response.WebhooksErrorResponse != nil {
return nil, fmt.Errorf("%s: %s", response.WebhooksErrorResponse.ErrorCode, response.WebhooksErrorResponse.ErrorMessage)
}

if response.StatusCode >= 300 {
Expand Down
3 changes: 2 additions & 1 deletion components/ledger/internal/analytics/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"runtime"
"time"

storageerrors "github.com/formancehq/ledger/internal/storage/sqlutils"

ledger "github.com/formancehq/ledger/internal"
storageerrors "github.com/formancehq/ledger/internal/storage"
"github.com/formancehq/stack/libs/go-libs/logging"
"github.com/pbnjay/memory"
"gopkg.in/segmentio/analytics-go.v3"
Expand Down
3 changes: 2 additions & 1 deletion components/ledger/internal/analytics/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package analytics
import (
"context"

storageerrors "github.com/formancehq/ledger/internal/storage"
storageerrors "github.com/formancehq/ledger/internal/storage/sqlutils"

"github.com/formancehq/ledger/internal/storage/driver"
ledgerstore "github.com/formancehq/ledger/internal/storage/ledgerstore"
"github.com/google/uuid"
Expand Down
17 changes: 17 additions & 0 deletions components/ledger/internal/api/backend/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package backend

import (
"context"
)

type ledgerKey struct{}

var _ledgerKey = ledgerKey{}

func ContextWithLedger(ctx context.Context, ledger Ledger) context.Context {
return context.WithValue(ctx, _ledgerKey, ledger)
}

func LedgerFromContext(ctx context.Context) Ledger {
return ctx.Value(_ledgerKey).(Ledger)
}
24 changes: 24 additions & 0 deletions components/ledger/internal/api/backend/playnumscript.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package backend

import (
"encoding/base64"
"encoding/json"
"fmt"
"strings"
)

func EncodeLink(errStr string) string {
if errStr == "" {
return ""
}

errStr = strings.ReplaceAll(errStr, "\n", "\r\n")
payload, err := json.Marshal(map[string]any{
"error": errStr,
})
if err != nil {
panic(err)
}
payloadB64 := base64.StdEncoding.EncodeToString(payload)
return fmt.Sprintf("https://play.numscript.org/?payload=%v", payloadB64)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package shared
package backend

import (
"math/rand"
Expand All @@ -7,9 +7,10 @@ import (
"sync"
"time"

sharedapi "github.com/formancehq/stack/libs/go-libs/api"

"github.com/pkg/errors"

"github.com/formancehq/ledger/internal/api/backend"
"github.com/formancehq/ledger/internal/opentelemetry/tracer"
"github.com/formancehq/stack/libs/go-libs/logging"
"github.com/go-chi/chi/v5"
Expand All @@ -20,6 +21,10 @@ var (
mu sync.Mutex
)

const (
ErrOutdatedSchema = "OUTDATED_SCHEMA"
)

func init() {
r = rand.New(rand.NewSource(time.Now().UnixNano()))
}
Expand All @@ -38,7 +43,7 @@ func randomTraceID(n int) string {
}

func LedgerMiddleware(
resolver backend.Backend,
resolver Backend,
excludePathFromSchemaCheck []string,
) func(handler http.Handler) http.Handler {
return func(handler http.Handler) http.Handler {
Expand Down Expand Up @@ -67,7 +72,7 @@ func LedgerMiddleware(

l, err := resolver.GetLedger(r.Context(), name)
if err != nil {
ResponseError(w, r, err)
sharedapi.BadRequest(w, sharedapi.ErrorInternal, err)
return
}

Expand All @@ -82,11 +87,11 @@ func LedgerMiddleware(
if !excluded {
isUpToDate, err := l.IsDatabaseUpToDate(ctx)
if err != nil {
ResponseError(w, r, err)
sharedapi.BadRequest(w, sharedapi.ErrorInternal, err)
return
}
if !isUpToDate {
ResponseError(w, r, errors.New("outdated schema"))
sharedapi.BadRequest(w, ErrOutdatedSchema, errors.New("You need to upgrade your ledger schema to the last version"))
return
}
}
Expand Down
6 changes: 6 additions & 0 deletions components/ledger/internal/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ func NewRouter(
readOnly bool,
) chi.Router {
mux := chi.NewRouter()
mux.Use(func(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
handler.ServeHTTP(w, r)
})
})
if readOnly {
mux.Use(ReadOnly)
}
Expand Down
19 changes: 0 additions & 19 deletions components/ledger/internal/api/shared/context.go

This file was deleted.

110 changes: 0 additions & 110 deletions components/ledger/internal/api/shared/errors.go

This file was deleted.

Loading

0 comments on commit 5572255

Please sign in to comment.