github.com/ethanhsieh/snapd@v0.0.0-20210615102523-3db9b8e4edc5/store/devicenauthctx.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2016-2019 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package store 21 22 import ( 23 "errors" 24 "net/url" 25 26 "github.com/snapcore/snapd/asserts" 27 "github.com/snapcore/snapd/overlord/auth" 28 ) 29 30 // A DeviceAndAuthContext mediates access to device and auth information for the store. 31 type DeviceAndAuthContext interface { 32 Device() (*auth.DeviceState, error) 33 34 UpdateDeviceAuth(device *auth.DeviceState, sessionMacaroon string) (actual *auth.DeviceState, err error) 35 36 UpdateUserAuth(user *auth.UserState, discharges []string) (actual *auth.UserState, err error) 37 38 StoreID(fallback string) (string, error) 39 40 DeviceSessionRequestParams(nonce string) (*DeviceSessionRequestParams, error) 41 ProxyStoreParams(defaultURL *url.URL) (proxyStoreID string, proxySroreURL *url.URL, err error) 42 43 CloudInfo() (*auth.CloudInfo, error) 44 } 45 46 // DeviceSessionRequestParams gathers the assertions and information to be sent to request a device session. 47 type DeviceSessionRequestParams struct { 48 Request *asserts.DeviceSessionRequest 49 Serial *asserts.Serial 50 Model *asserts.Model 51 } 52 53 func (p *DeviceSessionRequestParams) EncodedRequest() string { 54 return string(asserts.Encode(p.Request)) 55 } 56 57 func (p *DeviceSessionRequestParams) EncodedSerial() string { 58 return string(asserts.Encode(p.Serial)) 59 } 60 61 func (p *DeviceSessionRequestParams) EncodedModel() string { 62 return string(asserts.Encode(p.Model)) 63 } 64 65 var ( 66 // ErrNoSerial indicates that a device serial is not set yet. 67 ErrNoSerial = errors.New("no device serial yet") 68 )