Skip to content

esurdam/go-sophos

Repository files navigation

go-sophos

Documentation Go Report Card codecov go workflow MIT License Mentioned in Awesome Go

A Sophos UTM REST API client for Go with zero dependencies.

Prerequisites

The Sophos UTM REST API must be enabled in Administrator settings.

Familiarity with the Sophos docs.

API types and functions are generated and versioned against UTM's declared Restd version.

Usage

API is stable as of 0.1.0

go get github.com/esurdam/go-sophos

Create a client:

import "github.com/esurdam/go-sophos"

// All Options passed on initialize will be applied to all subsequent calls
client, _ := sophos.New(
    "192.168.0.1:4848", 
    sophos.WithBasicAuth("user", "pass"),
)

Requesting the current port of the WebAdmin (see Nodes for more usage):

import "github.com/esurdam/go-sophos"

client, _ := sophos.New(
    "192.168.0.1:4848", 
    sophos.WithApiToken("abCDEFghIjklMNOPQkwSnwbutCpHdjQz"),
)
res, _ := client.Get("/api/nodes/webadmin.port")

var port int
res.MarshalTo(&port)
fmt.Println(port)
// Output: 4848

Nodes

Nodes are interacted with using pacakage level functions:

import "github.com/esurdam/go-sophos/api/v1.3.0/nodes"

v, err := nodes.GetWebadminPort(client)
fmt.Println(v)
// Output: 4848

err = nodes.UpdateWebadminPort(client, 4444)

Or as struct types with syntactic sugar around the functions, as represented by the Node interface:

import "github.com/esurdam/go-sophos/api/v1.3.0/nodes"

var wap nodes.WebadminPort
err := wap.Get(client)
fmt.Println(wap.Value)
// Output: 4848

wap.Value = 4444
err = wap.Update(client)

You can get the whole UTM node tree as an object as well:

import "github.com/esurdam/go-sophos/api/v1.3.0/objects"