diff --git a/api/auth.go b/api/auth.go index 727ceada..af20e471 100644 --- a/api/auth.go +++ b/api/auth.go @@ -83,9 +83,9 @@ func NewAuth(key *ecdsa.PrivateKey, customers customers.Repository, passwd strin // CreateCustomerJWT creates a JWT that only stores the customer ID. func (auth *Auth) CreateCustomerJWT(customerId int) ([]byte, error) { t := openid.New() - t.Set(jwt.IssuedAtKey, time.Now()) - t.Set(jwt.ExpirationKey, time.Now().Add(MaxSessionAge)) - t.Set(CustomerID, customerId) + _ = t.Set(jwt.IssuedAtKey, time.Now()) + _ = t.Set(jwt.ExpirationKey, time.Now().Add(MaxSessionAge)) + _ = t.Set(CustomerID, customerId) return jwt.Sign(t, jwa.ES256, auth.sessionKey) } diff --git a/api/transfer.go b/api/transfer.go index 22c5c432..509250db 100644 --- a/api/transfer.go +++ b/api/transfer.go @@ -1,7 +1,6 @@ package api import ( - "context" "errors" "fmt" "net/http" @@ -96,6 +95,9 @@ func (w Wrapper) UpdateTransfer(ctx echo.Context, transferID string) error { t.TransferDate = updateRequest.TransferDate return t, nil }) + if err != nil { + return err + } transfer, err := w.TransferSenderService.GetTransferByID(ctx.Request().Context(), cid, transferID) if err != nil { @@ -258,16 +260,3 @@ func (w Wrapper) NotifyTransferUpdate(ctx echo.Context, taskID string) error { return ctx.NoContent(http.StatusAccepted) } - -func (w Wrapper) findNegotiation(ctx context.Context, customerID int, transferID, negotiationID string) (*types.TransferNegotiation, error) { - negotiations, err := w.TransferSenderRepo.ListNegotiations(ctx, customerID, transferID) - if err != nil { - return nil, err - } - for _, curr := range negotiations { - if string(curr.Id) == negotiationID { - return &curr, nil - } - } - return nil, errors.New("transfer negotiation not found") -} diff --git a/config.go b/config.go index 5d0e22a4..24fb2f22 100644 --- a/config.go +++ b/config.go @@ -167,7 +167,9 @@ func generateSessionKey() (*ecdsa.PrivateKey, error) { return nil, err } block := pem.Block{Type: "EC PRIVATE KEY", Bytes: keyBytes} - pem.Encode(log.Writer(), &block) + if err := pem.Encode(log.Writer(), &block); err != nil { + return nil, err + } return key, nil } diff --git a/domain/customers/repository.go b/domain/customers/repository.go index 715bc8b6..7664d321 100644 --- a/domain/customers/repository.go +++ b/domain/customers/repository.go @@ -19,13 +19,14 @@ type jsonFileRepo struct { filepath string } -func NewJsonFileRepository(filepath string) *jsonFileRepo { +func NewJsonFileRepository(filepath string) Repository { f, err := os.OpenFile(filepath, os.O_RDONLY, 0666) - defer f.Close() if err != nil { log.Warnf("Could not open cusomers file (path=%s), it still needs to be created: %s", filepath, err) // But allow to proceed, since it is shared with nuts-registry-admin-demo, which creates it. // In Docker environments, it might not be there yet if demo-ehr starts first. + } else { + defer f.Close() } return &jsonFileRepo{ diff --git a/domain/episode/service.go b/domain/episode/service.go index 825ecb71..61932f1e 100644 --- a/domain/episode/service.go +++ b/domain/episode/service.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "github.com/nuts-foundation/nuts-demo-ehr/domain/acl" - nutsClient "github.com/nuts-foundation/nuts-demo-ehr/nuts/client" "github.com/sirupsen/logrus" "net/url" "strings" @@ -46,7 +45,6 @@ type service struct { factory fhir.Factory auth auth.Service aclRepository *acl.Repository - nutsClient nutsClient.HTTPClient registry registry.OrganizationRegistry vcr registry.VerifiableCredentialRegistry } @@ -166,7 +164,7 @@ func (service *service) GetCollaborations(ctx context.Context, customerDID, doss var collaborations []types.Collaboration - for authorizedDID, _ := range authorizedDIDs { + for authorizedDID := range authorizedDIDs { org, err := service.registry.Get(ctx, authorizedDID) if err != nil { logrus.WithError(err).Warn("Error looking up episode collaborator organization") diff --git a/domain/fhir/client.go b/domain/fhir/client.go index 51e9b251..29ea9223 100644 --- a/domain/fhir/client.go +++ b/domain/fhir/client.go @@ -74,7 +74,6 @@ type httpClient struct { url string tenant int multiTenancyEnabled bool - tlsConfig *tls.Config } func (h httpClient) Create(ctx context.Context, resource interface{}, result interface{}) error { diff --git a/domain/fhir/util.go b/domain/fhir/util.go index 853dd53f..f60c5e72 100644 --- a/domain/fhir/util.go +++ b/domain/fhir/util.go @@ -67,8 +67,3 @@ func ToIDPtr(str string) *datatypes.ID { result := datatypes.ID(str) return &result } - -func toCodePtr(str string) *datatypes.Code { - result := datatypes.Code(str) - return &result -} diff --git a/domain/reports/repository.go b/domain/reports/repository.go index 79446de6..7f6f9a08 100644 --- a/domain/reports/repository.go +++ b/domain/reports/repository.go @@ -26,7 +26,7 @@ type fhirRepository struct { factory fhir.Factory } -func NewFHIRRepository(factory fhir.Factory) *fhirRepository { +func NewFHIRRepository(factory fhir.Factory) Repository { return &fhirRepository{ factory: factory, } diff --git a/http/auth/service.go b/http/auth/service.go index 9c1324ab..edca4e29 100644 --- a/http/auth/service.go +++ b/http/auth/service.go @@ -30,14 +30,6 @@ type authService struct { client *nutsAuthClient.ClientWithResponses } -func fromStringPtr(ptr *string) (output string) { - if ptr != nil { - output = *ptr - } - - return -} - func NewService(server string) (Service, error) { authClient, err := nutsAuthClient.NewClientWithResponses(server) if err != nil { diff --git a/main.go b/main.go index f003f829..90b35904 100644 --- a/main.go +++ b/main.go @@ -58,8 +58,6 @@ const assetPath = "web/dist" //go:embed web/dist/* var embeddedFiles embed.FS -const apiTimeout = 10 * time.Second - func getFileSystem(useFS bool) http.FileSystem { if useFS { logrus.Info("using live mode") @@ -134,7 +132,7 @@ func createServer() *echo.Echo { server.Logger.SetLevel(log2.DEBUG) server.HTTPErrorHandler = func(err error, ctx echo.Context) { if !ctx.Response().Committed { - ctx.Response().Write([]byte(err.Error())) + _, _ = ctx.Response().Write([]byte(err.Error())) ctx.Echo().Logger.Error(err) } } @@ -357,7 +355,7 @@ func httpErrorHandler(err error, c echo.Context) { code = he.Code msg = he.Message if he.Internal != nil { - err = fmt.Errorf("%v, %v", err, he.Internal) + msg = fmt.Sprintf("%v, %v", err, he.Internal) } } else { msg = err.Error() @@ -410,7 +408,7 @@ func (cb *fhirBinder) Bind(i interface{}, c echo.Context) (err error) { } if strings.Contains(c.Request().Header.Get("Content-Type"), "application/fhir+json") { - var bytes = make([]byte, 0) + var bytes []byte if bytes, err = io.ReadAll(c.Request().Body); err != nil { return }