Example #1
0
func loadConfig() *config.Config {
	// We do not use guessRepoFolder() here. It might abort
	folder := repo.GuessFolder()
	cfg, err := repoconfig.LoadConfig(filepath.Join(folder, ".brig", "config"))
	if err != nil {
		log.Warningf("Could not load config: %v", err)
		log.Warningf("Falling back on config defaults...")
		return repoconfig.CreateDefaultConfig()
	}

	return cfg
}
Example #2
0
func lookupID(configPath string) (id.ID, error) {
	cfg, err := config.LoadConfig(configPath)
	if err != nil {
		return "", fmt.Errorf("Could not load config: %v", err)
	}

	idString, err := cfg.String("repository.id")
	if err != nil {
		return "", fmt.Errorf("No ID in config: %v", err)
	}

	ID, err := id.Cast(idString)
	if err != nil {
		return "", err
	}

	return ID, nil
}
Example #3
0
// loadRepository load a brig repository from a given folder.
func loadRepository(pwd, folder string) (*Repository, error) {
	absFolderPath, err := filepath.Abs(folder)
	if err != nil {
		return nil, err
	}

	brigPath := filepath.Join(absFolderPath, ".brig")
	cfg, err := config.LoadConfig(filepath.Join(brigPath, "config"))
	if err != nil {
		return nil, err
	}

	configValues := map[string]string{
		"repository.id": "",
	}

	for key := range configValues {
		configValues[key], err = cfg.String(key)
		if err != nil {
			return nil, err
		}
	}

	idString, err := cfg.String("repository.id")
	if err != nil {
		return nil, err
	}

	ID, err := id.Cast(idString)
	if err != nil {
		return nil, err
	}

	remoteStore, err := NewYAMLRemotes(filepath.Join(brigPath, "remotes.yml"))
	if err != nil {
		return nil, err
	}

	ipfsSwarmPort, err := cfg.Int("ipfs.swarmport")
	if err != nil {
		return nil, err
	}

	ipfsLayer := ipfsutil.NewWithPort(
		filepath.Join(brigPath, "ipfs"),
		ipfsSwarmPort,
	)

	hash, err := ipfsLayer.Identity()
	if err != nil {
		return nil, err
	}

	ownStore, err := store.Open(brigPath, id.NewPeer(ID, hash), ipfsLayer)
	if err != nil {
		return nil, err
	}

	allStores := make(map[id.ID]*store.Store)
	allStores[ID] = ownStore

	repo := Repository{
		ID:             ID,
		Folder:         absFolderPath,
		Remotes:        remoteStore,
		InternalFolder: brigPath,
		Config:         cfg,
		OwnStore:       ownStore,
		Password:       pwd,
		IPFS:           ipfsLayer,
		allStores:      make(map[id.ID]*store.Store),
	}

	return &repo, nil
}