MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / NewServer

Function NewServer

pkg/basicstation/cups/server.go:168–214  ·  view source on GitHub ↗

NewServer returns a new CUPS server.

(ctx context.Context, c *component.Component, conf ServerConfig, options ...Option)

Source from the content-addressed store, hash-verified

166
167// NewServer returns a new CUPS server.
168func NewServer(ctx context.Context, c *component.Component, conf ServerConfig, options ...Option) (*Server, error) {
169 options = append([]Option{
170 WithAllowCUPSURIUpdate(conf.AllowCUPSURIUpdate),
171 WithDefaultLNSURI(conf.Default.LNSURI),
172 }, options...)
173
174 var registerUnknownTo *ttnpb.OrganizationOrUserIdentifiers
175 switch conf.RegisterUnknown.Type {
176 case "user":
177 registerUnknownTo = (&ttnpb.UserIdentifiers{
178 UserId: conf.RegisterUnknown.ID,
179 }).GetOrganizationOrUserIdentifiers()
180 case "organization":
181 registerUnknownTo = (&ttnpb.OrganizationIdentifiers{
182 OrganizationId: conf.RegisterUnknown.ID,
183 }).GetOrganizationOrUserIdentifiers()
184 }
185 if registerUnknownTo != nil && conf.RegisterUnknown.APIKey != "" {
186 options = append(options,
187 WithRegisterUnknown(registerUnknownTo, func(_ context.Context) grpc.CallOption {
188 return grpc.PerRPCCredentials(rpcmetadata.MD{
189 AuthType: "bearer",
190 AuthValue: conf.RegisterUnknown.APIKey,
191 AllowInsecure: c.AllowInsecureForCredentials(),
192 })
193 }),
194 )
195 }
196
197 // The Server.tlsConfig is used when dialing a CUPS or an LNS server to query its certificate chain.
198 // When dialing servers with self-signed certs, the Root CA of target server must either be trusted by the system or
199 // added explicitly via the `--tls.root-ca` option.
200 if tlsConfig, err := c.GetTLSClientConfig(c.Context()); err == nil {
201 options = append(options, WithTLSConfig(tlsConfig))
202 }
203
204 s := &Server{
205 component: c,
206 signers: make(map[uint32]stdcrypto.Signer),
207 trustCache: make(map[string]*x509.Certificate),
208 }
209 for _, opt := range options {
210 opt(s)
211 }
212 c.RegisterWeb(s)
213 return s, nil
214}
215
216// RegisterRoutes implements web.Registerer.
217func (s *Server) RegisterRoutes(srv *web.Server) {

Callers 3

NewFunction · 0.92
TestGetTrustFunction · 0.70
TestServerFunction · 0.70

Calls 9

WithAllowCUPSURIUpdateFunction · 0.85
WithDefaultLNSURIFunction · 0.85
WithRegisterUnknownFunction · 0.85
RegisterWebMethod · 0.80
WithTLSConfigFunction · 0.70
GetTLSClientConfigMethod · 0.65
ContextMethod · 0.65

Tested by 2

TestGetTrustFunction · 0.56
TestServerFunction · 0.56