No description
Find a file
Diógenes Fernandes b7639d7158
refactor: add more logging to git commands and CODEOWNERS (#51)
* refactor: add more logging to git commands

Signed-off-by: Diógenes Fernandes <diofeher@gmail.com>

* add CODEOWNERS

Signed-off-by: Diógenes Fernandes <diofeher@gmail.com>

* log in an easier way

Signed-off-by: Diógenes Fernandes <diofeher@gmail.com>

* fix tests

Signed-off-by: Diógenes Fernandes <diofeher@gmail.com>

---------

Signed-off-by: Diógenes Fernandes <diofeher@gmail.com>
2025-03-03 08:33:15 -05:00
.github/workflows Adding GH token for tests 2024-07-30 16:13:22 +02:00
cmd Merge pull request #37 from opentofu/segmented-module-dump 2024-09-30 14:51:35 +02:00
internal Reduce code duplication 2024-12-11 15:31:34 +01:00
logger Log fixes 2024-07-26 14:37:06 +02:00
metadata Adding GetProviderReverseAliases API call 2024-09-02 16:05:09 +02:00
types Fixes opentofu/registry#410: Add provider warnings 2024-10-11 08:49:29 +02:00
vcs refactor: add more logging to git commands and CODEOWNERS (#51) 2025-03-03 08:33:15 -05:00
.gitignore Base structure 2024-07-18 15:07:39 +02:00
api.go License change (must be signed off on the PR by @cam72cam @Yantrio @RLRabinowitz @kislerdm @virtualroot @vknabel) 2024-07-24 15:37:56 +02:00
CODEOWNERS refactor: add more logging to git commands and CODEOWNERS (#51) 2025-03-03 08:33:15 -05:00
error.go License change (must be signed off on the PR by @cam72cam @Yantrio @RLRabinowitz @kislerdm @virtualroot @vknabel) 2024-07-24 15:37:56 +02:00
generate.go License change (must be signed off on the PR by @cam72cam @Yantrio @RLRabinowitz @kislerdm @virtualroot @vknabel) 2024-07-24 15:37:56 +02:00
go.mod go.mod fix 2024-12-11 14:10:47 +01:00
go.sum go.mod fix 2024-12-11 14:10:47 +01:00
LICENSE License change (must be signed off on the PR by @cam72cam @Yantrio @RLRabinowitz @kislerdm @virtualroot @vknabel) 2024-07-24 15:37:56 +02:00
module_add.go Module improvements 2024-07-25 18:46:06 +02:00
module_add_test.go Fixed tests 2024-07-30 13:15:55 +02:00
module_update.go Top-level API Fix 2024-07-30 14:18:54 +02:00
module_update_test.go Fixed tests 2024-07-30 13:15:55 +02:00
README.md VCS repository access 2024-07-25 16:12:43 +02:00

Go library for the OpenTofu registry

Warning

This library is experimental.

This Go library implements the OpenTofu registry and also provides a library to access the underlying data. You can install this library by running:

go get github.com/opentofu/libregistry

The metadata API

The metadata API is a low-level API that allows you to access the stored registry data structure in the registry repository. Use this API when you need to work with the registry data without needing online functions, such as refreshing a module or provider.

You can use the metadata API like this:

package main

import (
    "context"

    "github.com/opentofu/libregistry/metadata"
    "github.com/opentofu/libregistry/metadata/storage/filesystem"
)

func main() {
    metadataAPI, err := metadata.New(filesystem.New("path/to/registry/data"))
    if err != nil {
        panic(err)
    }
    modules, err := metadataAPI.ListModules(context.Background())
    if err != nil {
        panic(err)
    }

    // Do something with modules here.
}

The registry API

The libregistry package contains the top level registry API. It implements the functions that are triggered from GitHub Actions, such as adding a module, etc.

You can use the registry API like this:

package main

import (
	"context"
	"os"

	"github.com/opentofu/libregistry"
	"github.com/opentofu/libregistry/metadata"
	"github.com/opentofu/libregistry/metadata/storage/filesystem"
	"github.com/opentofu/libregistry/vcs/github"
)

func main() {
	// github.New has more options, check the github package for details.
	ghClient, err := github.New(github.WithToken(os.Getenv("GITHUB_TOKEN")))
	if err != nil {
		panic(err)
	}

	storage := filesystem.New("path/to/registry/data")

	metadataAPI, err := metadata.New(storage)
	if err != nil {
		panic(err)
	}

	registry, err := libregistry.New(
		ghClient,
		metadataAPI,
	)
	if err != nil {
		panic(err)
	}

	if err := registry.AddModule(context.TODO(), "terraform-aws-modules/terraform-aws-iam"); err != nil {
		panic(err)
	}
}

VCS implementations

This library supports pluggable VCS systems. We run on GitHub by default, but you may be interested in implementing a VCS backend for a different system. Check out the vcs package for the VCS interface. Note, that the implementation still assumes that you will have an organization/repository structure and many systems, such as the registry UI, still assume that the VCS system will be git.

Metadata storage

You may also be interested in storing the metadata somewhere else than the local filesystem. For this purpose, check out the metadata/storage package, which contains the interface for defining storages.