CI step for static check (#467)
* CI step for static check * fix staticcheck
This commit is contained in:
@@ -42,6 +42,11 @@ jobs:
|
|||||||
version: latest
|
version: latest
|
||||||
args: build
|
args: build
|
||||||
|
|
||||||
|
- name: Static Check
|
||||||
|
uses: dominikh/staticcheck-action@v1.1.0
|
||||||
|
with:
|
||||||
|
version: "2021.1.1"
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
logConfig config.LoggingConfig
|
|
||||||
pionLevel zapcore.Level
|
pionLevel zapcore.Level
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -43,7 +42,6 @@ func SetLogger(l logr.Logger) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func InitFromConfig(config config.LoggingConfig) {
|
func InitFromConfig(config config.LoggingConfig) {
|
||||||
logConfig = config
|
|
||||||
lvl := parseLevel(config.Level)
|
lvl := parseLevel(config.Level)
|
||||||
pionLevel = parseLevel(config.PionLevel)
|
pionLevel = parseLevel(config.PionLevel)
|
||||||
if lvl > pionLevel {
|
if lvl > pionLevel {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ type UpTrackManager struct {
|
|||||||
func NewUpTrackManager(params UpTrackManagerParams) *UpTrackManager {
|
func NewUpTrackManager(params UpTrackManagerParams) *UpTrackManager {
|
||||||
return &UpTrackManager{
|
return &UpTrackManager{
|
||||||
params: params,
|
params: params,
|
||||||
publishedTracks: make(map[livekit.TrackID]types.MediaTrack, 0),
|
publishedTracks: make(map[livekit.TrackID]types.MediaTrack),
|
||||||
pendingSubscriptions: make(map[livekit.TrackID][]livekit.ParticipantID),
|
pendingSubscriptions: make(map[livekit.TrackID][]livekit.ParticipantID),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-3
@@ -15,10 +15,11 @@ import (
|
|||||||
const (
|
const (
|
||||||
authorizationHeader = "Authorization"
|
authorizationHeader = "Authorization"
|
||||||
bearerPrefix = "Bearer "
|
bearerPrefix = "Bearer "
|
||||||
grantsKey = "grants"
|
|
||||||
accessTokenParam = "access_token"
|
accessTokenParam = "access_token"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type grantsKey struct{}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrPermissionDenied = errors.New("permissions denied")
|
ErrPermissionDenied = errors.New("permissions denied")
|
||||||
)
|
)
|
||||||
@@ -75,20 +76,24 @@ func (m *APIKeyAuthMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request,
|
|||||||
|
|
||||||
// set grants in context
|
// set grants in context
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
r = r.WithContext(context.WithValue(ctx, grantsKey, grants))
|
r = r.WithContext(context.WithValue(ctx, grantsKey{}, grants))
|
||||||
}
|
}
|
||||||
|
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetGrants(ctx context.Context) *auth.ClaimGrants {
|
func GetGrants(ctx context.Context) *auth.ClaimGrants {
|
||||||
claims, ok := ctx.Value(grantsKey).(*auth.ClaimGrants)
|
claims, ok := ctx.Value(grantsKey{}).(*auth.ClaimGrants)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return claims
|
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) {
|
func SetAuthorizationToken(r *http.Request, token string) {
|
||||||
r.Header.Set(authorizationHeader, bearerPrefix+token)
|
r.Header.Set(authorizationHeader, bearerPrefix+token)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ import (
|
|||||||
"github.com/livekit/livekit-server/pkg/service/servicefakes"
|
"github.com/livekit/livekit-server/pkg/service/servicefakes"
|
||||||
)
|
)
|
||||||
|
|
||||||
const grantsKey = "grants"
|
|
||||||
|
|
||||||
func TestDeleteRoom(t *testing.T) {
|
func TestDeleteRoom(t *testing.T) {
|
||||||
t.Run("normal deletion", func(t *testing.T) {
|
t.Run("normal deletion", func(t *testing.T) {
|
||||||
svc := newTestRoomService()
|
svc := newTestRoomService()
|
||||||
@@ -23,7 +21,7 @@ func TestDeleteRoom(t *testing.T) {
|
|||||||
RoomCreate: true,
|
RoomCreate: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctx := context.WithValue(context.Background(), grantsKey, grant)
|
ctx := service.WithGrants(context.Background(), grant)
|
||||||
svc.store.LoadRoomReturns(nil, service.ErrRoomNotFound)
|
svc.store.LoadRoomReturns(nil, service.ErrRoomNotFound)
|
||||||
_, err := svc.DeleteRoom(ctx, &livekit.DeleteRoomRequest{
|
_, err := svc.DeleteRoom(ctx, &livekit.DeleteRoomRequest{
|
||||||
Room: "testroom",
|
Room: "testroom",
|
||||||
@@ -36,7 +34,7 @@ func TestDeleteRoom(t *testing.T) {
|
|||||||
grant := &auth.ClaimGrants{
|
grant := &auth.ClaimGrants{
|
||||||
Video: &auth.VideoGrant{},
|
Video: &auth.VideoGrant{},
|
||||||
}
|
}
|
||||||
ctx := context.WithValue(context.Background(), grantsKey, grant)
|
ctx := service.WithGrants(context.Background(), grant)
|
||||||
_, err := svc.DeleteRoom(ctx, &livekit.DeleteRoomRequest{
|
_, err := svc.DeleteRoom(ctx, &livekit.DeleteRoomRequest{
|
||||||
Room: "testroom",
|
Room: "testroom",
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -230,11 +230,9 @@ func (s *LivekitServer) Stop(force bool) {
|
|||||||
partTicker := time.NewTicker(5 * time.Second)
|
partTicker := time.NewTicker(5 * time.Second)
|
||||||
waitingForParticipants := !force && s.roomManager.HasParticipants()
|
waitingForParticipants := !force && s.roomManager.HasParticipants()
|
||||||
for waitingForParticipants {
|
for waitingForParticipants {
|
||||||
select {
|
<-partTicker.C
|
||||||
case <-partTicker.C:
|
logger.Infow("waiting for participants to exit")
|
||||||
logger.Infow("waiting for participants to exit")
|
waitingForParticipants = s.roomManager.HasParticipants()
|
||||||
waitingForParticipants = s.roomManager.HasParticipants()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
partTicker.Stop()
|
partTicker.Stop()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user