Giter VIP home page Giter VIP logo

go-sigsci's People

Contributors

andy-fastly avatar ben-sigsci avatar brookscunningham avatar clifton-sigsci avatar daniel-corbett avatar dkegel-fastly avatar grokify avatar jbhanrahan avatar jeremy-cxf avatar jhanrahan-sigsci avatar leaf-fastly avatar lsmith500 avatar mattg-sigsci avatar moserke avatar ponkio-o avatar ricoberger avatar shawnps avatar shawnps-sigsci avatar vvuksan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-sigsci's Issues

New release

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!

clientIPRules missing from site config

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}

[NITS]: seems to be a duplicate.

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 %

JSON tags added to types

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"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.