diag

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package diag implements functions to diagnose a Google Ads client environment.

Index

Constants

View Source
const (
	// DevToken is an abbreviation for developer token.
	// https://developers.google.com/google-ads/api/docs/first-call/dev-token
	DevToken = "DevToken"
	// ClientID is the OAuth client ID.
	ClientID = "ClientID"
	// ClientSecret is the secret provided from the Google API Console.
	// https://developers.google.com/google-ads/api/docs/oauth/cloud-project#create_a_client_id_and_client_secret/
	ClientSecret = "ClientSecret"
	// RefreshToken allows the client to obtain a new access token.
	RefreshToken = "RefreshToken"
	// PrivateKeyPath is the filepath of a private key file for service account
	PrivateKeyPath = "PrivateKeyPath"
	// DelegatedAccount is the email to impersonate
	DelegatedAccount = "DelegatedAccount"

	// ProjectID is the Google Cloud console project ID.
	ProjectID = "ProjectID"
	// PrivateKeyID is the private key ID that represents the identity of your service account.
	PrivateKeyID = "PrivateKeyID"
	// PrivateKey is the encrypted private key that represents your identity of your service account.
	PrivateKey = "PrivateKey"
	// ClientEmail is the service account email.
	ClientEmail = "ClientEmail"
	// ClientX509CertURL is the URL for x509 certificate.
	ClientX509CertURL = "ClientX509CertURL"

	// InstalledApp is the installed app type option for Google Ads API.
	// Read https://developers.google.com/google-ads/api/docs/oauth/cloud-project#choose_an_application_type.
	InstalledApp = "installed_app"
	// Web is the web app type option for Google Ads API.
	// Read https://developers.google.com/google-ads/api/docs/oauth/cloud-project#choose_an_application_type.
	Web = "web"
	// ServiceAccount allows server-to-server interactions between a web application and a Google service.
	ServiceAccount = "service_account"
)
View Source
const (
	// ENDPOINT is the googleapis host.
	ENDPOINT = "googleads.googleapis.com.:80"
)

Variables

View Source
var (
	// PIIWords is a slice of constant strings that indicate Personally Identifiable Information
	PIIWords = []string{DevToken, ClientID, ClientSecret, RefreshToken, ProjectID, PrivateKeyID,
		PrivateKey, ClientEmail, ClientX509CertURL}

	// RequiredKeys are the key names used in the Language structure that defines
	// the contents of a client library configuration file.
	RequiredKeys = map[string][]string{
		InstalledApp:   {DevToken, ClientID, ClientSecret, RefreshToken},
		Web:            {DevToken, ClientID, ClientSecret},
		ServiceAccount: {DevToken, PrivateKeyPath, DelegatedAccount},
	}
)
View Source
var Languages = map[string]Config{
	"java": {
		Comment: Comment{
			LeftMeta: "#",
		},
		Separator: "=",
		Cfg: ConfigFile{
			Filename: "ads.properties",
			ConfigKeys: ConfigKeys{
				ClientID:         "api.googleads.clientId",
				ClientSecret:     "api.googleads.clientSecret",
				DevToken:         "api.googleads.developerToken",
				RefreshToken:     "api.googleads.refreshToken",
				LoginCustomerID:  "api.googleads.loginCustomerId",
				PrivateKeyPath:   "api.googleads.jsonKeyFilePath",
				DelegatedAccount: "api.googleads.serviceAccountUser",
			}}},
	"dotnet": {
		Comment: Comment{
			LeftMeta:  "<!--",
			RightMeta: "-->",
		},
		Cfg: ConfigFile{
			Filename: "App.Config",
			ConfigKeys: ConfigKeys{
				ClientID:         "OAuth2ClientId",
				ClientSecret:     "OAuth2ClientSecret",
				DevToken:         "DeveloperToken",
				RefreshToken:     "OAuth2RefreshToken",
				LoginCustomerID:  "LoginCustomerId",
				PrivateKeyPath:   "OAuth2SecretsJsonPath",
				DelegatedAccount: "OAuth2PrnEmail",
			}}},
	"php": {
		Comment: Comment{
			LeftMeta: ";",
		},
		Separator: "=",
		Cfg: ConfigFile{
			Filename: "google_ads_php.ini",
			ConfigKeys: ConfigKeys{
				ClientID:         "clientId",
				ClientSecret:     "clientSecret",
				DevToken:         "developerToken",
				RefreshToken:     "refreshToken",
				LoginCustomerID:  "loginCustomerId",
				PrivateKeyPath:   "jsonKeyFilePath",
				DelegatedAccount: "impersonatedEmail",
			}}},
	"python": {
		Comment: Comment{
			LeftMeta: "#",
		},
		Separator: ":",
		Cfg: ConfigFile{
			Filename: "google-ads.yaml",
			ConfigKeys: ConfigKeys{
				ClientID:         "client_id",
				ClientSecret:     "client_secret",
				DevToken:         "developer_token",
				RefreshToken:     "refresh_token",
				LoginCustomerID:  "login_customer_id",
				PrivateKeyPath:   "path_to_private_key_file",
				DelegatedAccount: "delegated_account",
			}}},
	"ruby": {
		Comment: Comment{
			LeftMeta: "#",
		},
		Separator: "=",
		Cfg: ConfigFile{
			Filename: "google_ads_config.rb",
			ConfigKeys: ConfigKeys{
				ClientID:         "c.client_id",
				ClientSecret:     "c.client_secret",
				DevToken:         "c.developer_token",
				RefreshToken:     "c.refresh_token",
				LoginCustomerID:  "c.login_customer_id",
				PrivateKeyPath:   "c.keyfile",
				DelegatedAccount: "c.impersonate",
			},
		},
	},
}

Languages defines the idiomatic features of each language in a Google Ads API configuration file.

Functions

func ConnEndpoint

func ConnEndpoint() error

ConnEndpoint opens a tcp connection to the endpoint

func Contains

func Contains(s []string, str string) bool

Contains tests if a string exists in a slice of strings.

func IsPII

func IsPII(s string) bool

IsPII returns true when the given string is PII (peronsal identifiable information), else false.

func ListLanguages

func ListLanguages() []string

ListLanguages returns a slice of supported languages.

func MinGoVersion

func MinGoVersion() error

MinGoVersion tests for the minimum version of Go required. The current minimum version supported is 1.11.

func PrintIPv4

func PrintIPv4(host string)

PrintIPv4 prints local non-loopback IPv4 addresses

Types

type Comment

type Comment struct {
	LeftMeta  string
	RightMeta string
}

Comment represents comment characters. If a comment is a line comment, RightMeta will be an empty string.

type Config

type Config struct {
	Comment
	Separator string
	Cfg       ConfigFile
}

Config is the collection of language specific elements.

type ConfigFile

type ConfigFile struct {
	Filename  string
	Filepath  string
	Lang      string
	OAuthType string
	ConfigKeys
	ServiceAccountInfo
}

ConfigFile is the structure of a client configuration file.

func GetConfigFile

func GetConfigFile(lang, overridePath string) ConfigFile

GetConfigFile returns a ConfigFile containing config filepath and filename. When overridePath is an empty string, the function will retrieve the filepath and filename from the default location in the file system.

func GetDefaultConfigFile

func GetDefaultConfigFile(lang string) ConfigFile

GetDefaultConfigFile returns the default config path of Google Ads API client library.

func ParseKeyValueFile

func ParseKeyValueFile(lang, filepath, oauthType string) (c ConfigFile, err error)

ParseKeyValueFile reads a configuration file with keys and values separated by a language specific separator, and returns a ConfigFile.

func ParseXMLFile

func ParseXMLFile(filepath, oauthType string) (c ConfigFile, err error)

ParseXMLFile parses the file content given in filepath and returns a ConfigFile struct with the given attributes in the file.

func (*ConfigFile) GetConfigKeysInLang

func (c *ConfigFile) GetConfigKeysInLang(key string) string

GetConfigKeysInLang returns the key name in the configuration file based on the given language. For example, "client_id" is returned with "ClientID" for Python.

func (*ConfigFile) GetFilepath added in v1.0.4

func (c *ConfigFile) GetFilepath() string

func (*ConfigFile) Print

func (c *ConfigFile) Print(hidePII bool)

Print prints out the keys and values in ConfigFile.ConfigKeys.

func (*ConfigFile) ReplaceConfig

func (c *ConfigFile) ReplaceConfig(key, value string) string

ReplaceConfig replaces a value in ConfigFile.ConfigKeys and its configuration file.

func (*ConfigFile) ReplaceConfigFromReader

func (c *ConfigFile) ReplaceConfigFromReader(key, value string, r io.Reader) string

ReplaceConfigFromReader reads configuration file content from io.Reader according to a specific language config file syntax. It inserts the new key-value pair and comments out the existing one if found.

func (*ConfigFile) SetConfigKeys

func (c *ConfigFile) SetConfigKeys(k, v string)

SetConfigKeys updates the value of the given key in ConfigFile.ConfigKeys.

func (*ConfigFile) UpdateConfigKeys

func (c *ConfigFile) UpdateConfigKeys(keyValue map[string]string)

UpdateConfigKeys updates attributes in ConfigFile.ConfigKeys from keyValue map. The keys in keyValue must match the names in ConfigFile.ConfigKeys, else they will be ignored.

func (*ConfigFile) Validate

func (c *ConfigFile) Validate() (bool, error)

Validate returns true when all the values in ConfigFile.ConfigKeys meet the requirements. When it returns false, the returned error includes each reason why the attribute fails validation.

type ConfigKeys

type ConfigKeys struct {
	ClientID         string
	ClientSecret     string
	DevToken         string
	RefreshToken     string
	LoginCustomerID  string
	PrivateKeyPath   string
	DelegatedAccount string
}

ConfigKeys are the keys in a client configuration file.

type ServiceAccountInfo added in v1.0.4

type ServiceAccountInfo struct {
	Type                    string
	ProjectID               string `json:"project_id"`
	PrivateKeyID            string `json:"private_key_id"`
	PrivateKey              string `json:"private_key"`
	ClientEmail             string `json:"client_email"`
	ClientID                string `json:"client_id"`
	AuthURI                 string `json:"auth_uri"`
	TokenURI                string `json:"token_uri"`
	AuthProviderX509CertURL string `json:"auth_provider_x509_cert_url"`
	ClientX509CertURL       string `json:"client_x509_cert_url"`
}

type SysInfo

type SysInfo struct {
	Host     string
	CPUs     int
	OS       string
	Arch     string
	GOROOT   string
	PageSize int
	Heap     uint64
}

SysInfo stores the relevant system information.

func (*SysInfo) Init

func (s *SysInfo) Init()

Init intializes the struct with the runtime system parameters.

func (*SysInfo) Print

func (s *SysInfo) Print()

Print outputs the contents of a Sysinfo structure to stdout.

Jump to

Keyboard shortcuts

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