/
meeting.go
67 lines (56 loc) · 1.76 KB
/
meeting.go
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
// Copyright 2014 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package discharger
import (
"context"
"encoding/json"
"github.com/go-macaroon-bakery/macaroon-bakery/v3/httpbakery"
errgo "gopkg.in/errgo.v1"
"github.com/canonical/candid/meeting"
"github.com/canonical/candid/store"
)
type dischargeRequestInfo struct {
CaveatId []byte
Caveat []byte
Condition string
Origin string
}
type loginInfo struct {
// When a user logs in successfully their ProviderID will be supplied.
ProviderID store.ProviderIdentity
// When a login request fails, the error is filled out appropriately.
Error *httpbakery.Error
}
// place layers our desired types onto the general meeting.Place,
type place struct {
place *meeting.Place
}
func (p *place) NewRendezvous(ctx context.Context, id string, info *dischargeRequestInfo) error {
reqData, err := json.Marshal(info)
if err != nil {
return errgo.Notef(err, "cannot marshal reqData")
}
return p.place.NewRendezvous(ctx, id, reqData)
}
func (p *place) Done(ctx context.Context, id string, info *loginInfo) error {
data, err := json.Marshal(info)
if err != nil {
return errgo.Notef(err, "cannot marshal loginData")
}
return p.place.Done(ctx, id, data)
}
func (p *place) Wait(ctx context.Context, id string) (*dischargeRequestInfo, *loginInfo, error) {
reqData, loginData, err := p.place.Wait(ctx, id)
if err != nil {
return nil, nil, errgo.Notef(err, "cannot wait")
}
var info dischargeRequestInfo
if err := json.Unmarshal(reqData, &info); err != nil {
return nil, nil, errgo.Notef(err, "cannot unmarshal reqData")
}
var login loginInfo
if err := json.Unmarshal(loginData, &login); err != nil {
return nil, nil, errgo.Notef(err, "cannot unmarshal loginData")
}
return &info, &login, nil
}