コード例 #1
0
ファイル: joule_adaptor.go プロジェクト: hybridgroup/gobot
// Finalize releases all i2c devices and exported digital and pwm pins.
func (e *Adaptor) Finalize() (err error) {
	for _, pin := range e.digitalPins {
		if pin != nil {
			if errs := pin.Unexport(); errs != nil {
				err = multierror.Append(err, errs)
			}
		}
	}
	for _, pin := range e.pwmPins {
		if pin != nil {
			if errs := pin.enable("0"); errs != nil {
				err = multierror.Append(err, errs)
			}
			if errs := pin.unexport(); errs != nil {
				err = multierror.Append(err, errs)
			}
		}
	}
	if e.i2cDevice != nil {
		if errs := e.i2cDevice.Close(); errs != nil {
			err = multierror.Append(err, errs)
		}
	}
	return
}
コード例 #2
0
ファイル: output.go プロジェクト: koding/koding
func FixPerms() error {
	const read = 0444

	var merr error

	for _, file := range LogFiles {
		fi, err := os.Stat(file)
		if err != nil {
			if !os.IsNotExist(err) {
				merr = multierror.Append(merr, err)
			}

			continue
		}

		if (fi.Mode() & read) != read {
			err = os.Chmod(fi.Name(), fi.Mode()|read)
			if err != nil {
				merr = multierror.Append(merr, err)
			}
		}
	}

	return merr
}
コード例 #3
0
ファイル: tunnelproxy.go プロジェクト: koding/koding
func (c *callbacks) call(ident string) (err error) {
	c.mu.Lock()
	fns, ok := c.m[ident]
	delete(c.m, ident)
	c.mu.Unlock()

	if !ok {
		return nil
	}

	for i := range fns {
		// Start executing from callbacks from the newest to the oldest (like defer).
		fn := fns[len(fns)-i-1]

		// Ensure panic in a callback does not break executing other callbacks.
		func(fn func() error) {
			defer func() {
				if v := recover(); v != nil {
					e, ok := v.(error)
					if !ok {
						e = fmt.Errorf("%v", v)
					}
					err = multierror.Append(err, e)
				}
			}()

			if e := fn(); e != nil {
				err = multierror.Append(err, e)
			}
		}(fn)
	}

	return err
}
コード例 #4
0
ファイル: edison_adaptor.go プロジェクト: hybridgroup/gobot
// Connect initializes the Edison for use with the Arduino beakout board
func (e *Adaptor) Connect() (err error) {
	e.digitalPins = make(map[int]sysfs.DigitalPin)
	e.pwmPins = make(map[int]*pwmPin)

	switch e.Board() {
	case "sparkfun":
		e.pinmap = sparkfunPinMap
		if errs := e.sparkfunSetup(); errs != nil {
			err = multierror.Append(err, errs)
		}
	case "arduino":
		e.pinmap = arduinoPinMap
		if errs := e.arduinoSetup(); errs != nil {
			err = multierror.Append(err, errs)
		}
	case "miniboard":
		e.pinmap = miniboardPinMap
		if errs := e.miniboardSetup(); errs != nil {
			err = multierror.Append(err, errs)
		}
	default:
		errs := errors.New("Unknown board type: " + e.Board())
		err = multierror.Append(err, errs)
	}
	return
}
コード例 #5
0
ファイル: hcl_parser.go プロジェクト: kapalhq/envoy
func parseRawBool(key string, hcltree *hclObj.Object, errors *multierror.Error) bool {
	if rawValue := hcltree.Get(key, false); rawValue != nil {
		if rawValue.Type != hclObj.ValueTypeBool {
			errors = multierror.Append(errors, fmt.Errorf("Invalid type assigned to property: %s. Expected string type, Found %s", key, rawValue.Type))
		} else {
			return rawValue.Value.(bool)
		}
	} else {
		errors = multierror.Append(errors, fmt.Errorf("Property: %s not specified in the configuration", key))
	}
	return false
}
コード例 #6
0
ファイル: robot.go プロジェクト: hybridgroup/gobot
// Stop stops a Robot's connections and Devices
func (r *Robot) Stop() error {
	var result error
	log.Println("Stopping Robot", r.Name, "...")
	err := r.Devices().Halt()
	if err != nil {
		result = multierror.Append(result, err)
	}
	err = r.Connections().Finalize()
	if err != nil {
		result = multierror.Append(result, err)
	}

	r.done <- true
	return result
}
コード例 #7
0
ファイル: chip_adaptor.go プロジェクト: hybridgroup/gobot
// Finalize closes connection to board and pins
func (c *Adaptor) Finalize() (err error) {
	for _, pin := range c.digitalPins {
		if pin != nil {
			if e := pin.Unexport(); e != nil {
				err = multierror.Append(err, e)
			}
		}
	}
	if c.i2cDevice != nil {
		if e := c.i2cDevice.Close(); e != nil {
			err = multierror.Append(err, e)
		}
	}
	return
}
コード例 #8
0
ファイル: master_test.go プロジェクト: hybridgroup/gobot
func TestMasterFinalizeErrors(t *testing.T) {
	g := initTestMaster1Robot()
	e := errors.New("adaptor finalize error 2")

	testAdaptorFinalize = func() (err error) {
		return e
	}

	var expected error
	expected = multierror.Append(expected, e)
	expected = multierror.Append(expected, e)
	expected = multierror.Append(expected, e)

	gobottest.Assert(t, g.Start(), nil)
	gobottest.Assert(t, g.Stop(), expected)
}
コード例 #9
0
ファイル: parser.go プロジェクト: kapalhq/mozo
func parseMaxExecutions(jobNode *hclObj.Object, errors *multierror.Error) string {
	if rawCron := jobNode.Get("max_executions", false); rawCron != nil {
		if rawCron.Len() > 1 {
			errors = multierror.Append(errors, fmt.Errorf("max_executions was specified more than once"))
		} else {
			if rawCron.Type != hclObj.ValueTypeString {
				errors = multierror.Append(errors, fmt.Errorf("max_executions was specified as an invalid type - expected string, found %s", rawCron.Type))
			} else {
				return rawCron.Value.(string)
			}
		}
	} else {
		errors = multierror.Append(errors, fmt.Errorf("No max_executions was specified in the configuration"))
	}
	return ""
}
コード例 #10
0
ファイル: parser.go プロジェクト: kapalhq/mozo
func parseJob(jobNode *hclObj.Object, errors *multierror.Error) JobConfig {
	config := JobConfig{}

	if jobNode.Len() > 1 {
		errors = multierror.Append(errors, fmt.Errorf("job was specified more than once"))
	} else {
		if jobNode.Type != hclObj.ValueTypeObject {
			errors = multierror.Append(errors, fmt.Errorf("job was specified as an invalid type - expected object, found %s", jobNode.Type))
		} else {
			config.Name = jobNode.Key
			config.Trigger = parseJobTrigger(jobNode, errors)
			config.Exec = parseExec(jobNode, errors)
		}
	}
	return config
}
コード例 #11
0
ファイル: remote.go プロジェクト: purpleidea/mgmt
// Exit causes as much of the Remotes struct to shutdown as quickly and as
// cleanly as possible. It only returns once everything is shutdown.
func (obj *Remotes) Exit() error {
	obj.lock.Lock()
	obj.exiting = true // don't spawn new ones once this flag is set!
	obj.lock.Unlock()
	close(obj.exitChan)
	var reterr error
	for _, f := range obj.remotes {
		sshobj, exists := obj.sshmap[f]
		if !exists || sshobj == nil {
			continue
		}

		// TODO: should we run these as go routines?
		if err := sshobj.Stop(); err != nil {
			err = errwrap.Wrapf(err, "Remote: Error stopping!")
			reterr = multierr.Append(reterr, err) // list of errors
		}
	}

	if obj.callbackCancelFunc != nil {
		obj.callbackCancelFunc() // cancel our callback
	}

	defer obj.cuid.Unregister()
	obj.wg.Wait() // wait for everyone to exit
	return reterr
}
コード例 #12
0
ファイル: auth_flags.go プロジェクト: alphagov/paas-cf
func (auth *GitHubAuthFlag) Validate() error {
	var errs *multierror.Error
	if auth.ClientID == "" || auth.ClientSecret == "" {
		errs = multierror.Append(
			errs,
			errors.New("must specify --github-auth-client-id and --github-auth-client-secret to use GitHub OAuth."),
		)
	}
	if len(auth.Organizations) == 0 && len(auth.Teams) == 0 && len(auth.Users) == 0 {
		errs = multierror.Append(
			errs,
			errors.New("at least one of the following is required for github-auth: organizations, teams, users."),
		)
	}
	return errs.ErrorOrNil()
}
コード例 #13
0
ファイル: discovery.go プロジェクト: saper/jetpack
func OpenPubKey(location string) (types.ACIdentifier, *os.File, error) {
	if app := tryAppFromString(location); app != nil {
		// Proper ACIdentifier given, let's do the discovery
		// TODO: hostHeaders, insecure
		if pks, _, err := discovery.DiscoverPublicKeys(*app, nil, 0); err != nil {
			return app.Name, nil, err
		} else {
			// We assume multiple returned keys are alternatives, not
			// multiple different valid keychains.
			var err error
			for _, keyurl := range pks {
				if keyf, er1 := OpenLocation(keyurl); er1 != nil {
					err = multierror.Append(err, er1)
				} else {
					return app.Name, keyf, nil
				}
			}
			// All keys erred
			return app.Name, nil, err
		}
	} else {
		// Not an ACIdentifier, let's open as raw location
		f, err := OpenLocation(location)
		return "", f, err
	}
}
コード例 #14
0
ファイル: parser.go プロジェクト: kapalhq/mozo
func parseVersion(hcltree *hclObj.Object, errors *multierror.Error) string {
	if rawVersion := hcltree.Get("version", false); rawVersion != nil {
		if rawVersion.Len() > 1 {
			errors = multierror.Append(errors, fmt.Errorf("Version was specified more than once"))
		} else {
			if rawVersion.Type != hclObj.ValueTypeString {
				errors = multierror.Append(errors, fmt.Errorf("Version was specified as an invalid type - expected string, found %s", rawVersion.Type))
			} else {
				return rawVersion.Value.(string)
			}
		}
	} else {
		errors = multierror.Append(errors, fmt.Errorf("No version was specified in the configuration"))
	}
	return "*** Error"
}
コード例 #15
0
func deleteSecurityGroupRules(d *schema.ResourceData, meta interface{}, rules *schema.Set, ors *schema.Set) error {
	var errs *multierror.Error

	var wg sync.WaitGroup
	wg.Add(ors.Len())

	sem := make(chan struct{}, d.Get("parallelism").(int))
	for _, rule := range ors.List() {
		// Put a sleep here to avoid DoS'ing the API
		time.Sleep(500 * time.Millisecond)

		go func(rule map[string]interface{}) {
			defer wg.Done()
			sem <- struct{}{}

			// Create a single rule
			err := deleteSecurityGroupRule(d, meta, rule)
			if err != nil {
				errs = multierror.Append(errs, err)
			}

			// If we have at least one UUID, we need to save the rule
			if len(rule["uuids"].(map[string]interface{})) > 0 {
				rules.Add(rule)
			}

			<-sem
		}(rule.(map[string]interface{}))
	}

	wg.Wait()

	return errs.ErrorOrNil()
}
コード例 #16
0
func TestMqttAdaptorConnect(t *testing.T) {
	a := initTestMqttAdaptor()
	var expected error
	expected = multierror.Append(expected, errors.New("Network Error : Unknown protocol"))

	gobottest.Assert(t, a.Connect(), expected)
}
コード例 #17
0
ファイル: auth_flags.go プロジェクト: alphagov/paas-cf
func (auth *BasicAuthFlag) Validate() error {
	var errs *multierror.Error
	if auth.Username == "" {
		errs = multierror.Append(
			errs,
			errors.New("must specify --basic-auth-username to use basic auth."),
		)
	}
	if auth.Password == "" {
		errs = multierror.Append(
			errs,
			errors.New("must specify --basic-auth-password to use basic auth."),
		)
	}
	return errs.ErrorOrNil()
}
コード例 #18
0
ファイル: connection.go プロジェクト: hybridgroup/gobot
// Finalize calls Finalize on each Connection in c
func (c *Connections) Finalize() (err error) {
	for _, connection := range *c {
		if cerr := connection.Finalize(); cerr != nil {
			err = multierror.Append(err, cerr)
		}
	}
	return err
}
コード例 #19
0
ファイル: device.go プロジェクト: hybridgroup/gobot
// Halt calls Halt on each Device in d
func (d *Devices) Halt() (err error) {
	for _, device := range *d {
		if derr := device.Halt(); derr != nil {
			err = multierror.Append(err, derr)
		}
	}
	return err
}
コード例 #20
0
ファイル: mqtt_adaptor.go プロジェクト: hybridgroup/gobot
// Connect returns true if connection to mqtt is established
func (a *Adaptor) Connect() (err error) {
	a.client = paho.NewClient(createClientOptions(a.clientID, a.Host, a.username, a.password))
	if token := a.client.Connect(); token.Wait() && token.Error() != nil {
		err = multierror.Append(err, token.Error())
	}

	return
}
コード例 #21
0
ファイル: master_test.go プロジェクト: hybridgroup/gobot
func TestMasterStartDriverErrors(t *testing.T) {
	g := initTestMaster1Robot()
	e := errors.New("driver start error 1")
	testDriverStart = func() (err error) {
		return e
	}

	var expected error
	expected = multierror.Append(expected, e)
	expected = multierror.Append(expected, e)
	expected = multierror.Append(expected, e)

	gobottest.Assert(t, g.Start(), expected)
	gobottest.Assert(t, g.Stop(), nil)

	testDriverStart = func() (err error) { return }
}
コード例 #22
0
ファイル: validate.go プロジェクト: sevein/qubot
// Validate the confifugration file
func Validate(c *qubot.Config) error {
	var result error

	if c.Database == nil {
		result = multierror.Append(result, fmt.Errorf("'database' configuration section is missing"))
	}
	if c.Slack == nil {
		result = multierror.Append(result, fmt.Errorf("'slack' configuration section is missing"))
	}
	if c.Redmine == nil {
		result = multierror.Append(result, fmt.Errorf("'redmine' configuration section is missing"))
	}

	if c.Slack != nil {
		if c.Slack.Nickname == "" {
			result = multierror.Append(result, fmt.Errorf("slack: nickname is required"))
		}
		if c.Slack.Key == "" {
			result = multierror.Append(result, fmt.Errorf("slack: key is required"))
		}
	}

	if c.Redmine != nil {
		if c.Redmine.URL == "" {
			result = multierror.Append(result, fmt.Errorf("redmine: url is required"))
		}
		if c.Redmine.Key == "" {
			result = multierror.Append(result, fmt.Errorf("redmine: key is required"))
		}
	}

	return result
}
コード例 #23
0
ファイル: robot.go プロジェクト: hybridgroup/gobot
// Stop calls the Stop method of each Robot in the collection
func (r *Robots) Stop() (err error) {
	for _, robot := range *r {
		if rerr := robot.Stop(); rerr != nil {
			err = multierror.Append(err, rerr)
			return
		}
	}
	return
}
コード例 #24
0
func keyringErrorsOrNil(responses []*structs.KeyringResponse) error {
	var errs error
	for _, response := range responses {
		if response.Error != "" {
			errs = multierror.Append(errs, fmt.Errorf(response.Error))
		}
	}
	return errs
}
コード例 #25
0
ファイル: hcl_parser.go プロジェクト: kapalhq/envoy
func parseRawObject(key string, hcltree *hclObj.Object, errors *multierror.Error) (apisOut []*hclObj.Object) {
	if apis := hcltree.Get(key, false); apis != nil {
		for _, api := range apis.Elem(true) {
			apisOut = append(apisOut, api)
		}
	} else {
		errors = multierror.Append(errors, fmt.Errorf("No job_store was specified in the configuration"))
	}
	return apisOut
}
コード例 #26
0
ファイル: vault.go プロジェクト: zanella/nomad
// validateRole contacts Vault and checks that the given Vault role is valid for
// the purposes of being used by Nomad
func (v *vaultClient) validateRole(role string) error {
	if role == "" {
		return fmt.Errorf("Invalid empty role name")
	}

	// Validate the role
	rsecret, err := v.client.Logical().Read(fmt.Sprintf("auth/token/roles/%s", role))
	if err != nil {
		return fmt.Errorf("failed to lookup role %q: %v", role, err)
	}

	// Read and parse the fields
	var data struct {
		ExplicitMaxTtl int `mapstructure:"explicit_max_ttl"`
		Orphan         bool
		Period         int
		Renewable      bool
	}
	if err := mapstructure.WeakDecode(rsecret.Data, &data); err != nil {
		return fmt.Errorf("failed to parse Vault role's data block: %v", err)
	}

	// Validate the role is acceptable
	var mErr multierror.Error
	if data.Orphan {
		multierror.Append(&mErr, fmt.Errorf("Role must not allow orphans"))
	}

	if !data.Renewable {
		multierror.Append(&mErr, fmt.Errorf("Role must allow tokens to be renewed"))
	}

	if data.ExplicitMaxTtl != 0 {
		multierror.Append(&mErr, fmt.Errorf("Role can not use an explicit max ttl. Token must be periodic."))
	}

	if data.Period == 0 {
		multierror.Append(&mErr, fmt.Errorf("Role must have a non-zero period to make tokens periodic."))
	}

	return mErr.ErrorOrNil()
}
コード例 #27
0
ファイル: discovery.go プロジェクト: saper/jetpack
func discoverACI(app discovery.App, asc *os.File) (*os.File, *os.File, error) {
	var aci *os.File
	// TODO: hostHeaders, insecure
	if eps, _, err := discovery.DiscoverACIEndpoints(app, nil, 0); err != nil {
		return nil, nil, err
	} else {
		var err error

		if asc == nil {
			err = nil
			for _, ep := range eps {
				if af, er1 := OpenLocation(ep.ASC); er1 != nil {
					err = multierror.Append(err, er1)
				} else {
					asc = af
					break
				}
			}
			if err != nil {
				return nil, nil, err
			}
		}

		err = nil
		for _, ep := range eps {
			if af, er1 := OpenLocation(ep.ACI); er1 != nil {
				err = multierror.Append(err, er1)
			} else {
				aci = af
				break
			}
			if aci == nil {
				if asc != nil {
					asc.Close()
				}
				return nil, nil, err
			}
		}

		return aci, asc, nil
	}
}
コード例 #28
0
ファイル: parser.go プロジェクト: kapalhq/mozo
func parseJobStore(hcltree *hclObj.Object, errors *multierror.Error) []string {
	hosts := make([]string, 0)
	if jobStore := hcltree.Get("job_store", false); jobStore != nil {
		if jobStore.Len() > 1 {
			errors = multierror.Append(errors, fmt.Errorf("job_store was specified more than once"))
		} else {
			if jobStore.Type != hclObj.ValueTypeList {
				errors = multierror.Append(errors, fmt.Errorf("job_store was specified as an invalid type - expected string, found %s", jobStore.Type))
			} else {
				for _, host := range jobStore.Elem(true) {
					hosts = append(hosts, host.Value.(string))
				}
				return hosts
			}
		}
	} else {
		errors = multierror.Append(errors, fmt.Errorf("No job_store was specified in the configuration"))
	}
	return []string{}
}
コード例 #29
0
ファイル: raspi_adaptor.go プロジェクト: hybridgroup/gobot
// Finalize closes connection to board and pins
func (r *Adaptor) Finalize() (err error) {
	for _, pin := range r.digitalPins {
		if pin != nil {
			if perr := pin.Unexport(); err != nil {
				err = multierror.Append(err, perr)
			}
		}
	}
	for _, pin := range r.pwmPins {
		if perr := r.piBlaster(fmt.Sprintf("release %v\n", pin)); err != nil {
			err = multierror.Append(err, perr)
		}
	}
	if r.i2cDevice != nil {
		if perr := r.i2cDevice.Close(); err != nil {
			err = multierror.Append(err, perr)
		}
	}
	return
}
コード例 #30
0
ファイル: parser.go プロジェクト: kapalhq/mozo
func parseJobs(hcltree *hclObj.Object, errors *multierror.Error) []JobConfig {
	outputConfig := make([]JobConfig, 0)
	if rawJobs := hcltree.Get("job", false); rawJobs != nil {
		if rawJobs.Type != hclObj.ValueTypeObject {
			errors = multierror.Append(errors, fmt.Errorf("job was specified as an invalid type - expected list, found %s", rawJobs.Type))
		} else {
			arrayJobs := rawJobs.Elem(true)
			for _, job := range arrayJobs {
				outputConfig = append(outputConfig, parseJob(job, errors))
			}
		}

	} else {
		if len(outputConfig) == 0 {
			errors = multierror.Append(errors, fmt.Errorf("No job_store was specified in the configuration"))
		}
	}
	return outputConfig

}