Skip to content

Commit

Permalink
Merge pull request #741 from Lanestolen/develop
Browse files Browse the repository at this point in the history
removed secret events from low access users
  • Loading branch information
Lanestolen authored Sep 11, 2023
2 parents 133a4fc + a70e46d commit 033e475
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
12 changes: 6 additions & 6 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io"
"math"

pb "github.com/aau-network-security/haaukins/daemon/proto"
eproto "github.com/aau-network-security/haaukins/exercise/ex-proto"
"github.com/aau-network-security/haaukins/logging"
Expand All @@ -25,10 +28,7 @@ import (
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"
"gopkg.in/yaml.v2"
"io"
"io/ioutil"
"math"
"gopkg.in/yaml.v3"

"net"
"net/http"
Expand Down Expand Up @@ -112,7 +112,7 @@ func (m *MngtPortErr) Error() string {
}

func NewConfigFromFile(path string) (*Config, error) {
f, err := ioutil.ReadFile(path)
f, err := os.ReadFile(path)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -386,7 +386,7 @@ func (d *daemon) enableCertificates() (credentials.TransportCredentials, error)

// Create a certificate pool from the certificate authority
certPool := x509.NewCertPool()
ca, err := ioutil.ReadFile(d.conf.Certs.CAFile)
ca, err := os.ReadFile(d.conf.Certs.CAFile)
if err != nil {
return nil, fmt.Errorf("HAAUKINS Grpc could not read ca certificate: %s", err)
}
Expand Down
21 changes: 5 additions & 16 deletions daemon/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func (d *daemon) StopEvent(ctx context.Context, req *pb.StopEventRequest) (*pb.E

func (d *daemon) ListEvents(ctx context.Context, req *pb.ListEventsRequest) (*pb.ListEventsResponse, error) {
var events []*pb.ListEventsResponse_Events
var event *pb.ListEventsResponse_Events

// in list events there is no need to distinguish based on users.
// could be changed based on feedback
// events are listed through database instead of eventPool
Expand All @@ -484,28 +484,15 @@ func (d *daemon) ListEvents(ctx context.Context, req *pb.ListEventsRequest) (*pb
}

for _, e := range eventsFromDB.Events {
var event *pb.ListEventsResponse_Events
teamsFromDB, err := d.dbClient.GetEventTeams(ctx, &pbc.GetEventTeamsRequest{EventTag: e.Tag})
if err != nil {
log.Error().Msgf("Retrieving teams from db in ListEvent function %v", err)
return &pb.ListEventsResponse{}, err
}
teamCount := int32(len(teamsFromDB.Teams))
if user.SuperUser || user.Username == e.CreatedBy {
event = &pb.ListEventsResponse_Events{

Tag: string(e.Tag),
Name: e.Name,
TeamCount: teamCount,
Exercises: e.Exercises,
Availability: e.Available,
Capacity: e.Capacity,
CreationTime: e.StartedAt,
FinishTime: e.ExpectedFinishTime, //This is the Expected finish time
Status: e.Status,
CreatedBy: e.CreatedBy,
SecretEvent: e.SecretKey,
}
} else {
event = &pb.ListEventsResponse_Events{

Tag: string(e.Tag),
Expand All @@ -518,9 +505,11 @@ func (d *daemon) ListEvents(ctx context.Context, req *pb.ListEventsRequest) (*pb
FinishTime: e.ExpectedFinishTime, //This is the Expected finish time
Status: e.Status,
CreatedBy: e.CreatedBy,
SecretEvent: e.SecretKey,
}
events = append(events, event)
}
events = append(events, event)

}

return &pb.ListEventsResponse{Events: events}, nil
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
google.golang.org/protobuf v1.28.0
gopkg.in/src-d/go-git.v4 v4.13.1
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
)

require (
Expand Down

0 comments on commit 033e475

Please sign in to comment.