resource

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseResource

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

BaseResource is a mixin to handle some of the common resource related methods

func (*BaseResource) ID

func (r *BaseResource) ID() string

ID returns a path-safe, unique id for this resource

type Files

type Files struct {
	// Provide common helper functions
	BaseResource
	// contains filtered or unexported fields
}

Files provides a way to scan file systems

func NewFiles

func NewFiles(path string, options *FilesOptions) *Files

NewFiles returns a configured Files resource for the scanner to scan

func (*Files) Clone

func (r *Files) Clone(path string) error

Clone the resource to the desired local location and store the path

func (*Files) ClonePath

func (r *Files) ClonePath() string

ClonePath returns where this repo has been cloned if cloned else ""

func (*Files) Depth

func (r *Files) Depth() uint16

Depth returns the depth for things that have version control

func (*Files) Kind

func (r *Files) Kind() string

Kind of resource (always returns Files here)

func (*Files) ReadFile

func (r *Files) ReadFile(path string) ([]byte, error)

ReadFile provides a way to access values in the JSON data

func (*Files) SetCloneTimeout

func (r *Files) SetCloneTimeout(timeout time.Duration)

SetCloneTimeout lets you adjust the timeout before the clone aborts

func (*Files) SetDepth

func (r *Files) SetDepth(depth uint16)

SetDepth allows you to adjust the depth for the resource

func (*Files) Since

func (r *Files) Since() string

Since returns the date after which things should be scanned for things that have versions

func (*Files) String

func (r *Files) String() string

String representation of the resource

func (*Files) Walk

func (r *Files) Walk(fn WalkFunc) error

Walk traverses the JSON data structure like it's a directory tree

type FilesOptions

type FilesOptions struct {
}

FilesOptions are options for the Files resource

type GitRepo

type GitRepo struct {
	// Provide common helper functions
	BaseResource
	// contains filtered or unexported fields
}

GitRepo provides a way to interact with a git repo

func NewGitRepo

func NewGitRepo(cloneURL string, options *GitRepoOptions) *GitRepo

NewGitRepo returns a configured git repo resource for the scanner to scan

func (*GitRepo) Clone

func (r *GitRepo) Clone(path string) error

Clone the resource to the desired local location and store the path

func (*GitRepo) ClonePath

func (r *GitRepo) ClonePath() string

ClonePath returns where this repo has been cloned if cloned else ""

func (*GitRepo) Depth

func (r *GitRepo) Depth() uint16

Depth returns the depth for things that have version control

func (*GitRepo) GitDirPath

func (r *GitRepo) GitDirPath() string

GitDirPath returns the path to the git dir so that other things don't need to know how the repo was cloned

func (*GitRepo) Kind

func (r *GitRepo) Kind() string

Kind of resource (always returns GitRepo here

func (*GitRepo) ReadFile

func (r *GitRepo) ReadFile(path string) ([]byte, error)

ReadFile provides a way to get files out of the repo

func (*GitRepo) Refs

func (r *GitRepo) Refs() []string

Refs returns the unique OIDs in a repo

func (*GitRepo) RemoteRefExists

func (r *GitRepo) RemoteRefExists(ref string) bool

RemoteRefExists checks the remote repository to see if the ref exists

func (*GitRepo) SetCloneTimeout

func (r *GitRepo) SetCloneTimeout(timeout time.Duration)

SetCloneTimeout lets you adjust the timeout before the clone aborts

func (*GitRepo) SetDepth

func (r *GitRepo) SetDepth(depth uint16)

SetDepth allows you to adjust the depth for the resource

func (*GitRepo) ShallowCommits

func (r *GitRepo) ShallowCommits() []string

ShallowCommits returns a list of shallow commits in a git repo

func (*GitRepo) Since

func (r *GitRepo) Since() string

Since returns the date after which things should be scanned for things that have versions

func (*GitRepo) String

func (r *GitRepo) String() string

String representation of the resource

func (*GitRepo) Walk

func (r *GitRepo) Walk(fn WalkFunc) error

Walk traverses the HEAD of a git repo like it's a directory tree. This exists this way so even a bare repo can be crawled if needed. To crawl different branches, change HEAD.

type GitRepoOptions

type GitRepoOptions struct {
	// Only scan this branch
	Branch string `json:"branch"`
	// Only scan this many commits (reduced if larger than the max scan depth)
	Depth uint16 `json:"depth"`
	// Only scan since this date
	Since string `json:"since"`
	// Work through a proxy for this request
	Proxy string `json:"proxy"`
}

GitRepoOptions stores options specific to GitRepo scan requests

type JSONData

type JSONData struct {
	// Provide common helper functions
	BaseResource
	// contains filtered or unexported fields
}

JSONData provides a way to interact with a json data as a resource

func NewJSONData

func NewJSONData(raw string, options *JSONDataOptions) *JSONData

NewJSONData returns a configured JSONData resource for the scanner to scan

func (*JSONData) Clone

func (r *JSONData) Clone(path string) error

Clone the resource to the desired local location and store the path

func (*JSONData) ClonePath

func (r *JSONData) ClonePath() string

ClonePath returns where this repo has been cloned if cloned else ""

func (*JSONData) Depth

func (r *JSONData) Depth() uint16

Depth returns the depth for things that have version control

func (*JSONData) Kind

func (r *JSONData) Kind() string

Kind of resource (always returns JSONData here)

func (*JSONData) ReadFile

func (r *JSONData) ReadFile(path string) ([]byte, error)

ReadFile provides a way to access values in the JSON data

func (*JSONData) SetCloneTimeout

func (r *JSONData) SetCloneTimeout(timeout time.Duration)

SetCloneTimeout lets you adjust the timeout before the clone aborts

func (*JSONData) SetDepth

func (r *JSONData) SetDepth(depth uint16)

SetDepth allows you to adjust the depth for the resource

func (*JSONData) Since

func (r *JSONData) Since() string

Since returns the date after which things should be scanned for things that have versions

func (*JSONData) String

func (r *JSONData) String() string

String representation of the resource

func (*JSONData) Walk

func (r *JSONData) Walk(fn WalkFunc) error

Walk traverses the JSON data structure like it's a directory tree

type JSONDataOptions

type JSONDataOptions struct {
	FetchURLs bool `json:"fetch_urls"`
}

JSONDataOptions are options for the JSONData resource

type Resource

type Resource interface {
	Clone(path string) error
	ClonePath() string
	Depth() uint16
	ID() string
	Kind() string
	ReadFile(path string) ([]byte, error)
	SetCloneTimeout(timeout time.Duration)
	SetDepth(depth uint16)
	Since() string
	String() string
	// Walk is the main way to pick through resource data (except for GitRepo)
	Walk(WalkFunc) error
}

Resource provides a standard interface for acting with resources in the scanner

func NewResource

func NewResource(kind, resource string, options json.RawMessage) (Resource, error)

NewResource handles building out the resource from kind, the resource string and the options as a raw json message

type URL

type URL struct {
	// Provide common helper functions
	BaseResource
	// contains filtered or unexported fields
}

URL provides a to pull remote content by a URL

func NewURL

func NewURL(url string, options *URLOptions) *URL

NewURL returns a configured URL resource for the scanner to scan

func (*URL) Clone

func (r *URL) Clone(path string) error

Clone the resource to the desired local location and store the path

func (*URL) ClonePath

func (r *URL) ClonePath() string

ClonePath returns where this repo has been cloned if cloned else ""

func (*URL) Depth

func (r *URL) Depth() uint16

Depth returns the depth for things that have version control

func (*URL) Kind

func (r *URL) Kind() string

Kind of resource (always returns URL here)

func (*URL) ReadFile

func (r *URL) ReadFile(path string) ([]byte, error)

ReadFile provides a way to access values in the resource

func (*URL) SetCloneTimeout

func (r *URL) SetCloneTimeout(timeout time.Duration)

SetCloneTimeout lets you adjust the timeout before the clone aborts

func (*URL) SetDepth

func (r *URL) SetDepth(depth uint16)

SetDepth allows you to adjust the depth for the resource

func (*URL) Since

func (r *URL) Since() string

Since returns the date after which things should be scanned for things that have versions

func (*URL) String

func (r *URL) String() string

String representation of the resource

func (*URL) Walk

func (r *URL) Walk(fn WalkFunc) error

Walk traverses the resource like a directory tree

type URLOptions

type URLOptions struct {
}

URLOptions are options for the URL resource

type WalkFunc

type WalkFunc func(path string, reader io.Reader) error

WalkFunc is the func signature for functions passed into the various resource Walk methods.

Jump to

Keyboard shortcuts

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