util

package
v1.27.4 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToUTF8 added in v1.20.0

func ConvertToUTF8(content []byte) ([]byte, error)

func DecodePath added in v0.4.0

func DecodePath(encodedRelativePath string) (string, error)

func EncodePath added in v0.4.0

func EncodePath(relativePath string) string

func GetBranchName added in v1.25.0

func GetBranchName(path string) (string, error)

func GetCommitId added in v1.24.0

func GetCommitId(path string) (string, error)

func GetRepositoryUrl added in v1.1.0

func GetRepositoryUrl(path string) (string, error)

GetRepositoryUrl resolves the remote repository URL for the checkout at path from the "origin" remote.

The repository URL is what associates findings with an SCM asset/project, so a missing URL silently disables consistent-ignores. Only the "origin" remote is used: findings are never attributed to a different remote that happens to be configured. The returned URL is stripped of any embedded credentials.

func Hash

func Hash(content []byte) (string, error)

func SanitiseCredentials added in v1.5.4

func SanitiseCredentials(rawURL string) (string, error)

SanitiseCredentials returns the repository URL with any embedded credentials removed. It never returns a URL that still contains a secret:

  • Standard URLs (those with a "scheme://" - https, ssh, git, ...) have their entire userinfo component stripped.
  • scp-style SSH remotes ("[user@]host:path", which have no scheme) are returned unchanged: the user component (e.g. "git") is not a secret, and a password cannot appear in this syntax. An "@" at or after the host:path ":" belongs to the path (e.g. an email address in the path) and is preserved, so "host:dir/a@b.com/repo.git" is not mangled.
  • Input that cannot be confidently sanitized (a "scheme://" URL that fails to parse, where credentials could be present in an unknown position) fails closed with an error rather than returning the raw, credential-bearing string.

func ToAbsolutePath added in v0.4.0

func ToAbsolutePath(baseDir string, relativePath string) string

func ToRelativeUnixPath added in v0.4.0

func ToRelativeUnixPath(baseDir string, absoluteFilePath string) (string, error)

Types

This section is empty.

Directories

Path Synopsis
* © 2024 Snyk Limited All rights reserved.
* © 2024 Snyk Limited All rights reserved.

Jump to

Keyboard shortcuts

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