utils

package
v0.0.0-...-e68299f Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Copyright © 2021 Koen Kumps

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var Debug = log.New(os.Stdout, "\u001b[36mDEBUG: \u001B[0m", log.LstdFlags)

Debug writes logs in the color cyan with "DEBUG: " as prefix

View Source
var Error = log.New(os.Stdout, "\u001b[31mERROR: \u001b[0m", log.LstdFlags)

Error writes logs in the color red with "ERROR: " as prefix

View Source
var Info = log.New(os.Stdout, "\u001b[34mINFO: \u001B[0m", log.LstdFlags)

Info writes logs in the color blue with "INFO: " as prefix

View Source
var Warning = log.New(os.Stdout, "\u001b[33mWARNING: \u001B[0m", log.LstdFlags)

Warning writes logs in the color yellow with "WARNING: " as prefix

Functions

func DestinationExists

func DestinationExists(path string) bool

DestinationExists checks if a path or file exists

func DownloadGitHubIP

func DownloadGitHubIP(metaData **GitHub) (err error)

DownloadGithubIP fetches the CIDR zones from the GitHub API, meta endpoint

func DownloadZoneFiles

func DownloadZoneFiles(countryZones []string) (err error)

DownloadZoneFiles fetches the CIDR zones files from ipverse.net

It uses concurrent connections to speed up the download

func ExclName

func ExclName() (exclName string)

exclName is a shorthand to get the exclusions file name

func FileExists

func FileExists(file string) (fi fs.FileInfo, err error)

FileExists checks if a file exists and returns fileinfo

func InclName

func InclName() (inclName string)

inclName is a shorthand to get the inclusions file name

func IsTerminal

func IsTerminal() bool

IsTerminal checks if run in interactive shell

func MakeCountryUnblockArray

func MakeCountryUnblockArray(continents *Continents) (unblockedZones []string)

MakeCountryUnblockArray condenses all the "Unblocked" from the Continents struct into a single array for easy iteration

func MakeCountryZoneArray

func MakeCountryZoneArray(continents *Continents) (countryZones []string)

MakeCountryZoneArray condenses all the "Zones" from the Continents struct into a single array for easy iteration

func MakeDestination

func MakeDestination(path string)

MakeDestination creates directory if it doesn't exist

func RootDir

func RootDir() (dir string)

RootDir returns the application root directory

func UnmarshallAllowedZones

func UnmarshallAllowedZones(allowedZones **Allowedzones) (err error)

unmarshallAllowedZones reads the info from provided json file and fills struct with the needed info.

func UnmarshallBlockedZones

func UnmarshallBlockedZones(blockedZones **Blockedzones) (err error)

unmarshallBlockedZones reads the info from provided json file and fills struct with the needed info.

func UnmarshallCountries

func UnmarshallCountries(continents **Continents) (err error)

unmarshallCountries reads the info from provided json file and fills struct with the needed info.

Types

type Allowedzones

type Allowedzones struct {
	CIDR []string `json:"allowed"`
}

Allowedzones contains zones that should be explicitely allowed see exclzones.json file

type Blockedzones

type Blockedzones struct {
	CIDR []string `json:"blocked"`
}

Blockedzones contains zones that should be explicitely blocked see inclzones.json file

type Continents

type Continents struct {
	Afrika       Zones `json:"AFRICA"`
	Asia         Zones `json:"ASIA"`
	Europe       Zones `json:"EUROPE"`
	NorthAmerica Zones `json:"NORTH_AMERICA"`
	SouthAmerica Zones `json:"SOUTH_AMERICA"`
	Oceania      Zones `json:"OCEANIA"`
	Antartica    Zones `json:"ANTARTICA"`
}

Continents contains the ISO-3166-1 style country codes extracted from .uca-exclcountries.json divided by continent

type GH_ssh_fp

type GH_ssh_fp struct {
	RSA     string `json:"SHA256_RSA"`
	ECDSA   string `json:"SHA256_ECDSA"`
	ED25519 string `json:"SHA256_ED25519"`
}

GH_ssh_fp contains the ssh fingerprint from GitHub meta endpoint

type GitHub

type GitHub struct {
	VPA        bool      `json:"verifiable_password_authentication"`
	SSH_fp     GH_ssh_fp `json:"ssh_key_fingerprints"`
	Hooks      []string  `json:"hooks"`
	Web        []string  `json:"web"`
	API        []string  `json:"api"`
	Git        []string  `json:"git"`
	Packages   []string  `json:"packages"`
	Pages      []string  `json:"pages"`
	Importer   []string  `json:"importer"`
	Actions    []string  `json:"actions"`
	Dependabot []string  `json:"dependabot"`
}

GitHub is the base struct containing the data fetched from https://api.github.com/meta

type Zones

type Zones struct {
	Zones     []string `json:"zones"`
	Unblocked []string `json:"unblocked"`
}

Zones contains for each continent (referenced in Contintents) the available zone files (Zones) and the allowed zones (Unblocked)

Jump to

Keyboard shortcuts

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