-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathserver.go
More file actions
71 lines (62 loc) · 3.49 KB
/
Copy pathserver.go
File metadata and controls
71 lines (62 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package scd
import (
"context"
"time"
"github.com/interuss/dss/pkg/api/v1/scdpb"
"github.com/interuss/dss/pkg/auth"
dsserr "github.com/interuss/dss/pkg/errors"
scdmodels "github.com/interuss/dss/pkg/scd/models"
scdstore "github.com/interuss/dss/pkg/scd/store"
"github.com/interuss/stacktrace"
)
const (
strategicCoordinationScope = "utm.strategic_coordination"
constraintManagementScope = "utm.constraint_management"
constraintConsumptionScope = "utm.constraint_consumption"
)
func makeSubscribersToNotify(subscriptions []*scdmodels.Subscription) []*scdpb.SubscriberToNotify {
result := []*scdpb.SubscriberToNotify{}
subscriptionsByURL := map[string][]*scdpb.SubscriptionState{}
for _, sub := range subscriptions {
subState := &scdpb.SubscriptionState{
SubscriptionId: sub.ID.String(),
NotificationIndex: int32(sub.NotificationIndex),
}
subscriptionsByURL[sub.BaseURL] = append(subscriptionsByURL[sub.BaseURL], subState)
}
for url, states := range subscriptionsByURL {
result = append(result, &scdpb.SubscriberToNotify{
UssBaseUrl: url,
Subscriptions: states,
})
}
return result
}
// Server implements scdpb.DiscoveryAndSynchronizationService.
type Server struct {
Store scdstore.Store
Timeout time.Duration
}
// AuthScopes returns a map of endpoint to required Oauth scope.
func (a *Server) AuthScopes() map[auth.Operation]auth.KeyClaimedScopesValidator {
// TODO: replace with correct scopes
return map[auth.Operation]auth.KeyClaimedScopesValidator{
"/scdpb.UTMAPIUSSDSSAndUSSUSSService/DeleteConstraintReference": auth.RequireAnyScope(constraintManagementScope),
"/scdpb.UTMAPIUSSDSSAndUSSUSSService/DeleteOperationReference": auth.RequireAnyScope(strategicCoordinationScope),
"/scdpb.UTMAPIUSSDSSAndUSSUSSService/DeleteSubscription": auth.RequireAnyScope(strategicCoordinationScope, constraintConsumptionScope),
"/scdpb.UTMAPIUSSDSSAndUSSUSSService/GetConstraintReference": auth.RequireAnyScope(strategicCoordinationScope, constraintConsumptionScope, constraintManagementScope),
"/scdpb.UTMAPIUSSDSSAndUSSUSSService/GetOperationReference": auth.RequireAnyScope(strategicCoordinationScope),
"/scdpb.UTMAPIUSSDSSAndUSSUSSService/GetSubscription": auth.RequireAnyScope(strategicCoordinationScope, constraintConsumptionScope),
"/scdpb.UTMAPIUSSDSSAndUSSUSSService/MakeDssReport": auth.RequireAnyScope(strategicCoordinationScope, constraintConsumptionScope, constraintManagementScope),
"/scdpb.UTMAPIUSSDSSAndUSSUSSService/PutConstraintReference": auth.RequireAnyScope(constraintManagementScope),
"/scdpb.UTMAPIUSSDSSAndUSSUSSService/PutOperationReference": auth.RequireAnyScope(strategicCoordinationScope),
"/scdpb.UTMAPIUSSDSSAndUSSUSSService/PutSubscription": auth.RequireAnyScope(strategicCoordinationScope, constraintConsumptionScope),
"/scdpb.UTMAPIUSSDSSAndUSSUSSService/QueryConstraintReferences": auth.RequireAnyScope(strategicCoordinationScope, constraintConsumptionScope, constraintManagementScope),
"/scdpb.UTMAPIUSSDSSAndUSSUSSService/QuerySubscriptions": auth.RequireAnyScope(strategicCoordinationScope, constraintConsumptionScope),
"/scdpb.UTMAPIUSSDSSAndUSSUSSService/SearchOperationReferences": auth.RequireAnyScope(strategicCoordinationScope),
}
}
// MakeDssReport creates an error report about a DSS.
func (a *Server) MakeDssReport(ctx context.Context, req *scdpb.MakeDssReportRequest) (*scdpb.ErrorReport, error) {
return nil, stacktrace.NewErrorWithCode(dsserr.BadRequest, "Not yet implemented")
}