(ctx context.Context, bucket string, dbName string)
| 1812 | } |
| 1813 | |
| 1814 | func (sc *ServerContext) _fetchDatabaseFromBucket(ctx context.Context, bucket string, dbName string) (found bool, cnf DatabaseConfig, err error) { |
| 1815 | |
| 1816 | cas, err := sc.BootstrapContext.GetConfig(ctx, bucket, sc.Config.Bootstrap.ConfigGroupID, dbName, &cnf) |
| 1817 | if errors.Is(err, base.ErrNotFound) { |
| 1818 | base.DebugfCtx(ctx, base.KeyConfig, "%q did not contain config in group %q", bucket, sc.Config.Bootstrap.ConfigGroupID) |
| 1819 | return false, cnf, err |
| 1820 | } |
| 1821 | if err != nil { |
| 1822 | base.DebugfCtx(ctx, base.KeyConfig, "unable to fetch config in group %q from bucket %q: %v", sc.Config.Bootstrap.ConfigGroupID, bucket, err) |
| 1823 | return false, cnf, err |
| 1824 | } |
| 1825 | |
| 1826 | if cnf.Name == "" { |
| 1827 | cnf.Name = bucket |
| 1828 | } |
| 1829 | |
| 1830 | if cnf.Name != dbName { |
| 1831 | base.TracefCtx(ctx, base.KeyConfig, "%q did not contain config in group %q for db %q", bucket, sc.Config.Bootstrap.ConfigGroupID, dbName) |
| 1832 | return false, cnf, err |
| 1833 | } |
| 1834 | |
| 1835 | cnf.cfgCas = cas |
| 1836 | |
| 1837 | // inherit properties the bootstrap config |
| 1838 | cnf.CACertPath = sc.Config.Bootstrap.CACertPath |
| 1839 | |
| 1840 | // We need to check for corruption in the database config (CC. CBG-3292). If the fetched config doesn't match the |
| 1841 | // bucket name we got the config from we need to maker this db context as corrupt. Then remove the context and |
| 1842 | // in memory representation on the server context. |
| 1843 | if bucket != cnf.GetBucketName() { |
| 1844 | sc._handleInvalidDatabaseConfig(ctx, bucket, cnf, nil) |
| 1845 | return true, cnf, fmt.Errorf("mismatch in persisted database bucket name %q vs the actual bucket name %q. Please correct db %q's config, groupID %q.", base.MD(cnf.Bucket), base.MD(bucket), base.MD(cnf.Name), base.MD(sc.Config.Bootstrap.ConfigGroupID)) |
| 1846 | } |
| 1847 | bucketCopy := bucket |
| 1848 | // no corruption detected carry on as usual |
| 1849 | cnf.Bucket = &bucketCopy |
| 1850 | |
| 1851 | // any authentication fields defined on the dbconfig take precedence over any in the bootstrap config |
| 1852 | if cnf.Username == "" && cnf.Password == "" && cnf.CertPath == "" && cnf.KeyPath == "" { |
| 1853 | cnf.Username = sc.Config.Bootstrap.Username |
| 1854 | cnf.Password = sc.Config.Bootstrap.Password |
| 1855 | cnf.CertPath = sc.Config.Bootstrap.X509CertPath |
| 1856 | cnf.KeyPath = sc.Config.Bootstrap.X509KeyPath |
| 1857 | } |
| 1858 | base.TracefCtx(ctx, base.KeyConfig, "Got database config %s for bucket %q with cas %d and groupID %q", base.MD(dbName), base.MD(bucket), cas, base.MD(sc.Config.Bootstrap.ConfigGroupID)) |
| 1859 | return true, cnf, nil |
| 1860 | } |
| 1861 | |
| 1862 | func (sc *ServerContext) _fetchDatabase(ctx context.Context, dbName string) (found bool, dbConfig *DatabaseConfig, err error) { |
| 1863 | var cnf DatabaseConfig |
no test coverage detected