setupCtx enriches the base context with values from config file and database. This is called after files and database have been initialized.
(ctx context.DnoteCtx)
| 142 | // setupCtx enriches the base context with values from config file and database. |
| 143 | // This is called after files and database have been initialized. |
| 144 | func setupCtx(ctx context.DnoteCtx) (context.DnoteCtx, error) { |
| 145 | db := ctx.DB |
| 146 | |
| 147 | var sessionKey string |
| 148 | var sessionKeyExpiry int64 |
| 149 | |
| 150 | err := db.QueryRow("SELECT value FROM system WHERE key = ?", consts.SystemSessionKey).Scan(&sessionKey) |
| 151 | if err != nil && err != sql.ErrNoRows { |
| 152 | return ctx, errors.Wrap(err, "finding sesison key") |
| 153 | } |
| 154 | err = db.QueryRow("SELECT value FROM system WHERE key = ?", consts.SystemSessionKeyExpiry).Scan(&sessionKeyExpiry) |
| 155 | if err != nil && err != sql.ErrNoRows { |
| 156 | return ctx, errors.Wrap(err, "finding sesison key expiry") |
| 157 | } |
| 158 | |
| 159 | cf, err := config.Read(ctx) |
| 160 | if err != nil { |
| 161 | return ctx, errors.Wrap(err, "reading config") |
| 162 | } |
| 163 | |
| 164 | ret := context.DnoteCtx{ |
| 165 | Paths: ctx.Paths, |
| 166 | Version: ctx.Version, |
| 167 | DB: ctx.DB, |
| 168 | SessionKey: sessionKey, |
| 169 | SessionKeyExpiry: sessionKeyExpiry, |
| 170 | APIEndpoint: cf.APIEndpoint, |
| 171 | Editor: cf.Editor, |
| 172 | Clock: clock.New(), |
| 173 | EnableUpgradeCheck: cf.EnableUpgradeCheck, |
| 174 | HTTPClient: client.NewRateLimitedHTTPClient(), |
| 175 | } |
| 176 | |
| 177 | return ret, nil |
| 178 | } |
| 179 | |
| 180 | // getLegacyDnotePath returns a legacy dnote directory path placed under |
| 181 | // the user's home directory |
no test coverage detected