ipr

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2023 License: MIT Imports: 8 Imported by: 0

README

Go Reference Go Go Report Card GitHub go.mod Go version GitHub GitHub release (latest SemVer) GitHub tag (latest SemVer)

ipr

ipr is a Go library and a CLI tool for reading whitelisted AWS IP ranges.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main() int

Types

type Client

type Client struct {
	URL        string
	HTTPClient *http.Client
}

Client holds data for making calls to the AWS whitelisted endpoint.

func NewClient

func NewClient() *Client

NewClient creates a default API client ready to talk to AWS endpoint.

Default client uses the official AWS endpoint to fetch ip ranges. You can specify different enpoint by exporting the `AWS_IP_URL` env var.

func (*Client) GetRanges

func (c *Client) GetRanges() (IPRanges, error)

Ranges returns whitelisted AWS IPv4 and IPv6 ranges.

type IPRange

type IPRange struct {
	Type               string `json:"ipv"`
	IPprefix           string `json:"ip_prefix"`
	Region             string `json:"region"`
	Service            string `json:"service"`
	NetworkBorderGroup string `json:"network_border_group"`
}

IPRange represents information about whitelisted IP range.

type IPRanges

type IPRanges struct {
	SyncToken  int       `json:"sync_token"`
	CreateDate time.Time `json:"create_date"`
	IPv4Ranges []IPRange `json:"ipv4_ranges"`
	IPv6Ranges []IPRange `json:"ipv6_ranges"`
}

IPRanges represents IPv4 and IPv6 AWS whitelisted IP ranges.

func GetIPRanges

func GetIPRanges() (IPRanges, error)

GetIPRanges pulls AWS Whitelisted IP ranges.

It uses default IP Range client. If you want to use a different AWS Whitelisted IP URL export the env variable "AWS_IP_URL".

func ParseResponse

func ParseResponse(resp Response) (IPRanges, error)

ParseResponse takes response struct and returns IPRanges.

It errors if the token or timestamp is malformed, or when either IPv4 or IPv6 cannot be parsed.

func (IPRanges) CSVRecords

func (ip IPRanges) CSVRecords() [][]string

ToCSVRecords creates csv records ready to pass to a csv writer.

type Response

type Response struct {
	SyncToken  string `json:"syncToken"`
	CreateDate string `json:"createDate"`
	Prefixes   []struct {
		IPPrefix           string `json:"ip_prefix"`
		Ipv6Prefix         string `json:"ipv6_prefix"`
		Region             string `json:"region"`
		Service            string `json:"service"`
		NetworkBorderGroup string `json:"network_border_group"`
	} `json:"prefixes"`
}

Response represents data received from AWS after successfull call to the whitelisted ip ranges url: "https://ip-ranges.amazonaws.com/ip-ranges.json"

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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