common

package
v0.0.0-...-f8e792b Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const ChecksumFileName = "checksum"

ChecksumFileName is the name which contains the checksum of the network ranges file

View Source
const DefaultRegion = "unknown"

DefaultRegion is used when a vendor does not specify regions for the IP ranges provided

View Source
const DefaultService = "unknown"

DefaultService is used when a vendor does not specify service names for the IP ranges provider

View Source
const LatestPrefixFileName = "latest_prefix"

LatestPrefixFileName is the name of the file that contains the prefix of latest networks definitions.

View Source
const MasterBucketPrefix = "external-networks"

MasterBucketPrefix is the top level prefix we use for all the uploads we do in this crawler

View Source
const MaxNumDefinitions = 10

MaxNumDefinitions is the maximum number of runs(outputted network definitions) we remember in the bucket specified in script. Oldest record should be deleted first.

View Source
const NetworkFileName = "networks"

NetworkFileName is the name of the network file we upload

Variables

View Source
var (
	// Google is provider "enum" for Google Cloud
	Google = newProvider("Google")
	// Azure is provider "enum" for Microsoft Azure Cloud
	Azure = newProvider("Azure")
	// Amazon is provider "enum" for Amazon AWS
	Amazon = newProvider("Amazon")
	// Oracle is provider "enum" for Oracle Cloud Platform
	Oracle = newProvider("Oracle")
	// Cloudflare is provider "enum" for Cloudflare
	Cloudflare = newProvider("Cloudflare")
)
View Source
var ProviderToURLs = map[Provider][]string{
	Google: {
		"https://www.gstatic.com/ipranges/cloud.json",
	},

	Azure: {

		"https://www.microsoft.com/download/details.aspx?id=56519",

		"https://www.microsoft.com/download/details.aspx?id=57063",

		"https://www.microsoft.com/download/details.aspx?id=57062",

		"https://www.microsoft.com/download/details.aspx?id=57064",
	},
	Amazon: {
		"https://ip-ranges.amazonaws.com/ip-ranges.json",
	},
	Oracle: {
		"https://docs.cloud.oracle.com/en-us/iaas/tools/public_ip_ranges.json",
	},
	Cloudflare: {
		"https://api.cloudflare.com/client/v4/ips",
	},
}

ProviderToURLs is a mapping from provider to its crawler endpoint. It is kept here for easier maintenance.

Functions

func EmptyRegionNameError

func EmptyRegionNameError(providerName string) error

EmptyRegionNameError is returned when an empty region name is found

func EmptyServiceNameError

func EmptyServiceNameError(providerName, regionName string) error

EmptyServiceNameError is returned when an empty service name is found

func LatestPrefixFileNotFound

func LatestPrefixFileNotFound(bucketName string) error

LatestPrefixFileNotFound is returned when there is no latest metadata file on the bucket

func NoBucketNameSpecified

func NoBucketNameSpecified() error

NoBucketNameSpecified is returned when the script is invoked without a bucket name

func NoIPPrefixesError

func NoIPPrefixesError(providerName, regionName, serviceName string) error

NoIPPrefixesError is returned when a service does not have any IP prefix crawled

func NoRegionNetworksError

func NoRegionNetworksError(providerName string) error

NoRegionNetworksError is returned when a provider does not have any region crawled

func NoServiceNetworksError

func NoServiceNetworksError(providerName, regionName string) error

NoServiceNetworksError is returned when a region does not have any service crawled

func NotEnoughIPPrefixesError

func NotEnoughIPPrefixesError(providerName string, numObserved, numRequired int) error

NotEnoughIPPrefixesError is returned when a crawler did not crawl enough IP prefixes for a provider

func NumProvidersError

func NumProvidersError(numProviders, numCrawlers int) error

NumProvidersError is returned when the number of providers crawled does not match with the number of crawles spawned

func ProviderNameEmptyError

func ProviderNameEmptyError() error

ProviderNameEmptyError is returned when an empty provider name is found

func RegionNetworksNotFound

func RegionNetworksNotFound(region string) error

RegionNetworksNotFound is returned when a region networks spec is not found

func ServiceNetworksNotFound

func ServiceNetworksNotFound(service string) error

ServiceNetworksNotFound is returned when a service networks spec is not found

func SetVerbose

func SetVerbose()

SetVerbose enables verbose mode

func Verbose

func Verbose() bool

Verbose returns if verbose options is set

Types

type ExternalNetworkSources

type ExternalNetworkSources struct {
	ProviderNetworks []*ProviderNetworkRanges `json:"providerNetworks"`
}

ExternalNetworkSources contains all the external networks for all providers

type IsRedundantRegionServicePairFn

type IsRedundantRegionServicePairFn func(
	newPair *RegionServicePair,
	existingPair *RegionServicePair,
) (*RegionServicePair, error)

IsRedundantRegionServicePairFn is a predicate function to determine if a new region service pair should be added to output or not. For example, if an IP address belongs to multiple region/service pairs, user needs to provide a predicate function which looks at the pairs that are already recorded in ProviderNetworkRanges and the new pair that is about to be added, then decide if the new pair should be added as well or not. The existing pairs are given one by one to the user.

The return value indicates which pair to remove. There could be three different return outcomes. Remove the new pair, remove the existing pair, or keep both. The returned pair is first checked with the new pair before checking with the existing pair. In case of keeping both pairs, a nil value should be returned

func GetDefaultRegionServicePairRedundancyCheck

func GetDefaultRegionServicePairRedundancyCheck() IsRedundantRegionServicePairFn

GetDefaultRegionServicePairRedundancyCheck returns the default check Default check checks if region and service names are the same

type NetworkCrawler

type NetworkCrawler interface {
	CrawlPublicNetworkRanges() (*ProviderNetworkRanges, error)
	GetHumanReadableProviderName() string
	GetProviderKey() Provider
	// GetNumRequiredIPPrefixes returns number of required IP prefixes crawled by crawler
	// Used during validation of crawler outputs.
	GetNumRequiredIPPrefixes() int
}

NetworkCrawler defines an interface for the implementation of Provider specific network range crawlers

type Provider

type Provider string

Provider is a string representing different external network providers

func AllProviders

func AllProviders() []Provider

AllProviders returns all the providers available

func ToProvider

func ToProvider(s string) (Provider, error)

ToProvider converts a string representation of a provider to Provider type

func (Provider) String

func (p Provider) String() string

type ProviderNetworkRanges

type ProviderNetworkRanges struct {
	ProviderName   string                 `json:"providerName"`
	RegionNetworks []*RegionNetworkDetail `json:"regionNetworks"`
	// contains filtered or unexported fields
}

ProviderNetworkRanges contains networks for all regions of a provider

func NewProviderNetworkRanges

func NewProviderNetworkRanges(providerName string) *ProviderNetworkRanges

NewProviderNetworkRanges returns a new instance of ProviderNetworkRanges

func (*ProviderNetworkRanges) AddIPPrefix

func (p *ProviderNetworkRanges) AddIPPrefix(region, service, ipPrefix string, fn IsRedundantRegionServicePairFn) error

AddIPPrefix adds the specified IP prefix to the region and service name pair returns error if the IP given is not a valid IP prefix

type RegionNetworkDetail

type RegionNetworkDetail struct {
	RegionName      string             `json:"regionName"`
	ServiceNetworks []*ServiceIPRanges `json:"serviceNetworks"`
}

RegionNetworkDetail contains all the networks of services under a region

func RgnNetDetSliceRemove

func RgnNetDetSliceRemove(in []*RegionNetworkDetail, i int) []*RegionNetworkDetail

RgnNetDetSliceRemove removes an element from a RegionNetworkDetail slice at the specified index

type RegionServicePair

type RegionServicePair struct {
	Region  string
	Service string
}

RegionServicePair is a tuple of region and service names

func RgnSvcPairSliceRemove

func RgnSvcPairSliceRemove(in []*RegionServicePair, i int) []*RegionServicePair

RgnSvcPairSliceRemove removes an element from a RegionServicePair slice at the specified index

func (*RegionServicePair) Equals

Equals checks if two RegionServicePairs are equal

func (*RegionServicePair) String

func (r *RegionServicePair) String() string

String returns the string representation of a RegionServicePair

type ServiceIPRanges

type ServiceIPRanges struct {
	// ServiceName denotes the service name for the IP ranges
	ServiceName string `json:"serviceName"`
	// Sample IPv4 prefix: 8.8.0.0/16
	IPv4Prefixes []string `json:"ipv4Prefixes"`
	// Sample IPv6 prefix: 2600:1901::/48
	IPv6Prefixes []string `json:"ipv6Prefixes"`
}

ServiceIPRanges contains all the IP ranges used by a specific service

func SvcIPRangesSliceRemove

func SvcIPRangesSliceRemove(in []*ServiceIPRanges, i int) []*ServiceIPRanges

SvcIPRangesSliceRemove removes an element from a ServiceIPRanges slice at the specified index

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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