Exemple #1
0
func (ks *keyStore) createKeyStore() error {
	// Create keystore directory root if it doesn't exist yet
	ksPath := ks.node.conf.getKeyStorePath()
	ks.node.Debugf("Creating Keystore at [%s]...", ksPath)

	missing, err := utils.FileMissing(ksPath, ks.node.conf.getKeyStoreFilename())
	if !missing {
		ks.node.Debugf("Creating Keystore at [%s]. Keystore already there", ksPath)
		return nil
	}

	os.MkdirAll(ksPath, 0755)

	// Create Raw material folder
	os.MkdirAll(ks.node.conf.getRawsPath(), 0755)

	// Create DB
	ks.node.Debug("Open Keystore DB...")
	db, err := sql.Open("sqlite3", filepath.Join(ksPath, ks.node.conf.getKeyStoreFilename()))
	if err != nil {
		return err
	}

	ks.node.Debug("Ping Keystore DB...")
	err = db.Ping()
	if err != nil {
		ks.node.Errorf("Failend pinged keystore DB: [%s]", err)

		return err
	}
	defer db.Close()

	ks.node.Debugf("Keystore created at [%s].", ksPath)
	return nil
}
Exemple #2
0
func (ks *keyStore) createKeyStoreIfNotExists() error {
	// Check keystore directory
	ksPath := ks.node.conf.getKeyStorePath()
	missing, err := utils.DirMissingOrEmpty(ksPath)
	ks.node.Debugf("Keystore path [%s] missing [%t]: [%s]", ksPath, missing, utils.ErrToString(err))

	if !missing {
		// Check keystore file
		missing, err = utils.FileMissing(ks.node.conf.getKeyStorePath(), ks.node.conf.getKeyStoreFilename())
		ks.node.Errorf("Keystore [%s] missing [%t]:[%s]", ks.node.conf.getKeyStoreFilePath(), missing, utils.ErrToString(err))
	}

	if missing {
		err := ks.createKeyStore()
		if err != nil {
			ks.node.Errorf("Failed creating db At [%s]: [%s]", ks.node.conf.getKeyStoreFilePath(), err.Error())
			return nil
		}
	}

	return nil
}
Exemple #3
0
func (node *nodeImpl) isRegistered() bool {
	missing, _ := utils.FileMissing(node.conf.getRawsPath(), node.conf.getEnrollmentIDFilename())

	return !missing
}