CI step for static check (#467)

* CI step for static check

* fix staticcheck
This commit is contained in:
David Zhao
2022-02-24 23:07:15 -08:00
committed by GitHub
parent 778d1aa141
commit 130decbf1d
6 changed files with 19 additions and 15 deletions

View File

@@ -42,6 +42,11 @@ jobs:
version: latest
args: build
- name: Static Check
uses: dominikh/staticcheck-action@v1.1.0
with:
version: "2021.1.1"
- name: Test
run: |
set -euo pipefail

View File

@@ -12,7 +12,6 @@ import (
)
var (
logConfig config.LoggingConfig
pionLevel zapcore.Level
)
@@ -43,7 +42,6 @@ func SetLogger(l logr.Logger) {
}
func InitFromConfig(config config.LoggingConfig) {
logConfig = config
lvl := parseLevel(config.Level)
pionLevel = parseLevel(config.PionLevel)
if lvl > pionLevel {

View File

@@ -38,7 +38,7 @@ type UpTrackManager struct {
func NewUpTrackManager(params UpTrackManagerParams) *UpTrackManager {
return &UpTrackManager{
params: params,
publishedTracks: make(map[livekit.TrackID]types.MediaTrack, 0),
publishedTracks: make(map[livekit.TrackID]types.MediaTrack),
pendingSubscriptions: make(map[livekit.TrackID][]livekit.ParticipantID),
}
}

View File

@@ -15,10 +15,11 @@ import (
const (
authorizationHeader = "Authorization"
bearerPrefix = "Bearer "
grantsKey = "grants"
accessTokenParam = "access_token"
)
type grantsKey struct{}
var (
ErrPermissionDenied = errors.New("permissions denied")
)
@@ -75,20 +76,24 @@ func (m *APIKeyAuthMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request,
// set grants in context
ctx := r.Context()
r = r.WithContext(context.WithValue(ctx, grantsKey, grants))
r = r.WithContext(context.WithValue(ctx, grantsKey{}, grants))
}
next.ServeHTTP(w, r)
}
func GetGrants(ctx context.Context) *auth.ClaimGrants {
claims, ok := ctx.Value(grantsKey).(*auth.ClaimGrants)
claims, ok := ctx.Value(grantsKey{}).(*auth.ClaimGrants)
if !ok {
return nil
}
return claims
}
func WithGrants(ctx context.Context, grants *auth.ClaimGrants) context.Context {
return context.WithValue(ctx, grantsKey{}, grants)
}
func SetAuthorizationToken(r *http.Request, token string) {
r.Header.Set(authorizationHeader, bearerPrefix+token)
}

View File

@@ -13,8 +13,6 @@ import (
"github.com/livekit/livekit-server/pkg/service/servicefakes"
)
const grantsKey = "grants"
func TestDeleteRoom(t *testing.T) {
t.Run("normal deletion", func(t *testing.T) {
svc := newTestRoomService()
@@ -23,7 +21,7 @@ func TestDeleteRoom(t *testing.T) {
RoomCreate: true,
},
}
ctx := context.WithValue(context.Background(), grantsKey, grant)
ctx := service.WithGrants(context.Background(), grant)
svc.store.LoadRoomReturns(nil, service.ErrRoomNotFound)
_, err := svc.DeleteRoom(ctx, &livekit.DeleteRoomRequest{
Room: "testroom",
@@ -36,7 +34,7 @@ func TestDeleteRoom(t *testing.T) {
grant := &auth.ClaimGrants{
Video: &auth.VideoGrant{},
}
ctx := context.WithValue(context.Background(), grantsKey, grant)
ctx := service.WithGrants(context.Background(), grant)
_, err := svc.DeleteRoom(ctx, &livekit.DeleteRoomRequest{
Room: "testroom",
})

View File

@@ -230,11 +230,9 @@ func (s *LivekitServer) Stop(force bool) {
partTicker := time.NewTicker(5 * time.Second)
waitingForParticipants := !force && s.roomManager.HasParticipants()
for waitingForParticipants {
select {
case <-partTicker.C:
logger.Infow("waiting for participants to exit")
waitingForParticipants = s.roomManager.HasParticipants()
}
<-partTicker.C
logger.Infow("waiting for participants to exit")
waitingForParticipants = s.roomManager.HasParticipants()
}
partTicker.Stop()