Skip to content

Commit

Permalink
Use shared etcd client in IUT Provider
Browse files Browse the repository at this point in the history
  • Loading branch information
andmat900 committed Sep 30, 2024
1 parent 04118d9 commit daf5039
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
22 changes: 12 additions & 10 deletions cmd/iut/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import (
"time"

config "github.com/eiffel-community/etos-api/internal/configs/iut"
"github.com/eiffel-community/etos-api/internal/database/etcd"
"github.com/eiffel-community/etos-api/internal/logging"
server "github.com/eiffel-community/etos-api/internal/server"
"github.com/eiffel-community/etos-api/pkg/application"
"github.com/eiffel-community/etos-api/pkg/iut/v1alpha1"
"github.com/sirupsen/logrus"
"github.com/snowzach/rotatefilehook"
"go.elastic.co/ecslogrus"
clientv3 "go.etcd.io/etcd/client/v3"
)

// main sets up logging and starts up the webserver.
Expand Down Expand Up @@ -63,16 +63,18 @@ func main() {
})

// Database connection test
cli, err := clientv3.New(clientv3.Config{
Endpoints: []string{cfg.DatabaseURI()},
DialTimeout: 5 * time.Second,
})
if err != nil {
log.WithError(err).Fatal("failed to create etcd connection")
}

// cli, err := clientv3.New(clientv3.Config{
// Endpoints: []string{cfg.DatabaseURI()},
// DialTimeout: 5 * time.Second,
// })
// if err != nil {
// log.WithError(err).Fatal("failed to create etcd connection")
// }

iutEtcdTreePrefix := "/iut"
db := etcd.New(cfg, logger, iutEtcdTreePrefix)
log.Info("Loading v1alpha1 routes")
v1alpha1App := v1alpha1.New(cfg, log, ctx, cli)
v1alpha1App := v1alpha1.New(cfg, log, ctx, db)
defer v1alpha1App.Close()
router := application.New(v1alpha1App)

Expand Down
12 changes: 7 additions & 5 deletions pkg/iut/v1alpha1/v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (

eiffelevents "github.com/eiffel-community/eiffelevents-sdk-go"
config "github.com/eiffel-community/etos-api/internal/configs/iut"
"github.com/eiffel-community/etos-api/internal/database"
"github.com/eiffel-community/etos-api/pkg/application"
packageurl "github.com/package-url/packageurl-go"
clientv3 "go.etcd.io/etcd/client/v3"

"github.com/google/uuid"
"github.com/julienschmidt/httprouter"
Expand All @@ -38,14 +38,14 @@ import (
type V1Alpha1Application struct {
logger *logrus.Entry
cfg config.Config
database *clientv3.Client
database database.Opener
wg *sync.WaitGroup
}

type V1Alpha1Handler struct {
logger *logrus.Entry
cfg config.Config
database *clientv3.Client
database database.Opener
wg *sync.WaitGroup
}

Expand All @@ -72,11 +72,11 @@ func (a *V1Alpha1Application) Close() {
}

// New returns a new V1Alpha1Application object/struct
func New(cfg config.Config, log *logrus.Entry, ctx context.Context, cli *clientv3.Client) application.Application {
func New(cfg config.Config, log *logrus.Entry, ctx context.Context, db database.Opener) application.Application {
return &V1Alpha1Application{
logger: log,
cfg: cfg,
database: cli,
database: db,
wg: &sync.WaitGroup{},
}
}
Expand Down Expand Up @@ -153,6 +153,8 @@ func (h V1Alpha1Handler) Start(w http.ResponseWriter, r *http.Request, ps httpro
RespondWithError(w, http.StatusInternalServerError, err.Error())
return
}
client := h.database.Open(r.Context(), checkOutID)
client.Write()

Check failure on line 157 in pkg/iut/v1alpha1/v1alpha1.go

View workflow job for this annotation

GitHub Actions / run-gotest (1.21)

not enough arguments in call to client.Write

Check failure on line 157 in pkg/iut/v1alpha1/v1alpha1.go

View workflow job for this annotation

GitHub Actions / run-gotest (1.22.1)

not enough arguments in call to client.Write
_, err = h.database.Put(r.Context(), fmt.Sprintf("/iut/%s", checkOutID.String()), string(iuts))

Check failure on line 158 in pkg/iut/v1alpha1/v1alpha1.go

View workflow job for this annotation

GitHub Actions / run-gotest (1.21)

h.database.Put undefined (type database.Opener has no field or method Put)

Check failure on line 158 in pkg/iut/v1alpha1/v1alpha1.go

View workflow job for this annotation

GitHub Actions / run-gotest (1.22.1)

h.database.Put undefined (type database.Opener has no field or method Put)
if err != nil {
RespondWithError(w, http.StatusInternalServerError, err.Error())
Expand Down

0 comments on commit daf5039

Please sign in to comment.