Skip to content

Commit

Permalink
rename field
Browse files Browse the repository at this point in the history
  • Loading branch information
mwhooker committed Mar 19, 2021
1 parent 6843f47 commit f70a92f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
62 changes: 62 additions & 0 deletions cmd/workspace_show/main.go
Original file line number Diff line number Diff line change
@@ -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 <flags> <organization> <workspace>\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)
}
6 changes: 3 additions & 3 deletions workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit f70a92f

Please sign in to comment.