Categorygithub.com/wallarm/wallarm-go
modulepackage
0.5.2
Repository: https://github.com/wallarm/wallarm-go.git
Documentation: pkg.go.dev

# README

wallarm-go

build PkgGoDev codecov Go Report Card License: MIT

Table of Contents

Note: This library is in active development and highly suggested to use carefully.

A Go library for interacting with Wallarm API. This library allows you to:

  • Manage applications
  • Manage nodes
  • Manage integrations
  • Manage triggers
  • Manage users
  • Manage the denylist
  • Switch the WAF/Scanner/Active Threat Verification modes
  • Inquire found vulnerabilities

Install

You need a working Go environment

go get github.com/wallarm/wallarm-go

Getting Started

The sample code could be similar

package main

import (
	"log"
	"net/http"
	"os"

	wallarm "github.com/wallarm/wallarm-go"
)

func main() {

	wapiHost, exist := os.LookupEnv("WALLARM_API_HOST")
	if !exist {
		wapiHost = "https://api.wallarm.com"
	}
	wapiToken, exist := os.LookupEnv("WALLARM_API_TOKEN")
	if !exist {
		log.Fatal("ENV variable WALLARM_API_TOKEN is not present")
	}

	authHeaders := make(http.Header)
	authHeaders.Add("X-WallarmAPI-Token", wapiToken)

	// Construct a new API object
	api, err := wallarm.New(wallarm.UsingBaseURL(wapiHost), wallarm.Headers(authHeaders))
	if err != nil {
		log.Print(err)
	}

	// Fetch user details
	u, err := api.UserDetails()
	if err != nil {
		log.Print(err)
	}
	// Print user specific data
	log.Println(u.Body)

	// Change global Wallarm mode to monitoring
	clientID := 1
	modeParams := wallarm.WallarmMode{Mode: "monitoring"}

	mode, err := api.WallarmModeUpdate(&modeParams, clientID)
	if err != nil {
		log.Print(err)
	}
	// Print Wallarm mode
	log.Println(mode)

	// Create a trigger when the number of attacks more than 1000 in 10 minutes
	filter := wallarm.TriggerFilters{
		ID:       "ip_address",
		Operator: "eq",
		Values:   []interface{}{"2.2.2.2"},
	}

	var filters []wallarm.TriggerFilters
	filters = append(filters, filter)

	action := wallarm.TriggerActions{
		ID: "send_notification",
		Params: wallarm.TriggerActionParams{
			IntegrationIds: []int{5},
		},
	}

	var actions []wallarm.TriggerActions
	actions = append(actions, action)

	triggerBody := wallarm.TriggerCreate{
		Trigger: &wallarm.TriggerParam{
			Name:       "New Terraform Trigger Telegram",
			Comment:    "This is a description set by Terraform",
			TemplateID: "attacks_exceeded",
			Enabled:    true,
			Filters:    &filters,
			Actions:    &actions,
		},
	}

	triggerResp, err := api.TriggerCreate(&triggerBody, 1)
	if err != nil {
		log.Print(err)
	}
	// Print trigger metadata
	log.Println(triggerResp)
}

License

MIT licensed

# Functions

Contains wraps methods (for string and int) to check if List contains the element.
Headers allows you to set custom HTTP headers when making API calls (e.g.
HTTPClient accepts a custom *http.Client for making API calls.
New creates a new Wallarm API client.
UserAgent allows to set custome User-Agent header.
UsingBaseURL allows to set the Wallarm API endpoint.
UsingLogger can be set if you want to get log output from this API instance By default no log output is emitted.
UsingRetryPolicy applies a non-default number of retries and min/max retry delays This will be used when the client exponentially backs off after errored requests.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
Version is the client version.

# Variables

ErrExistingResource is returned when resource was created other than Terrafom ways - directly via the API.
ErrInvalidCredentials is raised when not all the credentials are presented.
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
RetryPolicy specifies number of retries and min/max retry delays This config is used when the client exponentially backs off after errored requests.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Logger defines the interface this library needs to use logging This is a subset of the methods implemented in the log package.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
Option is a functional option for configuring the API client.
No description provided by the author