signalsciences / go-sigsci Goto Github PK
View Code? Open in Web Editor NEWGo client library for the Signal Sciences API.
Home Page: https://docs.signalsciences.net/api/
License: MIT License
Go client library for the Signal Sciences API.
Home Page: https://docs.signalsciences.net/api/
License: MIT License
Can you please tag a new release?
We're currently vendoring this library by commit hash to get the latest changes, but we'd like to pull in an actual release tag.
Thanks!
Noticed that I was unable to mange client IP headers through Terraform:
https://docs.fastly.com/signalsciences/install-guides/agent-config/#agentcfg_client-ip-header
To do this, we will need to extend go-sigsci to allow the extension of the site_resource.
Raising for visibility and can implement if i get time.
Sample site payload:
{"agentLevel":"block","agentAnonMode":"EU","clientIPRules":[{"header":"X-Forwarded-For"},{"header":"Fastly-Client-IP"}],"blockHTTPCode":406}
When looking at responses received when hitting the json API directly there appears to be a mismatch to the API and it's documentation at https://docs.fastly.com/signalsciences/api/#_corps__corpName__sites__siteName__feed_requests_get. The "tlsProtocol", "tlsCipher", "scheme", "headersIn", & "headersOut" fields are a part of the API (as well as the console) but are not documented and therefore are likely missed in the SDK.
golangci-lint ( https://golangci-lint.run/ )
makoto@miyazakimakotonoMacBook-Pro go-sigsci % golangci-lint run api.go
api.go:1890:28: SA5008: duplicate JSON option "omitempty" (staticcheck)
Type string `json:"type,omitempty,omitempty"` //(signal, request, rateLimit)
^
api.go:2200:28: SA5008: duplicate JSON option "omitempty" (staticcheck)
Type string `json:"type,omitempty,omitempty"` //(request, signal)
^
makoto@miyazakimakotonoMacBook-Pro go-sigsci %
makoto@miyazakimakotonoMacBook-Pro go-sigsci % git show
commit 86e4108a489f55099da3feb416e8adc39f671b4b (HEAD -> dup/golangci-lint)
Author: gongqi.zhen <[email protected]>
Date: Wed Feb 3 23:44:56 2021 +0900
* golangci-lint : https://golangci-lint.run/
diff --git a/Makefile b/Makefile
index dfc78d3..c233b58 100644
--- a/Makefile
+++ b/Makefile
@@ -4,3 +4,5 @@ lint:
test -z $(gofmt -s -l .)
test:
go test -v
+
+.PHONY: lint test
\ No newline at end of file
diff --git a/api.go b/api.go
index 036776a..80aed89 100644
--- a/api.go
+++ b/api.go
@@ -1887,8 +1887,8 @@ type RateLimit struct {
//CreateSiteRuleBody contains the rule for the site
type CreateSiteRuleBody struct {
- Type string `json:"type,omitempty,omitempty"` //(signal, request, rateLimit)
- GroupOperator string `json:"groupOperator,omitempty"` //type: group - Conditions that must be matched when evaluating the request (all, any)
+ Type string `json:"type,omitempty"` //(signal, request, rateLimit)
+ GroupOperator string `json:"groupOperator,omitempty"` //type: group - Conditions that must be matched when evaluating the request (all, any)
Enabled bool `json:"enabled,omitempty"`
Reason string `json:"reason,omitempty"` //Description of the rule
Signal string `json:"signal,omitempty"` //The signal id of the signal being excluded. Null unless type==request
@@ -2196,9 +2196,9 @@ func (sc *Client) GetAllSiteRedactions(corpName, siteName string) (ResponseSiteR
//CreateCorpRuleBody contains the rule of a Corp
type CreateCorpRuleBody struct {
- SiteNames []string `json:"siteNames,omitempty"` //Sites with the rule available. Rules with a global corpScope will return '[]'.
- Type string `json:"type,omitempty,omitempty"` //(request, signal)
- CorpScope string `json:"corpScope,omitempty"` //Whether the rule is applied to all sites or to specific sites. (global, specificSites)
+ SiteNames []string `json:"siteNames,omitempty"` //Sites with the rule available. Rules with a global corpScope will return '[]'.
+ Type string `json:"type,omitempty"` //(request, signal)
+ CorpScope string `json:"corpScope,omitempty"` //Whether the rule is applied to all sites or to specific sites. (global, specificSites)
Enabled bool `json:"enabled,omitempty"`
GroupOperator string `json:"groupOperator,omitempty"` //type: group - Conditions that must be matched when evaluating the request (all, any)
Signal string `json:"signal,omitempty"` //The signal id of the signal being excluded
makoto@miyazakimakotonoMacBook-Pro go-sigsci %
When consuming the API there are times one might want to marshal the go types. For example when using the go sdk to get the request feed, marshal, then log the marshaled payloads. When doing this however you end up with different marshaled json to a call directly to the API with "accept/json". This is due to the go types not having json tags.
A slimmed down example. The go type:
type Request struct {
ID string
ServerHostname string
RemoteIP string
RemoteHostname string
}
Would generate marshaled json as
{
"ID": "1234567",
"ServerHostname": "host.name",
"RemoteIP": "127.0.0.1",
"RemoteHostname": "private network host"
}
However hitting the API directly would give you a json encoded response of
{
"id": "1234567",
"serverHostname": "host.name",
"remoteIP": "127.0.0.1",
"remoteHostname": "private network host"
}
Tags should be added to the go struct to match the API encoding. Like this
type Request struct {
ID string `json:"id"`
ServerHostname string `json:"serverHostname"`
RemoteIP string `json:"remoteIP"`
RemoteHostname string `json:"remoteHostname"
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.