registry

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: MPL-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsModuleNotFound

func IsModuleNotFound(err error) bool

IsModuleNotFound returns true only if the given error is a "module not found" error. This allows callers to recognize this particular error condition as distinct from operational errors such as poor network connectivity.

func IsServiceNotProvided

func IsServiceNotProvided(err error) bool

IsServiceNotProvided returns true only if the given error is a "service not provided" error. This allows callers to recognize this particular error condition as distinct from operational errors such as poor network connectivity.

func IsServiceUnreachable

func IsServiceUnreachable(err error) bool

IsServiceUnreachable returns true if the registry/discovery service was unreachable

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client provides methods to query OpenTofu module registries.

This client implements the "modules.v1" protocol. It does not implement any other OpenTofu registry protocols, and in particular the client for provider registry clients lives elsewhere.

(The overly-general name of this package is a historical accident, and perhaps one day this package should move to "getmodules/registry" instead of just "registry" to make the scope a little clearer.)

func NewClient

func NewClient(ctx context.Context, services *disco.Disco, client *retryablehttp.Client) *Client

NewClient returns a new initialized registry client.

func (*Client) InstallModulePackage

func (c *Client) InstallModulePackage(ctx context.Context, location PackageLocationDirect, targetDir string) (string, error)

InstallModulePackage attempts to install a module package from the given location into the given target directory.

This method is used only for "direct" package locations, where the registry is directly hosting packages in locations under its own control, and possibly authenticated using the registry's own credentials. If you have a PackageLocationIndirect instead then you must handle it separately using the "remote source address" installation process.

If successful this returns the final path of the requested module, taking into account any subdirectory selection that was included in the original module request. If the original source address did not include a subdirectory portion then the result is just a normalized version of targetDir.

func (*Client) ModulePackageLocation

func (c *Client) ModulePackageLocation(ctx context.Context, packageAddr regaddr.ModulePackage, version string, subdir string) (PackageLocation, error)

ModulePackageLocation finds the package location for a specific module package version.

The subdir parameter is the subdirectory path from the original module source address (e.g., from addrs.ModuleSourceRegistry.Subdir). This is passed separately because regaddr.ModulePackage represents only the package itself, not the full module source address which may include a subdirectory selector. The subdir is needed to properly construct the PackageLocation result.

This returns one of the concrete implementations of the closed interface PackageLocation, depending on what type of location the registry chooses to report. Refer to the documentation of those types for information on how each variant should be used to actually install the package.

func (*Client) ModulePackageVersions

func (c *Client) ModulePackageVersions(ctx context.Context, packageAddr regaddr.ModulePackage) (*response.ModuleVersions, error)

ModulePackageVersions queries the registry for a module package, and returns the available versions.

type PackageLocation

type PackageLocation interface {
	// UILabel returns a label that can be used to concisely refer to this
	// location in the OpenTofu UI, such as when reporting progress or
	// describing problems in error messages.
	//
	// The result is not necessarily a unique identifier for the location. It's
	// just expected to be something a human reader could use to confirm whether
	// OpenTofu is installing from somewhere reasonable and expected.
	UILabel() string

	// Subdir returns a path to a directory within the package that contains
	// the module that is being selected. Returns an empty string if the root
	// of the package contains the selected module.
	Subdir() string
	// contains filtered or unexported methods
}

PackageLocation abstractly represents a location that a module package should be installed from.

There are exactly two concrete implementations of this interface: PackageLocationDirect for packages that are hosted as part of the registry they were reported from, and PackageLocationIndirect (for registry packages that are really just aliases for source addresses that someone could've specified directly in their configuration).

This is a closed interface. If any new implementations of it are added in future then an exhaustive type-switch over these in the module installer will need to be updated to support the new variants.

type PackageLocationDirect

type PackageLocationDirect struct {
	// contains filtered or unexported fields
}

PackageLocationDirect represents a module package location that's considered to be a part of the registry that reported it, and so the same registry client that reported this location should also be used to install it.

This type is intentionally opaque, since values of this type should be passed directly to [Client.InstallPackage] on the same Client instance that returned this value. It encapsulates everything that client would need to perform the installation.

func (PackageLocationDirect) Subdir

func (p PackageLocationDirect) Subdir() string

Subdir implements PackageLocation.

func (PackageLocationDirect) UILabel

func (p PackageLocationDirect) UILabel() string

UILabel implements PackageLocation.

type PackageLocationIndirect

type PackageLocationIndirect struct {
	// SourceAddr is the remote source address to install from, which should
	// be treated in an equivalent way to how this address would've been treated
	// if specified directly in a module call's "source" argument.
	SourceAddr addrs.ModuleSourceRemote
}

PackageLocationIndirect represents a module package that is accessible through a "remote" module source address just like what could be written directly in a "source" argument in a module call, and so must be installed through the normal remote package fetcher instead of through the registry client.

For locations of this type, the registry client that produced it is no longer involved after the location has been decided.

func (PackageLocationIndirect) Subdir

func (p PackageLocationIndirect) Subdir() string

Subdir implements PackageLocation.

func (PackageLocationIndirect) UILabel

func (p PackageLocationIndirect) UILabel() string

UILabel implements PackageLocation.

type ServiceUnreachableError

type ServiceUnreachableError struct {
	// contains filtered or unexported fields
}

ServiceUnreachableError Registry service is unreachable

func (*ServiceUnreachableError) Error

func (e *ServiceUnreachableError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL