Debian Codegraph @

metadata/providers/cached/provider.go

raw symbols SCIP
1 package cachedscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/
2
3 import (
4 "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/"
5 "ioscip-go gomod github.com/golang/go/src go1.25.0 io/"
6 "net/httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/"
7 "osscip-go gomod github.com/golang/go/src go1.25.0 os/"
8
9 "github.com/go-webauthn/webauthn/metadatascip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/"
10 )
11
12 // New returns a new cached Provider given a set of functional [Option]'s. This provider will download a new version and
13 // save it to the configured file path if it doesn't exist or if it's out of date by default.
14 func Newscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/New().(opts ...Optionscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Option#) (provider metadatascip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/.Providerscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/Provider#, err error) {
15 p := &Providerscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#{
16 updatescip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#update.: true,
17 uriscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#uri.: metadatascip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/.ProductionMDSURLscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/ProductionMDSURL.,
18 }
19
20 for _, opt := range opts {
21 if err = opt(p); err != nil {
22 return nil, err
23 }
24 }
25
26 if p.namescip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#name. == "" {
27 return nil, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("provider configured without setting a path for the cached file blob")
28 }
29
30 if p.newupscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#newup. == nil {
31 p.newupscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#newup. = defaultNewscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/defaultNew().
32 }
33
34 if p.decoderscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#decoder. == nil {
35 if p.decoderscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#decoder., err = metadatascip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/.NewDecoderscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/NewDecoder().(metadatascip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/.WithIgnoreEntryParsingErrorsscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/WithIgnoreEntryParsingErrors().()); err != nil {
36 return nil, err
37 }
38 }
39
40 if p.clockscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#clock. == nil {
41 p.clockscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#clock. = &metadatascip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/.RealClockscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/RealClock#{}
42 }
43
44 if err = p.initscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#init().(); err != nil {
45 return nil, err
46 }
47
48 return p, nil
49 }
50
51 // Provider implements a [metadata.Provider] with a file-based cache.
52 type Providerscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider# struct {
53 metadatascip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/.Providerscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#Provider.
54
55 namescip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#name. string
56 uriscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#uri. string
57 updatescip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#update. bool
58 forcescip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#force. bool
59 clockscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#clock. metadatascip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/.Clockscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/Clock#
60 clientscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#client. *httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Clientscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Client#
61 decoderscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#decoder. *metadatascip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/.Decoderscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/Decoder#
62 newupscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#newup. NewFuncscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/NewFunc#
63 }
64
65 func (p *Providerscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#) initscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#init().() (err error) {
66 var (
67 f *osscip-go gomod github.com/golang/go/src go1.25.0 os/.Filescip-go gomod github.com/golang/go/src go1.25.0 os/File#
68 rc ioscip-go gomod github.com/golang/go/src go1.25.0 io/.ReadCloserscip-go gomod github.com/golang/go/src go1.25.0 io/ReadCloser#
69 created bool
70 mds *metadatascip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/.Metadatascip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/Metadata#
71 )
72
73 if f, created, err = doOpenOrCreatescip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/doOpenOrCreate().(p.namescip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#name.); err != nil {
74 return err
75 }
76
77 defer f.Closescip-go gomod github.com/golang/go/src go1.25.0 os/File#Close().()
78
79 if created || p.forcescip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#force. {
80 if rc, err = p.getscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#get().(); err != nil {
81 return err
82 }
83 } else {
84 if mds, err = p.parsescip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#parse().(f); err != nil {
85 return err
86 }
87
88 if p.outdatedscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#outdated().(mds) {
89 if rc, err = p.getscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#get().(); err != nil {
90 return err
91 }
92 }
93 }
94
95 if rc != nil {
96 if err = doTruncateCopyAndSeekStartscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/doTruncateCopyAndSeekStart().(f, rc); err != nil {
97 return err
98 }
99
100 if mds, err = p.parsescip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#parse().(f); err != nil {
101 return err
102 }
103 }
104
105 var provider metadatascip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/.Providerscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/Provider#
106
107 if provider, err = p.newupscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#newup.(mds); err != nil {
108 return err
109 }
110
111 p.Providerscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#Provider. = provider
112
113 return nil
114 }
115
116 func (p *Providerscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#) parsescip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#parse().(rc ioscip-go gomod github.com/golang/go/src go1.25.0 io/.ReadCloserscip-go gomod github.com/golang/go/src go1.25.0 io/ReadCloser#) (data *metadatascip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/.Metadatascip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/Metadata#, err error) {
117 var payload *metadatascip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/.PayloadJSONscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/PayloadJSON#
118
119 if payload, err = p.decoderscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#decoder..Decodescip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/Decoder#Decode().(rc); err != nil {
120 return nil, err
121 }
122
123 if data, err = p.decoderscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#decoder..Parsescip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/Decoder#Parse().(payload); err != nil {
124 return nil, err
125 }
126
127 return data, nil
128 }
129
130 func (p *Providerscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#) outdatedscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#outdated().(mds *metadatascip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/.Metadatascip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/Metadata#) bool {
131 return p.updatescip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#update. && p.clockscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#clock..Nowscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/Clock#Now.().Afterscip-go gomod github.com/golang/go/src go1.25.0 time/Time#After().(mds.Parsedscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/Metadata#Parsed..NextUpdatescip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata`/Parsed#NextUpdate.)
132 }
133
134 func (p *Providerscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#) getscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#get().() (f ioscip-go gomod github.com/golang/go/src go1.25.0 io/.ReadCloserscip-go gomod github.com/golang/go/src go1.25.0 io/ReadCloser#, err error) {
135 if p.clientscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#client. == nil {
136 p.clientscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#client. = &httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Clientscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Client#{}
137 }
138
139 var res *httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Responsescip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Response#
140
141 if res, err = p.clientscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#client..Getscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Client#Get().(p.uriscip-go gomod github.com/go-webauthn/webauthn . `github.com/go-webauthn/webauthn/metadata/providers/cached`/Provider#uri.); err != nil {
142 return nil, err
143 }
144
145 return res.Bodyscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Response#Body., nil
146 }