mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
Moving monocular client to internal and adding user agent to version pkg
Signed-off-by: Matt Farina <matt@mattfarina.com>
This commit is contained in:
parent
2613c3cda3
commit
2d4ced9090
6 changed files with 21 additions and 25 deletions
|
|
@ -19,9 +19,6 @@ package monocular
|
|||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"helm.sh/helm/internal/version"
|
||||
)
|
||||
|
||||
// ErrHostnameNotProvided indicates the url is missing a hostname
|
||||
|
|
@ -29,8 +26,6 @@ var ErrHostnameNotProvided = errors.New("no hostname provided")
|
|||
|
||||
// Client represents a client capable of communicating with the Monocular API.
|
||||
type Client struct {
|
||||
// The user agent to identify as when making requests
|
||||
UserAgent string
|
||||
|
||||
// The base URL for requests
|
||||
BaseURL string
|
||||
|
|
@ -48,9 +43,8 @@ func New(u string) (*Client, error) {
|
|||
}
|
||||
|
||||
return &Client{
|
||||
UserAgent: "Helm/" + strings.TrimPrefix(version.GetVersion(), "v"),
|
||||
BaseURL: u,
|
||||
Log: nopLogger,
|
||||
BaseURL: u,
|
||||
Log: nopLogger,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
@ -17,10 +17,7 @@ limitations under the License.
|
|||
package monocular
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"helm.sh/helm/internal/version"
|
||||
)
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
|
|
@ -31,9 +28,4 @@ func TestNew(t *testing.T) {
|
|||
if c.BaseURL != "https://hub.helm.sh" {
|
||||
t.Errorf("incorrect BaseURL. Expected \"https://hub.helm.sh\" but got %q", c.BaseURL)
|
||||
}
|
||||
|
||||
ua := "Helm/" + strings.TrimPrefix(version.GetVersion(), "v")
|
||||
if c.UserAgent != ua {
|
||||
t.Errorf("incorrect user agent. Expected %q but got %q", ua, c.UserAgent)
|
||||
}
|
||||
}
|
||||
|
|
@ -24,23 +24,27 @@ import (
|
|||
"path"
|
||||
"time"
|
||||
|
||||
"helm.sh/helm/internal/version"
|
||||
"helm.sh/helm/pkg/chart"
|
||||
)
|
||||
|
||||
// The structs below represent the structure of the response from the monocular
|
||||
// search API.
|
||||
// search API. The structs were not imported from monocular because monocular
|
||||
// imports from Helm v2 (avoiding circular version dependency) and the mappings
|
||||
// are slightly different (monocular search results do not directly reflect
|
||||
// the struct definitions).
|
||||
|
||||
// SearchResult represents an individual chart result
|
||||
type SearchResult struct {
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Attributes Attributes `json:"attributes"`
|
||||
Attributes Chart `json:"attributes"`
|
||||
Links Links `json:"links"`
|
||||
Relationships Relationships `json:"relationships"`
|
||||
}
|
||||
|
||||
// Attributes is the attributes for the chart
|
||||
type Attributes struct {
|
||||
// Chart is the attributes for the chart
|
||||
type Chart struct {
|
||||
Name string `json:"name"`
|
||||
Repo Repo `json:"repo"`
|
||||
Description string `json:"description"`
|
||||
|
|
@ -69,12 +73,12 @@ type Relationships struct {
|
|||
|
||||
// LatestChartVersion provides the details on the latest version of the chart
|
||||
type LatestChartVersion struct {
|
||||
Data Data `json:"data"`
|
||||
Links Links `json:"links"`
|
||||
Data ChartVersion `json:"data"`
|
||||
Links Links `json:"links"`
|
||||
}
|
||||
|
||||
// Data provides the specific data on the chart version
|
||||
type Data struct {
|
||||
// ChartVersion provides the specific data on the chart version
|
||||
type ChartVersion struct {
|
||||
Version string `json:"version"`
|
||||
AppVersion string `json:"app_version"`
|
||||
Created time.Time `json:"created"`
|
||||
|
|
@ -108,7 +112,7 @@ func (c *Client) Search(term string) ([]SearchResult, error) {
|
|||
|
||||
// Set the user agent so that monocular can identify where the request
|
||||
// is coming from
|
||||
req.Header.Set("User-Agent", c.UserAgent)
|
||||
req.Header.Set("User-Agent", version.GetUserAgent())
|
||||
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
|
|
@ -19,6 +19,7 @@ package version // import "helm.sh/helm/internal/version"
|
|||
import (
|
||||
"flag"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -59,6 +60,11 @@ func GetVersion() string {
|
|||
return version + "+" + metadata
|
||||
}
|
||||
|
||||
// GetUserAgent returns a user agent for user with an HTTP client
|
||||
func GetUserAgent() string {
|
||||
return "Helm/" + strings.TrimPrefix(GetVersion(), "v")
|
||||
}
|
||||
|
||||
// Get returns build info
|
||||
func Get() BuildInfo {
|
||||
v := BuildInfo{
|
||||
|
|
|
|||
Loading…
Reference in a new issue