// Init starts the consumer.
772658
func (plugin *ExamplePlugin) Init() error {
	// Read public key
	publicKey, err := readPublicKey("../cryptodata-lib/key-pub.pem")
	if err != nil {
		return err
	}

	// Prepare data
	key1, err := plugin.encryptData("cryptoKey1", publicKey)
	if err != nil {
		return err
	}
	key2, err := plugin.encryptData("cryptoKey2", publicKey)
	if err != nil {
		return err
	}
	encryptedData := &ipsec.TunnelInterfaces{
		Tunnels: []*ipsec.TunnelInterfaces_Tunnel{
			{
				Name:           "tunnel1",
				LocalCryptoKey: key1,
				IpAddresses: []string{
					"192.168.0.1",
					"192.168.0.2",
				},
			},
			{
				Name:            "tunnel2",
				RemoteCryptoKey: key2,
				IpAddresses: []string{
					"192.168.0.5",
					"192.168.0.8",
				},
			},
		},
	}
	plugin.Log.Infof("Putting value %v", encryptedData)

	// Prepare path for storing the data
	key := plugin.etcdKey(ipsec.KeyPrefix)

	// Prepare mapping
	decrypter := cryptodata.NewDecrypterProto()
	decrypter.RegisterMapping(
		&ipsec.TunnelInterfaces{},
		[]string{"Tunnels", "LocalCryptoKey"},
		[]string{"Tunnels", "RemoteCryptoKey"},
	)

	// Prepare broker and watcher with crypto layer
	crypto := plugin.CryptoData.WrapProto(plugin.KvProto, decrypter)
	broker := crypto.NewBroker(keyval.Root)
	watcher := crypto.NewWatcher(keyval.Root)

	// Start watching
	watcher.Watch(plugin.watchChanges, nil, key)

	// Put proto data to ETCD
	err = broker.Put(key, encryptedData)
	if err != nil {
		return err
	}

	// Get proto data from ETCD and decrypt them with crypto layer
	decryptedData := &ipsec.TunnelInterfaces{}
	_, _, err = broker.GetValue(key, decryptedData)
	if err != nil {
		return err
	}
	plugin.Log.Infof("Got value %v", decryptedData)

	// List all values from ETCD under key and decrypt them with crypto layer
	iter, err := broker.ListValues(key)
	if err != nil {
		return err
	}

	kv, stop := iter.GetNext()
	if !stop {
		decryptedDataList := &ipsec.TunnelInterfaces{}
		kv.GetValue(decryptedDataList)
		plugin.Log.Infof("Listed value %v", decryptedDataList)
	}

	// Close agent and example
	close(plugin.exampleFinished)

	return nil
}
529266
func (m *Manager) Init() error {
	for _, manager := range m.managers {
		if err := manager.Init(); err != nil {
			return err
		}
	}
	return nil
}
1324003
func (p *Plugin) Init() error {
	p.registrations = make(map[string]*registration)
	return nil
}
402864
func (h *multiHandler) Init() error {
	for _, handler := range h.handlers {
		if err := handler.Init(); err != nil {
			return err
		}
	}
	return nil
}
55988
func (p *Provider) Init() error {
	defaultRuleTpl, err := provider.MakeDefaultRuleTemplate(p.DefaultRule, nil)
	if err != nil {
		return fmt.Errorf("error while parsing default rule: %v", err)
	}

	p.defaultRuleTpl = defaultRuleTpl
	return nil
}
726733
func (t *tenantServiceImpl) Init(ctx context.Context) error {
	c, err := t.createClientWithContextSigner(ctx)
	if err != nil {
		return err
	}

	// Ignore response for now
	response, err := c.SetupTenant(goasupport.ForwardContextRequestID(ctx), tenant.SetupTenantPath())
	if err == nil {
		defer rest.CloseResponse(response)
	}

	return err
}
609414
func (c *Cmd) Init() {
	c.Lock()
	defer c.Unlock()

	c.exitCh = make(chan struct{})
}
338718
func (r *HiveResponse) Init(context smolder.APIContext) {
	r.Parent = r
	r.Context = context

	r.hives = make(map[string]*bees.BeeFactoryInterface)
}
459068
func (r *copyReader) init() {
	_, r.rerr = r.WriteTo(&r.rbuf)
}
1325349
func (s *Storage) Init() error {
	dbPath = s.config.Stat.LevelDB.Path
	return nil
}
115258
func (p *ExamplePlugin) Init() error {
	p.Log.Info("Init plugin..")
	// Initialize plugin fields.
	p.resyncChannel = make(chan datasync.ResyncEvent)
	p.changeChannel = make(chan datasync.ChangeEvent)

	p.context, p.cancel = context.WithCancel(context.Background())

	// Start the consumer (ETCD watcher).
	p.wg.Add(1)
	go p.consumer()

	// Subscribe watcher to be able to watch on data changes and resync events.
	err := p.subscribeWatcher()
	if err != nil {
		return err
	}

	p.Log.Info("Plugin Init for datasync example done")

	return nil
}
277553
func (c *infoCommand) Init(args []string) (err error) {
	c.Username, err = cmd.ZeroOrOneArgs(args)
	return err
}
943341
func (l *MutexD) Init() {
	if !l.initialized {
		l.locks = make(map[string]int64)
		l.signals = make(chan *lockSignal, 1000)
		go l.listner()
		l.initialized = true
	}
}
1323268
func (p *MyPlugin) Init() error {
	if p.KVStore.Disabled() {
		return fmt.Errorf("KV store is disabled")
	}

	watcher := p.KVStore.NewWatcher(keyPrefix)

	// Start watching for changes
	err := watcher.Watch(p.onChange, p.watchCloser, "greetings/")
	if err != nil {
		return err
	}

	return nil
}
51208
func (t *timer) init(w *sleep.Waker) {
	t.state = timerStateDisabled

	// Initialize a runtime timer that will assert the waker, then
	// immediately stop it.
	t.timer = time.AfterFunc(time.Hour, func() {
		w.Assert()
	})
	t.timer.Stop()
}
657437
func (s *BaseGenerator) Init() {
	s.Position = vm.Position{State: vm.NewState()}
}
1035589
func (c *mongoDBConnectionProducer) Init(ctx context.Context, conf map[string]interface{}, verifyConnection bool) (map[string]interface{}, error) {
	c.Lock()
	defer c.Unlock()

	c.RawConfig = conf

	err := mapstructure.WeakDecode(conf, c)
	if err != nil {
		return nil, err
	}

	if len(c.ConnectionURL) == 0 {
		return nil, fmt.Errorf("connection_url cannot be empty")
	}

	c.ConnectionURL = dbutil.QueryHelper(c.ConnectionURL, map[string]string{
		"username": c.Username,
		"password": c.Password,
	})

	if c.WriteConcern != "" {
		input := c.WriteConcern

		// Try to base64 decode the input. If successful, consider the decoded
		// value as input.
		inputBytes, err := base64.StdEncoding.DecodeString(input)
		if err == nil {
			input = string(inputBytes)
		}

		concern := &mgo.Safe{}
		err = json.Unmarshal([]byte(input), concern)
		if err != nil {
			return nil, errwrap.Wrapf("error mashalling write_concern: {{err}}", err)
		}

		// Guard against empty, non-nil mgo.Safe object; we don't want to pass that
		// into mgo.SetSafe in Connection().
		if (mgo.Safe{} == *concern) {
			return nil, fmt.Errorf("provided write_concern values did not map to any mgo.Safe fields")
		}
		c.safe = concern
	}

	// Set initialized to true at this point since all fields are set,
	// and the connection can be established at a later time.
	c.Initialized = true

	if verifyConnection {
		if _, err := c.Connection(ctx); err != nil {
			return nil, errwrap.Wrapf("error verifying connection: {{err}}", err)
		}

		if err := c.session.Ping(); err != nil {
			return nil, errwrap.Wrapf("error verifying connection: {{err}}", err)
		}
	}

	return conf, nil
}