Beispiel #1
0
func (a *acdb) online() error {
	a.Log(acd.DebugTrace, "[TRC] online")

	keysFilename, err := shared.DefaultKeysFilename()
	if err != nil {
		return err
	}
	rootDir := path.Dir(keysFilename)
	err = os.MkdirAll(rootDir, 0700)
	if err != nil {
		return err
	}

	filename := path.Join(rootDir, shared.TokenFilename)
	a.c, err = acd.NewClient(filename, a.Debugger)
	if err != nil {
		return fmt.Errorf("%v: %v", filename, err)
	}

	err = shared.LoadKeys(keysFilename, &a.keys)
	if err != nil {
		return err
	}

	// get root folders
	children, err := a.c.GetChildrenJSON("",
		"?filters=kind:"+acd.AssetFolder)
	if err != nil {
		return err
	}

	// save off data and metadata ids
	count := 0
	for _, v := range children.Data {
		switch v.Name {
		case dataName:
			a.dataID = v.ID
		case metadataName:
			a.metadataID = v.ID
		default:
			continue
		}
		count++
		if count == 2 {
			break
		}
	}
	if count != 2 {
		err = a.makeDirectories()
		if err != nil {
			return fmt.Errorf("could not create required "+
				"directories: %v", err)
		}
	}
	a.Log(debugApp, "[APP] root: %v data: %v metadata: %v",
		a.c.GetRoot(),
		a.dataID,
		a.metadataID)

	err = a.downloadSecrets()
	if err != nil {
		return err
	}

	return nil
}
Beispiel #2
0
func _main() error {
	debugLevel := flag.Int("d", 0, "debug level: 0 off, 1 trace, 2 loud")
	debugTarget := flag.String("l", "-", "debug target file name, - is stdout")
	compress := flag.Bool("c", false, "try to compress (default = false)")
	extract := flag.Bool("e", false, "extract files")
	flag.Parse()

	args := flag.Args()
	if len(args) == 0 {
		fmt.Printf("sfe [-d][-l target] <filename> ...\n")
		flag.PrintDefaults()
		return nil
	}

	var (
		err error
	)

	s := sfe{
		compress: *compress,
	}
	defer func() {
		goutil.Zero(s.keys.MD[:])
		goutil.Zero(s.keys.Data[:])
		goutil.Zero(s.keys.Dedup[:])
	}()

	// debug target
	if *debugTarget == "-" {
		s.Debugger, err = debug.NewDebugStdout()
		if err != nil {
			return err
		}
	} else {
		s.Debugger, err = debug.NewDebugFile(*debugTarget)
		if err != nil {
			return err
		}
	}

	switch *debugLevel {
	case 0:
		s.Debugger = debug.NewDebugNil()
	case 1:
		s.Debugger.Mask(dbgTrace)
	case 2:
		s.Debugger.Mask(dbgTrace | dbgLoud)
	default:
		return fmt.Errorf("invalid debug level %v", *debugLevel)
	}

	keysFilename, err := shared.DefaultKeysFilename()
	if err != nil {
		return err
	}
	rootDir := path.Dir(keysFilename)
	err = os.MkdirAll(rootDir, 0700)
	if err != nil {
		return err
	}

	err = shared.LoadKeys(keysFilename, &s.keys)
	if err != nil {
		return err
	}

	for _, v := range args {
		if *extract {
			s.Log(dbgTrace, "decrypting: %v\n", v)
			err = s.decrypt(v)
			if err != nil {
				fmt.Fprintf(os.Stderr, "could not decrypt: %v\n",
					err)
				continue
			}
		} else {
			s.Log(dbgTrace, "encrypting: %v\n", v)
			err = s.encrypt(v)
			if err != nil {
				fmt.Fprintf(os.Stderr, "could not encrypt: %v\n",
					err)
				continue
			}
		}
	}

	return nil
}