diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..68908e3 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,82 @@ +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- + +FROM golang:1 + +# Avoid warnings by switching to noninteractive +ENV DEBIAN_FRONTEND=noninteractive + +# This Dockerfile adds a non-root user with sudo access. Use the "remoteUser" +# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs +# will be updated to match your local UID/GID (when using the dockerFile property). +# See https://aka.ms/vscode-remote/containers/non-root-user for details. +ARG USERNAME=vscode +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +# Configure apt, install packages and tools +RUN apt-get update \ + && apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \ + # + # Verify git, process tools, lsb-release (common in install instructions for CLIs) installed + && apt-get -y install git openssh-client less iproute2 procps lsb-release \ + # + # Install Go tools w/module support + && mkdir -p /tmp/gotools \ + && cd /tmp/gotools \ + && GO111MODULE=on go get -v golang.org/x/tools/gopls@latest 2>&1 \ + && GO111MODULE=on go get -v \ + honnef.co/go/tools/...@latest \ + golang.org/x/tools/cmd/gorename@latest \ + golang.org/x/tools/cmd/goimports@latest \ + golang.org/x/tools/cmd/guru@latest \ + golang.org/x/lint/golint@latest \ + github.com/mdempsky/gocode@latest \ + github.com/cweill/gotests/...@latest \ + github.com/haya14busa/goplay/cmd/goplay@latest \ + github.com/sqs/goreturns@latest \ + github.com/josharian/impl@latest \ + github.com/davidrjenni/reftools/cmd/fillstruct@latest \ + github.com/uudashr/gopkgs/v2/cmd/gopkgs@latest \ + github.com/ramya-rao-a/go-outline@latest \ + github.com/acroca/go-symbols@latest \ + github.com/godoctor/godoctor@latest \ + github.com/rogpeppe/godef@latest \ + github.com/zmb3/gogetdoc@latest \ + github.com/fatih/gomodifytags@latest \ + github.com/mgechev/revive@latest \ + github.com/go-delve/delve/cmd/dlv@latest 2>&1 \ + # + # Install Go tools w/o module support + && go get -v github.com/alecthomas/gometalinter 2>&1 \ + # + # Install gocode-gomod + && go get -x -d github.com/stamblerre/gocode 2>&1 \ + && go build -o gocode-gomod github.com/stamblerre/gocode \ + && mv gocode-gomod $GOPATH/bin/ \ + # + # Install golangci-lint + && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin 2>&1 \ + # + # Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user. + && groupadd --gid $USER_GID $USERNAME \ + && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \ + # [Optional] Add sudo support + && apt-get install -y sudo \ + && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ + && chmod 0440 /etc/sudoers.d/$USERNAME \ + # Add write permission for /go/pkg + && chmod -R a+w /go/pkg \ + # + # Clean up + && apt-get autoremove -y \ + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* /go/src /tmp/gotools + +# Update this to "on" or "off" as appropriate +ENV GO111MODULE=auto + +# Switch back to dialog for any ad-hoc use of apt-get +ENV DEBIAN_FRONTEND=dialog diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..ce463bf --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,27 @@ +// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.106.0/containers/go +{ + "name": "Go", + "dockerFile": "Dockerfile", + "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], + + // Set *default* container specific settings.json values on container create. + "settings": { + "terminal.integrated.shell.linux": "/bin/bash", + "go.gopath": "/go" + }, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-vscode.go" + ] + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "go version", + + // Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root. + // "remoteUser": "vscode" +} \ No newline at end of file diff --git a/api.go b/api.go index 51b27d3..f314430 100644 --- a/api.go +++ b/api.go @@ -573,12 +573,12 @@ func (sc *Client) ListCustomAlerts(corpName, siteName string) ([]CustomAlert, er // CustomAlertBody is the body for creating a custom alert. type CustomAlertBody struct { - TagName string `json:"tagName"` - LongName string `json:"longName"` - Interval int `json:"interval"` - Threshold int `json:"threshold"` - Enabled bool `json:"enabled"` - Action string `json:"action"` + TagName string `hcl:"tag_name" json:"tagName"` + LongName string `hcl:"long_name" json:"longName"` + Interval int `hcl:"interval" json:"interval"` + Threshold int `hcl:"threshold" json:"threshold"` + Enabled bool `hcl:"enabled" json:"enabled"` + Action string `hcl:"action" json:"action"` } // CreateCustomAlert creates a custom alert. @@ -1864,38 +1864,38 @@ func (sc *Client) DeleteSite(corpName, siteName string) error { // Condition contains rule condition type Condition struct { - Type string `json:"type,omitempty"` //(group, single) - GroupOperator string `json:"groupOperator,omitempty"` //type: group - Conditions that must be matched when evaluating the request (all, any) - Field string `json:"field,omitempty"` //type: single - (scheme, method, path, useragent, domain, ip, responseCode, agentname, paramname, paramvalue, country, name, valueString, valueIp, signalType) - Operator string `json:"operator,omitempty"` //type: single - (equals, doesNotEqual, contains, doesNotContain, like, notLike, exists, doesNotExist, inList, notInList) - Value string `json:"value,omitempty"` //type: single - See request fields (https://docs.signalsciences.net/using-signal-sciences/features/rules/#request-fields) - Conditions []Condition `json:"conditions,omitempty"` + Type string `hcl:"type" json:"type,omitempty"` //(group, single) + GroupOperator string `hcl:"group_operator" json:"groupOperator,omitempty"` //type: group - Conditions that must be matched when evaluating the request (all, any) + Field string `hcl:"field" json:"field,omitempty"` //type: single - (scheme, method, path, useragent, domain, ip, responseCode, agentname, paramname, paramvalue, country, name, valueString, valueIp, signalType) + Operator string `hcl:"operator" json:"operator,omitempty"` //type: single - (equals, doesNotEqual, contains, doesNotContain, like, notLike, exists, doesNotExist, inList, notInList) + Value string `hcl:"value" json:"value,omitempty"` //type: single - See request fields (https://docs.signalsciences.net/using-signal-sciences/features/rules/#request-fields) + Conditions []Condition `hcl:"conditions,block" json:"conditions,omitempty"` } // Action contains the rule action type Action struct { - Type string `json:"type,omitempty"` //(block, allow, exclude) - Signal string `json:"signal,omitempty"` + Type string `hcl:"type" json:"type,omitempty"` //(block, allow, exclude) + Signal string `hcl:"signal" json:"signal,omitempty"` } // RateLimit holds all the data that is specific to rate limit rules type RateLimit struct { - Threshold int `json:"threshold"` - Interval int `json:"interval"` // interval in minutes, 1 or 10 - Duration int `json:"duration"` // duration in seconds + Threshold int `hcl:"threshold" json:"threshold"` + Interval int `hcl:"interval" json:"interval"` // interval in minutes, 1 or 10 + Duration int `hcl:"duration" json:"duration"` // duration in seconds } //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) - 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 - Expiration string `json:"expiration,omitempty"` //Date the rule will automatically be disabled. If rule is always enabled, will return empty string - Conditions []Condition `json:"conditions,omitempty"` - Actions []Action `json:"actions,omitempty"` - RateLimit *RateLimit `json:"rateLimit,omitempty"` //Null unless type==rateLimit + Type string `hcl:"type" json:"type,omitempty,omitempty"` //(signal, request, rateLimit) + GroupOperator string `hcl:"group_operator" json:"groupOperator,omitempty"` //type: group - Conditions that must be matched when evaluating the request (all, any) + Enabled bool `hcl:"enabled" json:"enabled,omitempty"` + Reason string `hcl:"reason" json:"reason,omitempty"` //Description of the rule + Signal string `hcl:"signal" json:"signal,omitempty"` //The signal id of the signal being excluded. Null unless type==request + Expiration string `hcl:"expiration" json:"expiration,omitempty"` //Date the rule will automatically be disabled. If rule is always enabled, will return empty string + Conditions []Condition `hcl:"conditions,block" json:"conditions,omitempty"` + Actions []Action `hcl:"actions,block" json:"actions,omitempty"` + RateLimit *RateLimit `hcl:"rate_limit,block" json:"rateLimit,omitempty"` //Null unless type==rateLimit } // ResponseSiteRuleBody contains the response from creating the rule @@ -1985,10 +1985,10 @@ func (sc *Client) GetAllSiteRules(corpName, siteName string) (ResponseSiteRuleBo // CreateListBody Create List Request type CreateListBody struct { - Name string `json:"name,omitempty"` //Descriptive list name - Type string `json:"type,omitempty"` //List types (string, ip, country, wildcard, signal) - Description string `json:"description,omitempty"` //Optional list description - Entries []string `json:"entries,omitempty"` //List entries + Name string `hcl:"name" json:"name,omitempty"` //Descriptive list name + Type string `hcl:"type" json:"type,omitempty"` //List types (string, ip, country, wildcard, signal) + Description string `hcl:"description" json:"description,omitempty"` //Optional list description + Entries []string `hcl:"entries" json:"entries,omitempty"` //List entries } // UpdateListBody update list @@ -2087,8 +2087,8 @@ func (sc *Client) GetAllSiteLists(corpName, siteName string) (ResponseListBodyLi // CreateSiteRedactionBody Create redaction Request type CreateSiteRedactionBody struct { - Field string `json:"field,omitempty"` //Field name - RedactionType int `json:"redactionType"` //Type of redaction (0: Request Parameter, 1: Request Header, 2: Response Header) + Field string `hcl:"field" json:"field,omitempty"` //Field name + RedactionType int `hcl:"redaction_type" json:"redactionType"` //Type of redaction (0: Request Parameter, 1: Request Header, 2: Response Header) } //UpdateSiteRedactionBody update site redaction @@ -2196,16 +2196,16 @@ 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) - 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 - Reason string `json:"reason,omitempty"` //Description of the rule - Expiration string `json:"expiration,omitempty"` //Date the rule will automatically be disabled. If rule is always enabled, will return empty string - Conditions []Condition `json:"conditions,omitempty"` - Actions []Action `json:"actions,omitempty"` + SiteNames []string `hcl:"site_short_names" json:"siteNames,omitempty"` //Sites with the rule available. Rules with a global corpScope will return '[]'. + Type string `hcl:"type" json:"type,omitempty,omitempty"` //(request, signal) + CorpScope string `hcl:"corp_scope" json:"corpScope,omitempty"` //Whether the rule is applied to all sites or to specific sites. (global, specificSites) + Enabled bool `hcl:"enabled" json:"enabled,omitempty"` + GroupOperator string `hcl:"group_operator" json:"groupOperator,omitempty"` //type: group - Conditions that must be matched when evaluating the request (all, any) + Signal string `hcl:"signal" json:"signal,omitempty"` //The signal id of the signal being excluded + Reason string `hcl:"reason" json:"reason,omitempty"` //Description of the rule + Expiration string `hcl:"expiration" json:"expiration,omitempty"` //Date the rule will automatically be disabled. If rule is always enabled, will return empty string + Conditions []Condition `hcl:"conditions,block" json:"conditions,omitempty"` + Actions []Action `hcl:"actions,block" json:"actions,omitempty"` } // ResponseCorpRuleBody contains the response from creating the rule @@ -2350,8 +2350,8 @@ func (sc *Client) DeleteCorpListByID(corpName string, id string) error { //CreateSignalTagBody create a signal tag type CreateSignalTagBody struct { - ShortName string `json:"shortName,omitempty"` //The display name of the signal tag - Description string `json:"description,omitempty"` //Optional signal tag description + ShortName string `hcl:"short_name" json:"shortName,omitempty"` //The display name of the signal tag + Description string `hcl:"description" json:"description,omitempty"` //Optional signal tag description } //UpdateSignalTagBody update a signal tag diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..a80206a --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=