Skip to content

Commit

Permalink
properly handle ms times
Browse files Browse the repository at this point in the history
  • Loading branch information
mwhooker committed Mar 18, 2021
1 parent 0f7d5a6 commit 9d745a0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
44 changes: 44 additions & 0 deletions cmd/workspace_show/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"context"
"flag"
"fmt"
"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)
}

spew.Dump(client.Workspaces.Read(context.Background(), flag.Arg(0), flag.Arg(1)))
}
10 changes: 5 additions & 5 deletions workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ func (s *workspaces) Read(ctx context.Context, organization, workspace string) (
}

// durations come over in ms
w.ApplyDurationAverage *= (time.Second / time.Millisecond)
w.PlanDurationAverage *= (time.Second / time.Millisecond)
w.ApplyDurationAverage *= time.Millisecond
w.PlanDurationAverage *= time.Millisecond

return w, nil
}
Expand Down Expand Up @@ -402,8 +402,8 @@ func (s *workspaces) ReadByID(ctx context.Context, workspaceID string) (*Workspa
}

// durations come over in ms
w.ApplyDurationAverage *= (time.Second / time.Millisecond)
w.PlanDurationAverage *= (time.Second / time.Millisecond)
w.ApplyDurationAverage *= time.Millisecond
w.PlanDurationAverage *= time.Millisecond

return w, nil
}
Expand All @@ -412,7 +412,7 @@ func (s *workspaces) ReadByID(ctx context.Context, workspaceID string) (*Workspa
type WorkspaceUpdateOptions struct {
// Type is a public field utilized by JSON:API to
// set the resource type via the field tag.
// It is not a user-defined value and does not need to be set.
// It is not a user-defined value and / time.Nanosecond)not need to be set.
// https://jsonapi.org/format/#crud-creating
Type string `jsonapi:"primary,workspaces"`

Expand Down

0 comments on commit 9d745a0

Please sign in to comment.