添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have a linting utility called config-lint: https://github.com/stelligent/config-lint which I downloaded for windows.

I downloaded it and added it to the path and able to run it as seen below

E:\>config-lint -terraform config-lint-master\example-files\config [   {
    "AssertionMessage": "None expression fails: ",
    "Category": "resource",
    "CreatedAt": "2020-10-02T10:23:19Z",
    "Filename": "config-lint-master\\example-files\\config\\s3.tf",
    "LineNumber": 43,
    "ResourceID": "bucket_with_not",
    "ResourceType": "aws_s3_bucket_policy",
    "RuleID": "S3_NOT_ACTION",
    "RuleMessage": "Should not use NotAction in S3 bucket policy",
    "Status": "WARNING"   },   {
    "AssertionMessage": "Not expression fails",
    "Category": "resource",
    "CreatedAt": "2020-10-02T10:23:19Z",
    "Filename": "config-lint-master\\example-files\\config\\security_group.tf",
    "LineNumber": 1,
    "ResourceID": "allow_all",
    "ResourceType": "aws_security_group",
    "RuleID": "SG_INGRESS_ALL_PROTOCOLS",
    "RuleMessage": "Best practices recommend not opening all protocols and ports to ingress traffic",
    "Status": "WARNING"   },

--- more output to follow

I wish to achieve the same via the exec package in go Lang. Below is my code

 args := []string{"-terraform", "E:\\config-lint-master\\example-files\\config"}
    app := "config-lint"
    cmd := exec.Command(app, args...)
    //cmd := exec.Command("config-lint", "-terraform", "E:\\config-lint-master\\example-files\\config")
    cmd.Stdout = &bytes.Buffer{}
    cmdOp := &bytes.Buffer{}
    cmd.Stdout = cmdOp
    err := cmd.Run()
    if err != nil {
        fmt.Println("Error->", err)
    } else {
        fmt.Println(cmdOp)

On executing this, I get the error as

Error-> exit status 4294967295

I have no idea what this means, I'm new to Go Lang.

Note: When I run it using the below by passing a file name at the end, it then executes. It doesn't seem to be working when a directory is passed.

 args := []string{"-terraform", "E:\\config-lint-master\\example-files\\config\\elb.tf"}

config-lint can be run as below

config-lint -terraform <FILE_OR_DIRECTORY_OF_TF_FILES>

Ref: https://stelligent.github.io/config-lint/#/terraform

Go Lang Version: go version go1.14.6 windows/amd64

OS: Win 10 Home, Build:19041.450

4294967295 is the unsigned interpretation of -1, a common value used by console applications to signal that something went wrong. It looks like your Go code promised to pass a config file but never actually passes a config file. "Something went wrong" is the expected answer. – IInspectable Oct 2, 2020 at 12:13

The issue is that for some reason, that command fails even in shell setting. So what I did was, ignore the error unless the output is empty:

package main
import (
   "fmt"
   "log"
   "os/exec"
func main() {
   o := exec.Command(
      "config-lint", "-terraform", "config-lint-master/example-files/config",
   y, e := o.Output()
   if len(y) == 0 {
      log.Fatal(e)
   fmt.Printf("%s", y)

or you can just output directly to console:

package main
import (
   "os/exec"
func main() {
   o := exec.Command(
      "config-lint", "-terraform", "config-lint-master/example-files/config",
   o.Stdout = os.Stdout
   o.Run()
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.