oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package equipo
2
3import (
4 "amadan.net/oficina/equipo/internal/equipo/team"
5 "context"
6 "database/sql"
7 "errors"
8 "gorm.io/gorm"
9 "gorm.io/plugin/dbresolver"
10 "time"
11)
12
13func (a *RosterAuthority) coordinator(ctx context.Context, req team.AdmissionRequest) (team.Admission, error) {
14 person := req.Target.Subject
15 if !validAddress(person) || req.Grant != CoordinatorGrantRef(person) || req.Project != 0 || req.Target.Repository != "" || req.Target.Ref != "" || req.Target.DefaultRef != "" || req.Target.BaseRevision != "" || req.Target.App != "" {
16 return team.Admission{}, team.ErrGrantRevoked
17 }
18 if req.Operation != team.OpProviderCall && req.Operation != team.OpJobContinue && req.Operation != team.OpAttemptContinue {
19 return team.Admission{}, team.ErrGrantRevoked
20 }
21 var out team.Admission
22 check := func(tx *gorm.DB) error {
23 b, err := conversationAt(tx).Binding(Actor{Address: person})
24 if err != nil {
25 return err
26 }
27 if string(req.Account) != b.TeamID {
28 return ErrForbidden
29 }
30 if _, err = a.store.coordinatorSelection(tx, b); err != nil {
31 return err
32 }
33 var instance Team
34 if err = tx.First(&instance).Error; err != nil {
35 return err
36 }
37 now := a.clock.Now()
38 out = team.Admission{Grant: req.Grant, Version: b.Generation, Epoch: instance.RosterEpoch, IssuedAt: now, ExpiresAt: now.Add(5 * time.Second)}
39 return nil
40 }
41 var err error
42 if tx, ok := ctx.Value(runnerTxKey{}).(*gorm.DB); ok {
43 err = check(tx)
44 } else {
45 err = a.store.db.G.WithContext(ctx).Clauses(dbresolver.Read).Transaction(check, &sql.TxOptions{ReadOnly: true})
46 }
47 if err != nil {
48 if errors.Is(err, ErrForbidden) || errors.Is(err, ErrNotFound) || errors.Is(err, gorm.ErrRecordNotFound) {
49 return out, team.ErrGrantRevoked
50 }
51 return out, team.ErrAuthorityUnavailable
52 }
53 return out, nil
54}
55