Documentation
¶
Overview ¶
Package util provides helper functions for the minder CLI.
Package util provides helper functions for the minder CLI.
Package util provides helper functions for minder ¶
Package util provides helper functions for the minder CLI.
Index ¶
- Variables
- func ExpandFileArgs(files []string) ([]string, error)
- func GenerateCurlCommand(method, apiBaseURL, endpoint, body string) (string, error)
- func GetArtifactWithVersions(ctx context.Context, store db.ExtendQuerier, repoID, artifactID uuid.UUID) (*minderv1.Artifact, error)
- func GetBytesFromProto(message protoreflect.ProtoMessage) ([]byte, error)
- func GetGrpcConnection(grpc_host string, grpc_port int, allowInsecure bool, issuerUrl string, ...) (*grpc.ClientConn, error)
- func GetJsonFromProto(msg protoreflect.ProtoMessage) (string, error)
- func GetPassFromTerm(confirm bool) ([]byte, error)
- func GetPullRequest(ctx context.Context, store db.ExtendQuerier, repoID, pullRequestID uuid.UUID) (*minderv1.PullRequest, error)
- func GetRepository(ctx context.Context, store db.ExtendQuerier, repoID uuid.UUID) (*minderv1.Repository, error)
- func GetToken(issuerUrl string, clientId string) (string, error)
- func GetYamlFromProto(msg protoreflect.ProtoMessage) (string, error)
- func HttpMethodFromString(inMeth, dfl string) string
- func Int32FromString(v string) (int32, error)
- func JQReadFrom[T any](ctx context.Context, path string, obj any) (T, error)
- func OpenFileArg(f string, dashOpen io.Reader) (desc io.Reader, closer func(), err error)
- func PBRepositoryFromDB(dbrepo db.Repository) *minderv1.Repository
- func ParseNewHtmlTemplate(tmpl *string, name string) (*htmltemplate.Template, error)
- func ParseNewTextTemplate(tmpl *string, name string) (*template.Template, error)
- func RemoveCredentials() error
- func SanitizingInterceptor() grpc.UnaryServerInterceptor
- func SaveCredentials(tokens OpenIdCredentials) (string, error)
- func WriteToFile(out string, content []byte, perms fs.FileMode) error
- type JWTTokenCredentials
- type NiceStatus
- type OpenIdCredentials
- type TestWriter
Constants ¶
This section is empty.
Variables ¶
var ( // PyRequestsVersionRegexp is a regexp to match a line in a requirements.txt file, including the package version // and the comparison operators PyRequestsVersionRegexp = regexp.MustCompile(`\s*(>=|<=|==|>|<|!=)\s*(\d+(\.\d+)*(\*)?)`) // PyRequestsNameRegexp is a regexp to match a line in a requirements.txt file, parsing out the package name PyRequestsNameRegexp = regexp.MustCompile(`\s*(>=|<=|==|>|<|!=)`) )
var ErrNoValueFound = errors.New("evaluation error")
ErrNoValueFound is an error that is returned when the accessor doesn't find anything
Functions ¶
func ExpandFileArgs ¶
ExpandFileArgs expands a list of file arguments into a list of files. If the file list contains "-" or regular files, it will leave them as-is. If the file list contains directories, it will expand them into a list of files.
func GenerateCurlCommand ¶
GenerateCurlCommand generates a curl command from a method, apiBaseURL, endpoint, and body this is useful to provide a dry-run for remediations
func GetArtifactWithVersions ¶
func GetArtifactWithVersions( ctx context.Context, store db.ExtendQuerier, repoID, artifactID uuid.UUID) (*minderv1.Artifact, error)
GetArtifactWithVersions retrieves an artifact and its versions from the database
func GetBytesFromProto ¶
func GetBytesFromProto(message protoreflect.ProtoMessage) ([]byte, error)
GetBytesFromProto given a proto message, formats into bytes
func GetGrpcConnection ¶
func GetGrpcConnection( grpc_host string, grpc_port int, allowInsecure bool, issuerUrl string, clientId string, opts ...grpc.DialOption) ( *grpc.ClientConn, error)
GetGrpcConnection is a helper for getting a testing connection for grpc
func GetJsonFromProto ¶
func GetJsonFromProto(msg protoreflect.ProtoMessage) (string, error)
GetJsonFromProto given a proto message, formats into json
func GetPassFromTerm ¶
GetPassFromTerm gets a password from the terminal
func GetPullRequest ¶ added in v0.0.17
func GetPullRequest( ctx context.Context, store db.ExtendQuerier, repoID, pullRequestID uuid.UUID, ) (*minderv1.PullRequest, error)
GetPullRequest retrieves a pull request from the database and converts it to a protobuf
func GetRepository ¶ added in v0.0.17
func GetRepository(ctx context.Context, store db.ExtendQuerier, repoID uuid.UUID) (*minderv1.Repository, error)
GetRepository retrieves a repository from the database and converts it to a protobuf
func GetToken ¶
GetToken retrieves the access token from the credentials file and refreshes it if necessary
func GetYamlFromProto ¶
func GetYamlFromProto(msg protoreflect.ProtoMessage) (string, error)
GetYamlFromProto given a proto message, formats into yaml
func HttpMethodFromString ¶
HttpMethodFromString returns the HTTP method from a string based on upprecase inMeth, defaulting to dfl
func Int32FromString ¶
Int32FromString converts a string to an int32
func JQReadFrom ¶
JQReadFrom gets the typed value from the given accessor. Returns an error when the accessor doesn't find anything or when the type assertion fails. Useful for when you know the type you're expecting AND the accessor must return a value (IOW, the value is required by the caller)
func OpenFileArg ¶
OpenFileArg opens a file argument and returns a descriptor, closer, and error If the file is "-", it will return whatever is passed in as dashOpen and a no-op closer
func PBRepositoryFromDB ¶ added in v0.0.21
func PBRepositoryFromDB(dbrepo db.Repository) *minderv1.Repository
PBRepositoryFromDB converts a database repository to a protobuf Note this doesn't set the context as that's assumed to be set on the caller's side.
func ParseNewHtmlTemplate ¶ added in v0.0.19
func ParseNewHtmlTemplate(tmpl *string, name string) (*htmltemplate.Template, error)
ParseNewHtmlTemplate parses a named template from a string, ensuring it is not empty
func ParseNewTextTemplate ¶ added in v0.0.19
ParseNewTextTemplate parses a named template from a string, ensuring it is not empty
func RemoveCredentials ¶
func RemoveCredentials() error
RemoveCredentials removes the local credentials file
func SanitizingInterceptor ¶
func SanitizingInterceptor() grpc.UnaryServerInterceptor
SanitizingInterceptor sanitized error statuses which do not conform to NiceStatus, ensuring that we don't accidentally leak implementation details over gRPC.
func SaveCredentials ¶
func SaveCredentials(tokens OpenIdCredentials) (string, error)
SaveCredentials saves the credentials to a file
Types ¶
type JWTTokenCredentials ¶
type JWTTokenCredentials struct {
// contains filtered or unexported fields
}
JWTTokenCredentials is a helper struct for grpc
func (JWTTokenCredentials) GetRequestMetadata ¶
func (jwt JWTTokenCredentials) GetRequestMetadata(_ context.Context, _ ...string) (map[string]string, error)
GetRequestMetadata implements the PerRPCCredentials interface.
func (JWTTokenCredentials) RequireTransportSecurity ¶
func (JWTTokenCredentials) RequireTransportSecurity() bool
RequireTransportSecurity implements the PerRPCCredentials interface.
type NiceStatus ¶
type NiceStatus struct { // Description status code Code codes.Code // Name Name string // Description Description string // Actions, reasons and links Details string }
NiceStatus A wrapper around a status to give a better description.
func FromRpcError ¶
func FromRpcError(s *status.Status) *NiceStatus
FromRpcError convert a grpc status.Status to a nice status for formatting
func GetNiceStatus ¶
func GetNiceStatus(code codes.Code) *NiceStatus
GetNiceStatus get a nice status from the code.
func UserVisibleError ¶
func UserVisibleError(code codes.Code, message string, args ...any) *NiceStatus
UserVisibleError returns a status error where message is visible to the user, rather than being filtered to generic advice. You need to use this explicitly, so that it's easy to track where we are providing (leaking) user-visible information from minder.
func (*NiceStatus) GRPCStatus ¶
func (s *NiceStatus) GRPCStatus() *status.Status
GRPCStatus makes NiceStatus a valid GRPC status response (see https://godoc.org/google.golang.org/grpc/status#FromError for details)
func (*NiceStatus) SetCode ¶
func (s *NiceStatus) SetCode(code codes.Code) *NiceStatus
SetCode generates the nice status from the code.
func (*NiceStatus) String ¶
func (s *NiceStatus) String() string
String convert the status to a string
type OpenIdCredentials ¶
type OpenIdCredentials struct { AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token"` AccessTokenExpiresAt time.Time `json:"expiry"` }
OpenIdCredentials is a struct to hold the access and refresh tokens
func LoadCredentials ¶
func LoadCredentials() (OpenIdCredentials, error)
LoadCredentials loads the credentials from a file
func RefreshCredentials ¶
func RefreshCredentials(refreshToken string, issuerUrl string, clientId string) (OpenIdCredentials, error)
RefreshCredentials uses a refresh token to get and save a new set of credentials
type TestWriter ¶
type TestWriter struct {
Output string
}
TestWriter is a helper struct for testing
Directories
¶
Path | Synopsis |
---|---|
Package cli contains utility for the cli
|
Package cli contains utility for the cli |
table
Package table contains utilities for rendering tables
|
Package table contains utilities for rendering tables |
table/layouts
Package layouts defines the available table layouts
|
Package layouts defines the available table layouts |
table/simple
Package simple contains a simple table
|
Package simple contains a simple table |
useragent
Package useragent contains utilities for setting up the CLI's user agent
|
Package useragent contains utilities for setting up the CLI's user agent |
Package jsonyaml contains utility functions for converting to/from json and yaml
|
Package jsonyaml contains utility functions for converting to/from json and yaml |
Package rand contains utility functions largely for unit testing.
|
Package rand contains utility functions largely for unit testing. |
Package schemaupdate contains utility functions to compare two schemas for updates
|
Package schemaupdate contains utility functions to compare two schemas for updates |
Package testqueue contains queue utilities for testing
|
Package testqueue contains queue utilities for testing |