github.com/docker/app@v0.9.1-beta3.0.20210611140623-a48f773ab002/types/metadata/metadata.go (about)

     1  package metadata
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/deislabs/cnab-go/bundle"
     7  )
     8  
     9  // Maintainer represents one of the apps's maintainers
    10  type Maintainer struct {
    11  	Name  string
    12  	Email string `json:",omitempty"`
    13  }
    14  
    15  // Maintainers is a list of maintainers
    16  type Maintainers []Maintainer
    17  
    18  // String gives a string representation of a list of maintainers
    19  func (ms Maintainers) String() string {
    20  	res := make([]string, len(ms))
    21  	for i, m := range ms {
    22  		res[i] = m.String()
    23  	}
    24  	return strings.Join(res, ", ")
    25  }
    26  
    27  // String gives a string representation of a maintainer
    28  func (m Maintainer) String() string {
    29  	s := m.Name
    30  	if m.Email != "" {
    31  		s += " <" + m.Email + ">"
    32  	}
    33  	return s
    34  }
    35  
    36  // AppMetadata is the format of the data found inside the metadata.yml file
    37  type AppMetadata struct {
    38  	Version     string
    39  	Name        string
    40  	Description string      `json:",omitempty"`
    41  	Maintainers Maintainers `json:",omitempty"`
    42  }
    43  
    44  // FromBundle extracts the docker-app metadata from the bundle
    45  func FromBundle(bndl *bundle.Bundle) AppMetadata {
    46  	meta := AppMetadata{
    47  		Name:        bndl.Name,
    48  		Version:     bndl.Version,
    49  		Description: bndl.Description,
    50  	}
    51  	for _, m := range bndl.Maintainers {
    52  		meta.Maintainers = append(meta.Maintainers, Maintainer{
    53  			Name:  m.Name,
    54  			Email: m.Email,
    55  		})
    56  	}
    57  	return meta
    58  }