github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/plugin/plugin_repository.go (about)

     1  package plugin
     2  
     3  import (
     4  	"net/url"
     5  	"path"
     6  	"strings"
     7  )
     8  
     9  // PluginRepository represents a plugin repository
    10  type PluginRepository struct {
    11  	Plugins []Plugin `json:"plugins"`
    12  }
    13  
    14  type PluginBinary struct {
    15  	Platform string `json:"platform"`
    16  	URL      string `json:"url"`
    17  	Checksum string `json:"checksum"`
    18  }
    19  
    20  type Plugin struct {
    21  	Name        string         `json:"name"`
    22  	Description string         `json:"description"`
    23  	Version     string         `json:"version"`
    24  	Binaries    []PluginBinary `json:"binaries"`
    25  }
    26  
    27  func (client *Client) GetPluginRepository(repositoryURL string) (PluginRepository, error) {
    28  	parsedURL, err := url.Parse(repositoryURL)
    29  	if err != nil {
    30  		return PluginRepository{}, err
    31  	}
    32  
    33  	parsedURL.Path = strings.TrimSuffix(parsedURL.Path, "/")
    34  	if !strings.HasSuffix(parsedURL.Path, "/list") {
    35  		parsedURL.Path = path.Join(parsedURL.Path, "list")
    36  	}
    37  
    38  	request, err := client.newGETRequest(parsedURL.String())
    39  	if err != nil {
    40  		return PluginRepository{}, err
    41  	}
    42  
    43  	var pluginRepository PluginRepository
    44  	response := Response{
    45  		Result: &pluginRepository,
    46  	}
    47  	err = client.connection.Make(request, &response, nil)
    48  	if err != nil {
    49  		return PluginRepository{}, err
    50  	}
    51  
    52  	return pluginRepository, nil
    53  }