Example #1
0
func (s *MetadataService) Metadata(c request.Client) (metadata.Interface, error) {
	/*
	 *if _, ok := s.SupportedVersions[v]; ok != true {
	 *    return nil, fmt.Errorf("metadata: version %v for %v is not supported", v, s.Name)
	 *}
	 */

	var m *Metadata

	responce, err := request.Get(instanceMetadataURL.WithVersion("v1"), request.Header("Metadata-Flavor", "Google"))
	if err != nil {
		return nil, err
	}

	err = response.JSON(&m.Instance)
	if err != nil {
		return nil, err
	}

	pu := projectMetadataURL.WithVersion(v)
	responce, err := request.Get(projectMetadataURL.WithVersion("v1"), request.Header("Metadata-Flavor", "Google"))
	if err != nil {
		return nil, err
	}

	err = response.JSON(&m.Project)
	if err != nil {
		return nil, err
	}

	return m, nil
}
Example #2
0
func (s *MetadataService) fetchMetadata() (*Metadata, error) {
	// currently only supported metadata version is "v1"
	version := "v1"
	/*
	 *if _, ok := s.supportedversions[v]; ok != true {
	 *    return nil, fmt.errorf("metadata: version %v for %v is not supported", v, s.name)
	 *}
	 */

	var m Metadata

	instanceurl := s.URL.Fill(version, "instance")
	response, err := request.Get(instanceurl, request.Header("Metadata-Flavor", "Google"))
	if err != nil {
		return nil, err
	}

	err = response.JSON(&m.Instance)
	if err != nil {
		return nil, err
	}

	projecturl := s.URL.Fill(version, "project")
	response, err = request.Get(projecturl, request.Header("Metadata-Flavor", "Google"))
	if err != nil {
		return nil, err
	}

	err = response.JSON(&m.Project)
	return &m, err
}