repositoryhost

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DateFormat defines format for LastModifiedDate & PublishDate
	DateFormat = "2006-01-02 15:04:05"
)

Variables

This section is empty.

Functions

func IsRelative

func IsRelative(link string) bool

IsRelative is a helper function that checks if a link is relative

func IsResourceURL

func IsResourceURL(link string) bool

IsResourceURL checks if link is resource URL

func RawURL

func RawURL(resourceURL string) (string, error)

RawURL returns the GitHub raw URL if the resource is 'blob', otherwise returns the origin URL

func ReadGitInfo

func ReadGitInfo(ctx context.Context, repositories Repositories, r URL) ([]byte, error)

ReadGitInfo reads the git info for a given resource URL

Types

type Credential

type Credential struct {
	Host       string
	OAuthToken string
}

Credential holds repository credential data

type ErrResourceNotFound

type ErrResourceNotFound string

ErrResourceNotFound indicated that a resource was not found

func (ErrResourceNotFound) Error

func (e ErrResourceNotFound) Error() string

Error returns "resource r not found" error

type Git

type Git interface {
	GetBlobRaw(ctx context.Context, owner, repo, sha string) ([]byte, *github.Response, error)
	GetTree(ctx context.Context, owner string, repo string, sha string, recursive bool) (*github.Tree, *github.Response, error)
}

Git is an interface needed for faking

type GitInfo

type GitInfo struct {
	LastModifiedDate *string        `json:"lastmod,omitempty"`
	PublishDate      *string        `json:"publishdate,omitempty"`
	Author           *github.User   `json:"author,omitempty"`
	Contributors     []*github.User `json:"contributors,omitempty"`
	WebURL           *string        `json:"weburl,omitempty"`
	SHA              *string        `json:"sha,omitempty"`
	SHAAlias         *string        `json:"shaalias,omitempty"`
	Path             *string        `json:"path,omitempty"`
}

GitInfo defines git resource attributes

type InitOptions

type InitOptions struct {
	CacheHomeDir     string            `mapstructure:"cache-dir"`
	Credentials      map[string]string `mapstructure:"github-oauth-token-map"`
	ResourceMappings map[string]string `mapstructure:"resourceMappings"`
	Hugo             bool              `mapstructure:"hugo"`
}

InitOptions options for the resource handler

type Interface

type Interface interface {
	// ResourceURL returns a valid resource url object from a string url
	ResourceURL(resourceURL string) (*URL, error)
	// ResolveRelativeLink resolves a relative link given a source resource url
	ResolveRelativeLink(source URL, relativeLink string) (string, error)
	// LoadRepository loads the content of the repository of a given url
	LoadRepository(ctx context.Context, resourceURL string) error
	// Tree returns files that are present in the given url tree
	Tree(resource URL) ([]string, error)
	// Accept accepts manifests if this RepositoryHost can manage the type of resources identified by the URI scheme of uri.
	Accept(link string) bool
	// Read a resource content at uri into a byte array
	Read(ctx context.Context, resource URL) ([]byte, error)
	// Name of repository host
	Name() string
	// Repositories returns the repositories object
	Repositories() Repositories
	// GetClient returns an HTTP client for accessing handler's resources
	GetClient() httpclient.Client
	// GetRateLimit returns rate limit and remaining API calls for the resource handler backend (e.g. GitHub RateLimit)
	// returns negative values if RateLimit is not applicable
	GetRateLimit(ctx context.Context) (int, int, time.Time, error)
}

Interface does resource specific operations on a type of objects identified by an uri schema that it accepts to handle

func NewGHC

func NewGHC(hostName string, rateLimit RateLimitSource, repositories Repositories, git Git, client httpclient.Client, acceptedHosts []string, options ParsingOptions) Interface

NewGHC creates new GHC resource handler

func NewLocal

func NewLocal(os osshim.Os, urlPrefix string, localPath string) Interface

NewLocal creates a local repository host

func NewLocalTest

func NewLocalTest(localRepo embed.FS, urlPrefix string, localPath string) Interface

NewLocalTest creates a local repository host used for testing

type Local

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

Local represents a local repository defined by respurce mapping

func (*Local) Accept

func (l *Local) Accept(link string) bool

Accept if the link has the same url prefix as defined

func (*Local) GetClient

func (l *Local) GetClient() httpclient.Client

GetClient does nothing

func (*Local) GetRateLimit

func (l *Local) GetRateLimit(ctx context.Context) (int, int, time.Time, error)

GetRateLimit is not implemented

func (*Local) LoadRepository

func (l *Local) LoadRepository(ctx context.Context, resourceURL string) error

LoadRepository does nothing

func (*Local) Name

func (l *Local) Name() string

Name returns "local " + urlPrefix

func (*Local) Read

func (l *Local) Read(_ context.Context, resource URL) ([]byte, error)

Read a resource content at uri into a byte array from file system

func (*Local) Repositories

func (l *Local) Repositories() Repositories

Repositories does nothing

func (l *Local) ResolveRelativeLink(source URL, relativeLink string) (string, error)

ResolveRelativeLink resolves a relative link given a source resource url

func (*Local) ResourceURL

func (l *Local) ResourceURL(resourceURL string) (*URL, error)

ResourceURL returns a valid resource url object from a string url

func (*Local) Tree

func (l *Local) Tree(resource URL) ([]string, error)

Tree returns files that are present in the given url tree

type ParsingOptions

type ParsingOptions struct {
	ExtractedFilesFormats []string `mapstructure:"extracted-files-formats"`
	Hugo                  bool     `mapstructure:"hugo"`
}

ParsingOptions are options when parsing

type RateLimitSource

type RateLimitSource interface {
	RateLimits(ctx context.Context) (*github.RateLimits, *github.Response, error)
}

RateLimitSource is an interface needed for faking

type Repositories

type Repositories interface {
	ListCommits(ctx context.Context, owner, repo string, opts *github.CommitsListOptions) ([]*github.RepositoryCommit, *github.Response, error)
	Get(ctx context.Context, owner, repo string) (*github.Repository, *github.Response, error)
}

Repositories is an interface needed for faking

type URL

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

URL represents an repsource url

func (URL) GetDifferentType

func (r URL) GetDifferentType(newType string) (string, error)

GetDifferentType returns the url string of the given resource but with a different type

func (URL) GetHost

func (r URL) GetHost() string

GetHost returns the host of the URL

func (URL) GetOwner

func (r URL) GetOwner() string

GetOwner returns the owner of the URL

func (URL) GetRef

func (r URL) GetRef() string

GetRef returns the reference of the URL

func (URL) GetRepo

func (r URL) GetRepo() string

GetRepo returns the repository of the URL

func (URL) GetResourcePath

func (r URL) GetResourcePath() string

GetResourcePath returns the resource path of the URL

func (URL) GetResourceSuffix

func (r URL) GetResourceSuffix() string

GetResourceSuffix returns the resource suffix of the URL

func (URL) GetResourceType

func (r URL) GetResourceType() string

GetResourceType returns the resource type of the URL

func (URL) ReferenceURL

func (r URL) ReferenceURL() URL

ReferenceURL returns the reference url object

func (r URL) ResolveRelativeLink(relativeLink string) (string, string, error)

ResolveRelativeLink returns the possible blob and tree url string of a given relative link

func (URL) ResourceURL

func (r URL) ResourceURL() string

ResourceURL returns the resource url without resource suffix

func (URL) String

func (r URL) String() string

String returns the full url

Directories

Path Synopsis
internal
SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Gardener contributors
SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Gardener contributors

Jump to

Keyboard shortcuts

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