Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding hcl tags so a terraform config can be generated #10

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

janitha09
Copy link

@janitha09 janitha09 commented Oct 13, 2020

package marshal

import (
	"fmt"

	"github.com/hashicorp/hcl2/gohcl"
	"github.com/hashicorp/hcl2/hclwrite"
	"github.com/signalsciences/go-sigsci"
)

type localCreateSignalTagBody sigsci.CreateSignalTagBody

func (l localCreateSignalTagBody) marshalSiteText(localName, site string) string {
	str := fmt.Sprintf(`resource %s "%s" {
	site_short_name = "%s"
`, l.TFSiteResourceName(), localName, site)
	f := hclwrite.NewEmptyFile()
	gohcl.EncodeIntoBody(&l, f.Body())
	str += string(f.Bytes())

	str += "}\n"
	return str
}```

a test for it looks like this
```go
func TestTextMarshalSiteSignalTag(t *testing.T) {
	createSignalTagBody := localCreateSignalTagBody{
		ShortName:   "Example Signal Tag 1",
		Description: "An example of a custom signal tag",
	}

	got := createSignalTagBody.marshalSiteText("test", "splunk-test")
	expected := "resource sigsci_site_signal_tag \"test\" {\n\tsite_short_name = \"splunk-test\"\nshort_name  = \"Example Signal Tag 1\"\ndescription = \"An example of a custom signal tag\"\n}\n"
	assert.Equal(t, expected, got)
}```

Added functions to create and delete sites
not committing the test files yet
Adds create and delete methods for Site Rules
Add GetSiteByRuleId to the api
add api_test
Readactions returns all redactions I assume that the list is ordered and the last one is taken to be the one that was created. A test checks for this
Test for alerts and lists also added.
gitignore adds settings and launch file
api corp rules and lists. using the same List structure for corps and site. Did not combine the corp rules and site rules structures sitenames and corpscope are additions to it. To some extent influenced by the existing code that doesn't combine and update and create nor the response.
…ng and method naming convention

adds site and corp signals
remove redundant type
fix spelling error ResponseSingal
GetAllCustomSiteAlerts to GetAllSiteCustomAlerts
Add Tests
check the response for signal shortname and lists to conversion lowercase and hyphenated no special characters
This allows you to generate terraform HCL using a snippet like this
```go
func (l localCreateSiteRuleBody) marshalText(localName, site, dependson string) string {
	str := fmt.Sprintf(`resource "sigsci_site_rule" "%s" {
	%s
	site_short_name="%s"
`, localName, dependson, site)
	f := hclwrite.NewEmptyFile()
	gohcl.EncodeIntoBody(&l, f.Body())
	str += string(f.Bytes())
	// str += marshalStructText(l)
	str += "}\n"
	return str
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant