package
0.0.0-20240830163701-3b66f187944b
Repository: https://github.com/yoanm/go-github-tf.git
Documentation: pkg.go.dev

# README

core

Package core provides core functionality for GitHub config to terraform file conversion

Constants

const (
    RepositoryTemplateType       = "repository"
    BranchTemplateType           = "branch"
    BranchProtectionTemplateType = "branch protection"

    TemplateMaxDepth = 10
    TemplateMaxCount = 10
)
const (
    DefaultBranchIdentifier = "default"
)

Variables

var (
    ErrRepositoryNameIsMandatory = errors.New("repository name is mandatory")

    ErrWorkspacePathDoesntExist              = errors.New("workspace path doesn't exist")
    ErrWorkspacePathIsExpectedToBeADirectory = errors.New("workspace path is expected to be a directory")

    ErrNoTemplateAvailable                 = errors.New("not found as none available")
    ErrNoRepositoryTemplateAvailable       = fmt.Errorf("%s template %w", RepositoryTemplateType, ErrNoTemplateAvailable)
    ErrNoBranchTemplateAvailable           = fmt.Errorf("%s template %w", BranchTemplateType, ErrNoTemplateAvailable)
    ErrNoBranchProtectionTemplateAvailable = fmt.Errorf(
        "%s template %w",
        BranchProtectionTemplateType,
        ErrNoTemplateAvailable,
    )

    ErrTemplateNotFound                 = errors.New("not found")
    ErrRepositoryTemplateNotFound       = fmt.Errorf("%s template %w", RepositoryTemplateType, ErrTemplateNotFound)
    ErrBranchTemplateNotFound           = fmt.Errorf("%s template %w", BranchTemplateType, ErrTemplateNotFound)
    ErrBranchProtectionTemplateNotFound = fmt.Errorf("%s template %w", BranchProtectionTemplateType, ErrTemplateNotFound)

    ErrMaxTemplateCount = errors.New("maximum template count reached")
    ErrMaxTemplateDepth = errors.New("maximum template depth reached")

    ErrDuringWriteTerraformFiles = errors.New("error while writing terraform files")
    ErrDuringFileGeneration      = errors.New("error while generating files")
    ErrDuringComputation         = errors.New("error during computation")

    ErrSchemaValidation        = errors.New("schema validation error")
    ErrEmptySchema             = errors.New("empty schema")
    ErrSchemaNotFound          = errors.New("schema not found")
    ErrSchemaIsNil             = errors.New("schema is nil")
    ErrDuringSchemaCompilation = errors.New("error during schema compilation")

    ErrFileError             = errors.New("file")
    ErrBranchError           = errors.New("branch")
    ErrDefaultBranchError    = errors.New("default branch")
    ErrBranchProtectionError = errors.New("branch protection")
)
var (
    //nolint:gochecknoglobals //Easier to manage it as exported variable
    YamlAnchorDirectory *string
    //nolint:gochecknoglobals //Easier to manage it as exported variable
    Schemas = &SchemaList{
        "map:///repo.json":                              {Content: &repositoryConfigSchema},
        "map:///repos.json":                             {Content: &repositoriesConfigSchema},
        "map:///branch-protection.json":                 {Content: &branchProtectionSchema},
        "map:///branch-protection-template.json":        {Content: &branchProtectionTemplateSchema},
        "map:///branch-branch-protection.json":          {Content: &branchBranchProtectionSchema},
        "map:///branch-branch-protection-template.json": {Content: &branchBranchProtectionTemplateSchema},
        "map:///branch-template.json":                   {Content: &branchTemplateSchema},
        "map:///branch.json":                            {Content: &branchSchema},
        "map:///default-branch.json":                    {Content: &defaultBranchSchema},
        "map:///repo-template.json":                     {Content: &repositoryTemplateSchema},
    }
)

Functions

func ApplyBranchProtectionsTemplate

func ApplyBranchProtectionsTemplate(config *GhRepoConfig, templates *TemplatesConfig) error

func ApplyBranchesTemplate

func ApplyBranchesTemplate(repoConfig *GhRepoConfig, templates *TemplatesConfig) error

func BranchError

func BranchError(branch string, err error) error

func BranchProtectionError

func BranchProtectionError(index int, err error) error

func ComputationError

func ComputationError(errList []error) error

func ConfigTrace

func ConfigTrace[T GhRepoConfig | Config](header string, c *T)

func DefaultBranchError

func DefaultBranchError(err error) error

func EmptySchemaError

func EmptySchemaError(url string) error

func FileError

func FileError(filepath string, err error) error

func FileGenerationError

func FileGenerationError(msgList []string) error

func GenerateHclRepoFiles

func GenerateHclRepoFiles(configList []*GhRepoConfig) (map[string]*hclwrite.File, error)

func JoinErrors

func JoinErrors(errList []error, separator string) error

func LoadTemplate

func LoadTemplate[T any]( tplName string, loaderFn func(s string) *T, finderFn func(c *T) *[]string, tplType string, path ...string, ) ([]*T, error)

func LoadTemplateList

func LoadTemplateList[T any]( tplNameList *[]string, loaderFn func(s string) *T, finderFn func(c *T) *[]string, tplType string, path ...string, ) ([]*T, error)

func MapBranchToBranchProtectionRes

func MapBranchToBranchProtectionRes( pattern *string, protection *BaseGhBranchProtectionConfig, valGen tfsig.ValueGenerator, repo *GhRepoConfig, repoTfId string, links ...MapperLink, ) *ghbranchprotect.Config

func MapDefaultBranchToBranchProtectionRes

func MapDefaultBranchToBranchProtectionRes( branchConfig *GhDefaultBranchConfig, valGen tfsig.ValueGenerator, repo *GhRepoConfig, repoTfId string, links ...MapperLink, ) *ghbranchprotect.Config

func MapToBranchProtectionRes

func MapToBranchProtectionRes( branchProtectionConfig *GhBranchProtectionConfig, valGen tfsig.ValueGenerator, repo *GhRepoConfig, repoTfId string, links ...MapperLink, ) *ghbranchprotect.Config

func MapToBranchRes

func MapToBranchRes( name string, branchConfig *GhBranchConfig, valGen tfsig.ValueGenerator, repo *GhRepoConfig, repoTfId string, links ...MapperLink, ) *ghbranch.Config

func MapToDefaultBranchRes

func MapToDefaultBranchRes( branchConfig *GhDefaultBranchConfig, valGen tfsig.ValueGenerator, repo *GhRepoConfig, repoTfId string, links ...MapperLink, ) *ghbranchdefault.Config

func MapToRepositoryRes

func MapToRepositoryRes(repoConfig *GhRepoConfig, valGen tfsig.ValueGenerator, repoTfId string) *ghrepository.Config

func MapToSortedList

func MapToSortedList[T any](list map[string]T) []T

func MapToSortedListWithKeys

func MapToSortedListWithKeys[T any](list map[string]T) ([]string, []T)

func MaxTemplateCountReachedError

func MaxTemplateCountReachedError(tplType string, path []string) error

func MaxTemplateDepthReachedError

func MaxTemplateDepthReachedError(tplType string, path []string) error

func NewHclRepository

func NewHclRepository(repoTfId string, repoConfig *GhRepoConfig, valGen tfsig.ValueGenerator) *hclwrite.File

func NoTemplateAvailableError

func NoTemplateAvailableError(tplType string) error

func RepositoryNameIsMandatoryForConfigIndexError

func RepositoryNameIsMandatoryForConfigIndexError(index int) error

func RepositoryNameIsMandatoryForRepoError

func RepositoryNameIsMandatoryForRepoError(index int) error

func SchemaCompilationError

func SchemaCompilationError(url string, msg string) error

func SchemaIsNilError

func SchemaIsNilError(url string) error

func SchemaNotFoundError

func SchemaNotFoundError(url string) error

func SchemaValidationError

func SchemaValidationError(path string, location string, msg string) error

func TerraformFileWritingErrors

func TerraformFileWritingErrors(errList []error) error

func UnknownTemplateError

func UnknownTemplateError(tplType string, tplName string) error

func ValidateBranchProtectionTemplateConfig

func ValidateBranchProtectionTemplateConfig(filePath string) error

func ValidateBranchTemplateConfig

func ValidateBranchTemplateConfig(filePath string) error

func ValidateRepositoryConfig

func ValidateRepositoryConfig(filePath string) error

func ValidateRepositoryConfigs

func ValidateRepositoryConfigs(filePath string) error

func ValidateRepositoryTemplateConfig

func ValidateRepositoryTemplateConfig(filePath string) error

func WorkspacePathDoesntExistError

func WorkspacePathDoesntExistError(path string) error

func WorkspacePathIsExpectedToBeADirectoryError

func WorkspacePathIsExpectedToBeADirectoryError(path string) error

func WriteTerraformFiles

func WriteTerraformFiles(rootPath string, files map[string]*hclwrite.File) error

Types

type BaseGhBranchConfig

type BaseGhBranchConfig struct { ... }

func (*BaseGhBranchConfig) Merge

func (to *BaseGhBranchConfig) Merge(from *BaseGhBranchConfig)

type BaseGhBranchProtectionConfig

type BaseGhBranchProtectionConfig struct { ... }

func (*BaseGhBranchProtectionConfig) Merge

func (to *BaseGhBranchProtectionConfig) Merge(from *BaseGhBranchProtectionConfig)

type Config

type Config struct { ... }

func ComputeConfig

func ComputeConfig(config *Config) (*Config, error)

func NewConfig

func NewConfig() *Config

func (*Config) AppendRepo

func (c *Config) AppendRepo(repo *GhRepoConfig)

func (*Config) GetRepo

func (c *Config) GetRepo(name string) *GhRepoConfig

type GhBranchConfig

type GhBranchConfig struct { ... }

func ApplyBranchTemplate

func ApplyBranchTemplate(branchConfig *GhBranchConfig, templates *TemplatesConfig) (*GhBranchConfig, error)

func LoadBranchTemplateFromFile

func LoadBranchTemplateFromFile(filePath string, decoderOpts ...yaml.DecodeOption) (*GhBranchConfig, error)

func LoadGhRepoBranchConfigFromFile

func LoadGhRepoBranchConfigFromFile( filePath string, decoderOpts ...yaml.DecodeOption, ) (*GhBranchConfig, error)

LoadGhRepoBranchConfigFromFile loads the file content to GhBranchConfig struct No schema validation will be performed, use loadBranchTemplateFromFile instead !

func (*GhBranchConfig) Merge

func (to *GhBranchConfig) Merge(from *GhBranchConfig)

type GhBranchProtectPRReviewConfig

type GhBranchProtectPRReviewConfig struct { ... }

func (*GhBranchProtectPRReviewConfig) Merge

func (to *GhBranchProtectPRReviewConfig) Merge(from *GhBranchProtectPRReviewConfig)

type GhBranchProtectPRReviewDismissalsConfig

type GhBranchProtectPRReviewDismissalsConfig struct { ... }

func (*GhBranchProtectPRReviewDismissalsConfig) Merge

func (to *GhBranchProtectPRReviewDismissalsConfig) Merge(from *GhBranchProtectPRReviewDismissalsConfig)

type GhBranchProtectPushesConfig

type GhBranchProtectPushesConfig struct { ... }

func (*GhBranchProtectPushesConfig) Merge

func (to *GhBranchProtectPushesConfig) Merge(from *GhBranchProtectPushesConfig)

type GhBranchProtectStatusChecksConfig

type GhBranchProtectStatusChecksConfig struct { ... }

func (*GhBranchProtectStatusChecksConfig) Merge

func (to *GhBranchProtectStatusChecksConfig) Merge(from *GhBranchProtectStatusChecksConfig)

type GhBranchProtectionConfig

type GhBranchProtectionConfig struct { ... }

func ApplyBranchProtectionTemplate

func ApplyBranchProtectionTemplate( branchProtectionConfig *GhBranchProtectionConfig, templates *TemplatesConfig, ) (*GhBranchProtectionConfig, error)

func LoadBranchProtectionTemplateFromFile

func LoadBranchProtectionTemplateFromFile( filePath string, decoderOpts ...yaml.DecodeOption, ) (*GhBranchProtectionConfig, error)

func LoadGhRepoBranchProtectionConfigFromFile

func LoadGhRepoBranchProtectionConfigFromFile( filePath string, decoderOpts ...yaml.DecodeOption, ) (*GhBranchProtectionConfig, error)

LoadGhRepoBranchProtectionConfigFromFile loads the file content to GhBranchProtectionConfig struct No schema validation will be performed, use loadBranchProtectionTemplateFromFile instead !

func (*GhBranchProtectionConfig) Merge

func (to *GhBranchProtectionConfig) Merge(from *GhBranchProtectionConfig)

type GhBranchProtectionsConfig

type GhBranchProtectionsConfig []*GhBranchProtectionConfig

func (*GhBranchProtectionsConfig) Merge

func (to *GhBranchProtectionsConfig) Merge(from *GhBranchProtectionsConfig)

type GhBranchesConfig

type GhBranchesConfig map[string]*GhBranchConfig

func (*GhBranchesConfig) Merge

func (to *GhBranchesConfig) Merge(from *GhBranchesConfig)

type GhDefaultBranchConfig

type GhDefaultBranchConfig struct { ... }

func (*GhDefaultBranchConfig) Merge

func (to *GhDefaultBranchConfig) Merge(from *GhDefaultBranchConfig)

type GhRepoConfig

type GhRepoConfig struct { ... }

func ApplyRepositoryTemplate

func ApplyRepositoryTemplate(repoConfig *GhRepoConfig, templates *TemplatesConfig) (*GhRepoConfig, error)

func ComputeRepoConfig

func ComputeRepoConfig(base *GhRepoConfig, templates *TemplatesConfig) (*GhRepoConfig, error)

func LoadGhRepoConfigFromFile

func LoadGhRepoConfigFromFile(filePath string, decoderOpts ...yaml.DecodeOption) (*GhRepoConfig, error)

LoadGhRepoConfigFromFile loads the file content to GhRepoConfig struct No schema validation will be performed, use loadRepositoryFromFile or loadRepositoryTemplateFromFile instead !

func LoadGhRepoConfigListFromFile

func LoadGhRepoConfigListFromFile(filePath string, decoderOpts ...yaml.DecodeOption) ([]*GhRepoConfig, error)

LoadGhRepoConfigListFromFile loads the file content to GhRepoConfig struct No schema validation will be performed, use loadRepositoriesFromFile instead !

func LoadRepositoriesFromFile

func LoadRepositoriesFromFile(filePath string, decoderOpts ...yaml.DecodeOption) ([]*GhRepoConfig, error)

func LoadRepositoryFromFile

func LoadRepositoryFromFile(filePath string, decoderOpts ...yaml.DecodeOption) (*GhRepoConfig, error)

func LoadRepositoryTemplateFromFile

func LoadRepositoryTemplateFromFile(filePath string, decoderOpts ...yaml.DecodeOption) (*GhRepoConfig, error)

func (*GhRepoConfig) Merge

func (to *GhRepoConfig) Merge(from *GhRepoConfig)

type GhRepoFileTemplatesConfig

type GhRepoFileTemplatesConfig struct { ... }

func (*GhRepoFileTemplatesConfig) Merge

func (to *GhRepoFileTemplatesConfig) Merge(from *GhRepoFileTemplatesConfig)

type GhRepoMiscellaneousConfig

type GhRepoMiscellaneousConfig struct { ... }

func (*GhRepoMiscellaneousConfig) Merge

func (to *GhRepoMiscellaneousConfig) Merge(from *GhRepoMiscellaneousConfig)

type GhRepoPRBranchConfig

type GhRepoPRBranchConfig struct { ... }

func (*GhRepoPRBranchConfig) Merge

func (to *GhRepoPRBranchConfig) Merge(from *GhRepoPRBranchConfig)

type GhRepoPRCommitConfig

type GhRepoPRCommitConfig struct { ... }

func (*GhRepoPRCommitConfig) Merge

func (to *GhRepoPRCommitConfig) Merge(from *GhRepoPRCommitConfig)

type GhRepoPRMergeStrategyConfig

type GhRepoPRMergeStrategyConfig struct { ... }

func (*GhRepoPRMergeStrategyConfig) Merge

func (to *GhRepoPRMergeStrategyConfig) Merge(from *GhRepoPRMergeStrategyConfig)

type GhRepoPagesConfig

type GhRepoPagesConfig struct { ... }

func (*GhRepoPagesConfig) Merge

func (to *GhRepoPagesConfig) Merge(from *GhRepoPagesConfig)

type GhRepoPullRequestConfig

type GhRepoPullRequestConfig struct { ... }

func (*GhRepoPullRequestConfig) Merge

func (to *GhRepoPullRequestConfig) Merge(from *GhRepoPullRequestConfig)

type GhRepoSecurityConfig

type GhRepoSecurityConfig struct { ... }

func (*GhRepoSecurityConfig) Merge

func (to *GhRepoSecurityConfig) Merge(from *GhRepoSecurityConfig)

type GhRepoTemplateConfig

type GhRepoTemplateConfig struct { ... }

func (*GhRepoTemplateConfig) Merge

func (to *GhRepoTemplateConfig) Merge(from *GhRepoTemplateConfig)

type GhRepoTerraformConfig

type GhRepoTerraformConfig struct { ... }

func (*GhRepoTerraformConfig) Merge

func (to *GhRepoTerraformConfig) Merge(from *GhRepoTerraformConfig)

type MapperLink

type MapperLink int

Constants

const (
    LinkToRepository MapperLink = iota
    LinkToBranch
)

type Schema

type Schema struct { ... }

type SchemaList

type SchemaList map[string]*Schema

func (*SchemaList) Compile

func (s *SchemaList) Compile(url string) (*jsonschema.Schema, error)

func (*SchemaList) Find

func (s *SchemaList) Find(url string) (*Schema, error)

func (*SchemaList) FindCompiled

func (s *SchemaList) FindCompiled(url string) *jsonschema.Schema

func (*SchemaList) FindContent

func (s *SchemaList) FindContent(url string) (*string, error)

type TemplatesConfig

type TemplatesConfig struct { ... }

func (*TemplatesConfig) GetBranch

func (c *TemplatesConfig) GetBranch(name string) *GhBranchConfig

func (*TemplatesConfig) GetBranchProtection

func (c *TemplatesConfig) GetBranchProtection(name string) *GhBranchProtectionConfig

func (*TemplatesConfig) GetRepo

func (c *TemplatesConfig) GetRepo(name string) *GhRepoConfig


Readme created from Go doc with goreadme