New creates a Server. The server will manage sources for a given username@hostname.
(ctx context.Context, options *Options)
| 1107 | // New creates a Server. |
| 1108 | // The server will manage sources for a given username@hostname. |
| 1109 | func New(ctx context.Context, options *Options) (*Server, error) { |
| 1110 | if options.Authorizer == nil { |
| 1111 | return nil, errors.New("missing authorizer") |
| 1112 | } |
| 1113 | |
| 1114 | if options.PasswordPersist == nil { |
| 1115 | return nil, errors.New("missing password persistence") |
| 1116 | } |
| 1117 | |
| 1118 | if options.AuthCookieSigningKey == "" { |
| 1119 | // generate random signing key |
| 1120 | options.AuthCookieSigningKey = uuid.New().String() |
| 1121 | } |
| 1122 | |
| 1123 | s := &Server{ |
| 1124 | rootctx: ctx, |
| 1125 | options: *options, |
| 1126 | sourceManagers: map[snapshot.SourceInfo]*sourceManager{}, |
| 1127 | maxParallelSnapshots: 1, |
| 1128 | grpcServerState: makeGRPCServerState(options.MaxConcurrency), |
| 1129 | authenticator: options.Authenticator, |
| 1130 | authorizer: options.Authorizer, |
| 1131 | taskmgr: uitask.NewManager(options.PersistentLogs), |
| 1132 | mounts: map[object.ID]mount.Controller{}, |
| 1133 | authCookieSigningKey: []byte(options.AuthCookieSigningKey), |
| 1134 | nextRefreshTime: clock.Now().Add(options.RefreshInterval), |
| 1135 | schedulerRefresh: make(chan string, 1), |
| 1136 | } |
| 1137 | |
| 1138 | s.parallelSnapshotsChanged = sync.NewCond(&s.parallelSnapshotsMutex) |
| 1139 | |
| 1140 | return s, nil |
| 1141 | } |
no test coverage detected