go-threatmatrix is a client library/SDK that allows developers to easily automate and integrate ThreatMatrix with their own set of tools!
- Go 1.17+
Use go get to retrieve the SDK to add it to your GOPATH workspace, or project's Go module dependencies.
$ go get github.com/khulnasoft/go-threatmatrix
This library was built with ease of use in mind! Here are some quick examples to get you started. If you need more example you can go to the examples directory
To start using the go-threatmatrix library you first need to import it:
import "github.com/khulnasoft/go-threatmatrix/gothreatmatrix"
Construct a new ThreatMatrixClient
, then use the various services to easily access different parts of Threatmatrix's REST API. Here's an example of getting all jobs:
clientOptions := gothreatmatrix.ThreatMatrixClientOptions{
Url: "your-cool-URL-goes-here",
Token: "your-super-secret-token-goes-here",
// This is optional
Certificate: "your-optional-certificate-goes-here",
}
threatmatrix := gothreatmatrix.NewThreatMatrixClient(
&clientOptions,
nil
)
ctx := context.Background()
// returns *[]Jobs or an ThreatMatrixError!
jobs, err := threatmatrix.JobService.List(ctx)
For easy configuration and set up we opted for options
structs. Where we can customize the client API or service endpoint to our liking! For more information go here. Here's a quick example!
// ...Making the client and context!
tagOptions = gothreatmatrix.TagParams{
Label: "NEW TAG",
Color: "#ffb703",
}
createdTag, err := threatmatrix.TagService.Create(ctx, tagOptions)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(createdTag)
}
The examples directory contains a couple for clear examples, of which one is partially listed here as well:
package main
import (
"fmt"
"github.com/khulnasoft/go-threatmatrix/gothreatmatrix"
)
func main(){
threatmatrixOptions := gothreatmatrix.ThreatMatrixClientOptions{
Url: "your-cool-url-goes-here",
Token: "your-super-secret-token-goes-here",
Certificate: "your-optional-certificate-goes-here",
}
client := gothreatmatrix.NewThreatMatrixClient(
&threatmatrixOptions,
nil,
)
ctx := context.Background()
// Get User details!
user, err := client.UserService.Access(ctx)
if err != nil {
fmt.Println("err")
fmt.Println(err)
} else {
fmt.Println("USER Details")
fmt.Println(*user)
}
}
For complete usage of go-threatmatrix, see the full package docs.
If you want to follow the updates, discuss, contribute, or just chat then please join our slack channel we'd love to hear your feedback!
Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE.
You need a valid API key to interact with the ThreatMatrix server.
You can get an API by doing the following:
- Log / Signin into threatmatrix
- At the upper right click on your profile from the drop down select
API Access/ Sessions
- Then generate an API key or see it!
Keys should be created from the admin interface of ThreatMatrix: you have to go in the Durin section (click on Auth tokens
) and generate a key there.