Ejemplo n.º 1
0
func resourceFirewallRuleExists(d *schema.ResourceData, meta interface{}) (bool, error) {
	client := meta.(*cloudapi.Client)

	rule, err := client.GetFirewallRule(d.Id())
	if errors.IsResourceNotFound(err) {
		return false, nil
	}

	return rule != nil && err == nil, err
}
Ejemplo n.º 2
0
// DeleteContainer deletes the named container from the storage account.
func (s *JoyentStorage) DeleteContainer(containerName string) error {
	err := s.manta.DeleteDirectory(containerName)
	if err == nil && strings.EqualFold(s.containerName, containerName) {
		s.madeContainer = false
	}
	if je.IsResourceNotFound(err) {
		return errors.NewNotFound(err, fmt.Sprintf("cannot delete %s, not found", containerName))
	}
	return err
}
Ejemplo n.º 3
0
func (s *JoyentStorage) Remove(name string) error {
	err := s.manta.DeleteObject(s.containerName, name)
	if err != nil {
		if je.IsResourceNotFound(err) {
			// gojoyent returns an error if file doesn't exist
			// just log a warning
			logger.Warningf("cannot delete %s from %s, already deleted", name, s.containerName)
		} else {
			return err
		}
	}

	if strings.Contains(name, "/") {
		var parents []string
		dirs := strings.Split(name, "/")
		for i := (len(dirs) - 1); i >= 0; i-- {
			if i < (len(dirs) - 1) {
				parents = append(parents, strings.Join(dirs[:(i+1)], "/"))
			}
		}

		for _, dir := range parents {
			err := s.manta.DeleteDirectory(path.Join(s.containerName, dir))
			if err != nil {
				if je.IsBadRequest(err) {
					// check if delete request returned a bad request error, i.e. directory is not empty
					// just log a warning
					logger.Warningf("cannot delete %s, not empty", dir)
				} else if je.IsResourceNotFound(err) {
					// check if delete request returned a resource not found error, i.e. directory was already deleted
					// just log a warning
					logger.Warningf("cannot delete %s, already deleted", dir)
				} else {
					return fmt.Errorf("cannot delete parent directory %q in control container %q: %v", dir, s.containerName, err)
				}
			}
		}
	}

	return nil
}
Ejemplo n.º 4
0
func (c *MantaClient) Get() (*Payload, error) {
	bytes, err := c.Client.GetObject(c.Path, c.ObjectName)
	if err != nil {
		if joyenterrors.IsResourceNotFound(err.(joyenterrors.Error).Cause()) {
			return nil, nil
		}

		return nil, err
	}

	md5 := md5.Sum(bytes)

	return &Payload{
		Data: bytes,
		MD5:  md5[:],
	}, nil
}
Ejemplo n.º 5
0
func (s *ErrorsSuite) TestCreateResourceNotFoundError(c *gc.C) {
	context := "context"
	err := errors.NewResourceNotFoundf(nil, context, "It was resource not found: %s", context)
	c.Assert(errors.IsResourceNotFound(err), gc.Equals, true)
	c.Assert(err.Error(), gc.Equals, "It was resource not found: context")
}
Ejemplo n.º 6
0
func (s *ErrorsSuite) TestCreateSimpleResourceNotFoundError(c *gc.C) {
	context := "context"
	err := errors.NewResourceNotFoundf(nil, context, "")
	c.Assert(errors.IsResourceNotFound(err), gc.Equals, true)
	c.Assert(err.Error(), gc.Equals, "Resource Not Found: context")
}