Documentation
¶
Overview ¶
Package datasource provides clients to fetch data from different APIs.
Index ¶
- Constants
- func MakeMavenAuth(globalSettings, userSettings MavenSettingsXML) map[string]*HTTPAuthentication
- func NewMavenDecoder(reader io.Reader) *xml.Decoder
- type CachedInsightsClient
- func (c *CachedInsightsClient) GetPackage(ctx context.Context, in *pb.GetPackageRequest, opts ...grpc.CallOption) (*pb.Package, error)
- func (c *CachedInsightsClient) GetRequirements(ctx context.Context, in *pb.GetRequirementsRequest, opts ...grpc.CallOption) (*pb.Requirements, error)
- func (c *CachedInsightsClient) GetVersion(ctx context.Context, in *pb.GetVersionRequest, opts ...grpc.CallOption) (*pb.Version, error)
- func (c *CachedInsightsClient) GobDecode(b []byte) error
- func (c *CachedInsightsClient) GobEncode() ([]byte, error)
- type HTTPAuthMethod
- type HTTPAuthentication
- type MavenRegistry
- type MavenRegistryAPIClient
- func (m *MavenRegistryAPIClient) AddRegistry(registry MavenRegistry) error
- func (m *MavenRegistryAPIClient) GetProject(ctx context.Context, groupID, artifactID, version string) (maven.Project, error)
- func (m *MavenRegistryAPIClient) GetRegistries() (registries []MavenRegistry)
- func (m *MavenRegistryAPIClient) GetVersions(ctx context.Context, groupID, artifactID string) ([]maven.String, error)
- func (m *MavenRegistryAPIClient) GobDecode(b []byte) error
- func (m *MavenRegistryAPIClient) GobEncode() ([]byte, error)
- func (m *MavenRegistryAPIClient) WithoutRegistries() *MavenRegistryAPIClient
- type MavenSettingsXML
- type MavenSettingsXMLServer
- type RequestCache
Constants ¶
const MavenCentral = "https://repo.maven.apache.org/maven2"
MavenCentral holds the URL of Maven Central Repository.
Variables ¶
This section is empty.
Functions ¶
func MakeMavenAuth ¶
func MakeMavenAuth(globalSettings, userSettings MavenSettingsXML) map[string]*HTTPAuthentication
MakeMavenAuth returns a map of Maven authentication information index by repository ID.
Types ¶
type CachedInsightsClient ¶
type CachedInsightsClient struct { pb.InsightsClient // contains filtered or unexported fields }
CachedInsightsClient is a wrapper for InsightsClient that caches requests.
func NewCachedInsightsClient ¶
func NewCachedInsightsClient(addr string, userAgent string) (*CachedInsightsClient, error)
NewCachedInsightsClient creates a CachedInsightsClient.
func (*CachedInsightsClient) GetPackage ¶
func (c *CachedInsightsClient) GetPackage(ctx context.Context, in *pb.GetPackageRequest, opts ...grpc.CallOption) (*pb.Package, error)
GetPackage returns metadata about a package by querying deps.dev API.
func (*CachedInsightsClient) GetRequirements ¶
func (c *CachedInsightsClient) GetRequirements(ctx context.Context, in *pb.GetRequirementsRequest, opts ...grpc.CallOption) (*pb.Requirements, error)
GetRequirements returns requirements of the given version by querying deps.dev API.
func (*CachedInsightsClient) GetVersion ¶
func (c *CachedInsightsClient) GetVersion(ctx context.Context, in *pb.GetVersionRequest, opts ...grpc.CallOption) (*pb.Version, error)
GetVersion returns metadata about a version by querying deps.dev API.
func (*CachedInsightsClient) GobDecode ¶
func (c *CachedInsightsClient) GobDecode(b []byte) error
GobDecode decodes bytes to cache.
func (*CachedInsightsClient) GobEncode ¶
func (c *CachedInsightsClient) GobEncode() ([]byte, error)
GobEncode encodes cache to bytes.
type HTTPAuthMethod ¶
type HTTPAuthMethod int
HTTPAuthMethod definesthe type of HTTP authentication method.
const ( AuthBasic HTTPAuthMethod = iota AuthBearer AuthDigest )
HTTP authentication method.
type HTTPAuthentication ¶
type HTTPAuthentication struct { SupportedMethods []HTTPAuthMethod // In order of preference, only one method will be attempted. // AlwaysAuth determines whether to always send auth headers. // If false, the server must respond with a WWW-Authenticate header which will be checked for supported methods. // Must be set to false to use Digest authentication. AlwaysAuth bool // Shared Username string // Basic & Digest, plain text. Password string // Basic & Digest, plain text. // Basic BasicAuth string // Base64-encoded username:password. Overrides Username & Password fields if set. // Bearer BearerToken string // Digest CnonceFunc func() string // Function used to generate cnonce string for Digest. OK to leave unassigned. Mostly for use in tests. // contains filtered or unexported fields }
HTTPAuthentication holds the information needed for general HTTP Authentication support. Requests made through this will automatically populate the relevant info in the Authorization headers. This is a general implementation and should be suitable for use with any ecosystem.
func (*HTTPAuthentication) Get ¶
func (auth *HTTPAuthentication) Get(ctx context.Context, httpClient *http.Client, url string) (*http.Response, error)
Get makes an http GET request with the given http.Client. The Authorization Header will automatically be populated according from the fields in the HTTPAuthentication.
type MavenRegistry ¶
type MavenRegistry struct { URL string Parsed *url.URL // Information from pom.xml ID string ReleasesEnabled bool SnapshotsEnabled bool }
MavenRegistry defines a Maven registry.
type MavenRegistryAPIClient ¶
type MavenRegistryAPIClient struct {
// contains filtered or unexported fields
}
MavenRegistryAPIClient defines a client to fetch metadata from a Maven registry.
func NewMavenRegistryAPIClient ¶
func NewMavenRegistryAPIClient(registry MavenRegistry) (*MavenRegistryAPIClient, error)
NewMavenRegistryAPIClient returns a new MavenRegistryAPIClient.
func (*MavenRegistryAPIClient) AddRegistry ¶
func (m *MavenRegistryAPIClient) AddRegistry(registry MavenRegistry) error
AddRegistry adds the given registry to the list of registries if it has not been added.
func (*MavenRegistryAPIClient) GetProject ¶
func (m *MavenRegistryAPIClient) GetProject(ctx context.Context, groupID, artifactID, version string) (maven.Project, error)
GetProject fetches a pom.xml specified by groupID, artifactID and version and parses it to maven.Project. Each registry in the list is tried until we find the project. For a snapshot version, version level metadata is used to find the extact version string. More about Maven Repository Metadata Model: https://maven.apache.org/ref/3.9.9/maven-repository-metadata/ More about Maven Metadata: https://maven.apache.org/repositories/metadata.html
func (*MavenRegistryAPIClient) GetRegistries ¶
func (m *MavenRegistryAPIClient) GetRegistries() (registries []MavenRegistry)
GetRegistries returns the registries added to this client.
func (*MavenRegistryAPIClient) GetVersions ¶
func (m *MavenRegistryAPIClient) GetVersions(ctx context.Context, groupID, artifactID string) ([]maven.String, error)
GetVersions returns the list of available versions of a Maven package specified by groupID and artifactID. Versions found in all registries are unioned, then sorted by semver.
func (*MavenRegistryAPIClient) GobDecode ¶
func (m *MavenRegistryAPIClient) GobDecode(b []byte) error
GobDecode encodes bytes to cache.
func (*MavenRegistryAPIClient) GobEncode ¶
func (m *MavenRegistryAPIClient) GobEncode() ([]byte, error)
GobEncode encodes cache to bytes.
func (*MavenRegistryAPIClient) WithoutRegistries ¶
func (m *MavenRegistryAPIClient) WithoutRegistries() *MavenRegistryAPIClient
WithoutRegistries makes MavenRegistryAPIClient including its cache but not registries.
type MavenSettingsXML ¶
type MavenSettingsXML struct {
Servers []MavenSettingsXMLServer `xml:"servers>server"`
}
MavenSettingsXML defines Maven settings.xml.
func ParseMavenSettings ¶
func ParseMavenSettings(path string) MavenSettingsXML
ParseMavenSettings parses Maven settings at the given path.
type MavenSettingsXMLServer ¶
type MavenSettingsXMLServer struct { ID string `xml:"id"` Username string `xml:"username"` Password string `xml:"password"` }
MavenSettingsXMLServer defines a Maven server in settings.xml.
type RequestCache ¶
type RequestCache[K comparable, V any] struct { // contains filtered or unexported fields }
RequestCache is a map to cache the results of expensive functions that are called concurrently.
func NewRequestCache ¶
func NewRequestCache[K comparable, V any]() *RequestCache[K, V]
NewRequestCache creates a new RequestCache.
func (*RequestCache[K, V]) Get ¶
func (rq *RequestCache[K, V]) Get(key K, fn func() (V, error)) (V, error)
Get gets the value from the cache map if it's cached, otherwise it will call fn to get the value and cache it. fn will only ever be called once for a key, even if there are multiple simultaneous calls to Get before the first call is finished.
func (*RequestCache[K, V]) GetMap ¶
func (rq *RequestCache[K, V]) GetMap() map[K]V
GetMap gets a shallow clone of the stored cache map.
func (*RequestCache[K, V]) SetMap ¶
func (rq *RequestCache[K, V]) SetMap(m map[K]V)
SetMap loads (a shallow clone of) the provided map into the cache map.