diff --git a/cmd/workspace_show/main.go b/cmd/workspace_show/main.go new file mode 100644 index 000000000..6f4f7568f --- /dev/null +++ b/cmd/workspace_show/main.go @@ -0,0 +1,62 @@ +package main + +import ( + "context" + "flag" + "fmt" + "io/ioutil" + "os" + + "github.com/davecgh/go-spew/spew" + "github.com/hashicorp/go-tfe" +) + +var ( + token, + baseAddress string +) + +func init() { + const defaultAddress = "https://staging-app.terraform.io" + flag.StringVar(&baseAddress, "base_address", defaultAddress, "tf env base address.") + flag.StringVar(&token, "token", "", "tf token.") +} + +func main() { + flag.Parse() + if len(flag.Args()) != 2 { + fmt.Fprint(os.Stderr, + "usage: workspace_show \nflags:\n", + ) + flag.PrintDefaults() + os.Exit(1) + } + + cfg := &tfe.Config{ + Address: baseAddress, + Token: token, + } + client, err := tfe.NewClient(cfg) + if err != nil { + panic(err) + } + + ws, err := client.Workspaces.Read(context.Background(), flag.Arg(0), flag.Arg(1)) + if err != nil { + panic(err) + } + + spew.Dump(ws) + + readme, err := client.Workspaces.Readme(context.Background(), ws.ID) + if err != nil { + panic(err) + } + + rms, err := ioutil.ReadAll(readme) + if err != nil { + panic(err) + } + + spew.Dump(rms) +} diff --git a/workspace.go b/workspace.go index 24f50e29b..6b60522fb 100644 --- a/workspace.go +++ b/workspace.go @@ -80,8 +80,8 @@ type WorkspaceList struct { // WorkspaceReadme contains the readme of the workspace. type WorkspaceReadme struct { - ID string `jsonapi:"primary,workspace-readme"` - Readme string `jsonapi:"attr,raw-markdown"` + ID string `jsonapi:"primary,workspace-readme"` + RawMarkdown string `jsonapi:"attr,raw-markdown"` } // Workspace represents a Terraform Enterprise workspace. @@ -391,7 +391,7 @@ func (s *workspaces) Readme(ctx context.Context, workspaceID string) (io.Reader, return nil, err } - return strings.NewReader(r.Readme.Readme), nil + return strings.NewReader(r.Readme.RawMarkdown), nil } // WorkspaceUpdateOptions represents the options for updating a workspace.