Skip to content

Commit

Permalink
Clean up dead/broken code
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul committed May 13, 2024
1 parent a9481b2 commit 618b1de
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 43 deletions.
6 changes: 3 additions & 3 deletions api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
17 changes: 3 additions & 14 deletions api/transfer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package api

import (
"context"
"errors"
"fmt"
"net/http"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}
4 changes: 3 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 3 additions & 2 deletions domain/customers/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 1 addition & 3 deletions domain/episode/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion domain/fhir/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 0 additions & 5 deletions domain/fhir/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion domain/reports/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
8 changes: 0 additions & 8 deletions http/auth/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 3 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 618b1de

Please sign in to comment.