예제 #1
0
파일: stack.go 프로젝트: koding/koding
func (s *Stack) VerifyCredential(c *stack.Credential) error {
	cred := c.Credential.(*Cred)

	if err := cred.Valid(); err != nil {
		return err
	}

	computeService, err := cred.ComputeService()
	if err != nil {
		return &stack.Error{
			Err: err,
		}
	}

	// Try to get project info. If there is no error, project name and JSON key
	// are valid.
	_, err = compute.NewProjectsService(computeService).Get(cred.Project).Do()
	if err != nil {
		return &stack.Error{
			Err: err,
		}
	}

	return nil
}
예제 #2
0
func (d *Deployer) checkProjectID() error {
	// TODO(mpl): cache the computeService in Deployer, instead of recreating a new one everytime?
	s, err := compute.New(d.Client)
	if err != nil {
		return projectIDError{
			id:    d.Conf.Project,
			cause: err,
		}
	}
	project, err := compute.NewProjectsService(s).Get(d.Conf.Project).Do()
	if err != nil {
		return projectIDError{
			id:    d.Conf.Project,
			cause: err,
		}
	}
	if project.Name != d.Conf.Project {
		return projectIDError{
			id:    d.Conf.Project,
			cause: fmt.Errorf("project ID do not match: got %q, wanted %q", project.Name, d.Conf.Project),
		}
	}
	return nil
}