hostdetect

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package hostdetect provides git hosting provider detection utilities. This package is used for consistent provider identification across: - SBOM generation (supplier extraction) - PURL creation (package type detection) - CVE/vulnerability scanning (ecosystem detection for OSV.dev)

The detection supports both well-known hosts (github.com, gitlab.com, bitbucket.org) and self-hosted/enterprise instances (e.g., gitlab.internal.corp, github.enterprise.com).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsKnownProvider

func IsKnownProvider(p Provider) bool

IsKnownProvider returns true if the provider is a recognized hosting service (not ProviderUnknown). This is useful for determining if PURL type should be specific (github, gitlab, bitbucket) or generic.

func SupportsCVEScanning

func SupportsCVEScanning(p Provider) bool

SupportsCVEScanning returns true if the provider is supported by vulnerability databases like OSV.dev for CVE scanning.

Types

type Info

type Info struct {
	// Provider is the detected git hosting provider.
	Provider Provider

	// Host is the hostname (e.g., "github.com", "gitlab.internal.corp").
	Host string

	// Owner is the repository owner/organization (may include nested groups for GitLab).
	Owner string

	// Repo is the repository name.
	Repo string
}

Info contains information extracted from a repository URL.

func FromURL

func FromURL(repoURL string) *Info

FromURL extracts provider information from a git repository URL. Returns nil if the URL is empty, invalid, or doesn't have enough path components.

Supported URL formats:

type Provider

type Provider string

Provider represents a git hosting provider type.

const (
	// ProviderGitHub represents GitHub (github.com and GitHub Enterprise).
	ProviderGitHub Provider = "github"

	// ProviderGitLab represents GitLab (gitlab.com and self-hosted GitLab).
	ProviderGitLab Provider = "gitlab"

	// ProviderBitbucket represents Bitbucket (bitbucket.org and Bitbucket Server).
	ProviderBitbucket Provider = "bitbucket"

	// ProviderUnknown represents an unknown or generic git hosting provider.
	ProviderUnknown Provider = "unknown"
)

Provider constants for common git hosting services.

func DetectProvider

func DetectProvider(host string) Provider

DetectProvider determines the provider type from a hostname.

Detection strategy: 1. Exact match on well-known hosts (github.com, gitlab.com, bitbucket.org) 2. Suffix match for enterprise instances (e.g., github.enterprise.com) 3. Contains match for self-hosted instances (e.g., gitlab.internal.corp)

This allows detection of enterprise/self-hosted instances while avoiding false positives like "notgithub.com".

Jump to

Keyboard shortcuts

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