예제 #1
0
func marshalError(err error) string {
	switch err.(type) {
	case *accounts.NotFoundError:
		logger.Noticef("Request failed: %v.", err)
		return "404"
	default:
		logger.Noticef("Request failed: %v.", err)
		return "500"
	}
}
예제 #2
0
// AuthorizedKeys satisfies APIClient.
func (c *googleAPIClient) AuthorizedKeys(username string) ([]string, error) {
	logger.Infof("Fetching authorized keys for %v.", username)
	p, z, i, err := c.instanceInfo()
	if err != nil {
		return nil, err
	}
	view, err := c.service.Linux.GetAuthorizedKeysView(p, z, username, i).Do()
	switch e := err.(type) {
	case nil:
		if view.Resource == nil {
			logger.Noticef("User %v has no authorized keys.", username)
			return nil, nil
		}
		return view.Resource.Keys, nil
	case *googleapi.Error:
		if e.Code == 404 {
			logger.Noticef("User %v does not exist.", username)
			return nil, nil
		}
		return nil, err
	default:
		return nil, err
	}
}