From 6be4494a4b42a0b876c47f4bf285efc56bba6bba Mon Sep 17 00:00:00 2001 From: budougumi0617 <budougumi0617@gmail.com> Date: Fri, 1 Jan 2021 16:41:26 +0900 Subject: [PATCH] :recycle: modules: change pixela library --- go.mod | 4 +-- go.sum | 15 +++----- pixela/data_source_graphs.go | 12 +++---- pixela/data_source_graphs_test.go | 2 +- pixela/provider.go | 2 +- pixela/resource_graph.go | 59 ++++++++++++++++--------------- pixela/resource_graph_test.go | 20 ++++------- 7 files changed, 51 insertions(+), 63 deletions(-) diff --git a/go.mod b/go.mod index 859f7a4..1f1b5ab 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/budougumi0617/terraform-provider-pixela go 1.15 require ( - github.com/ebc-2in2crc/pixela4go v1.3.0 - github.com/google/go-cmp v0.5.2 + github.com/budougumi0617/pixela v0.0.5 + github.com/google/go-cmp v0.5.4 github.com/hashicorp/terraform v0.14.2 github.com/hashicorp/terraform-plugin-sdk/v2 v2.2.0 ) diff --git a/go.sum b/go.sum index eef5e6b..05b34d3 100644 --- a/go.sum +++ b/go.sum @@ -56,7 +56,6 @@ github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb0 github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM= -github.com/Songmu/make2help v0.2.0/go.mod h1:nTGeq2JX5TVWpwNJvViMnEdDNHJ1PGVAH9gVsx1+puo= github.com/abdullin/seq v0.0.0-20160510034733-d5467c17e7af/go.mod h1:5Jv4cbFiHJMsVxt52+i0Ha45fjshj6wxYr1r19tB9bw= github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE= @@ -103,6 +102,8 @@ github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bmatcuk/doublestar v1.1.5/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= +github.com/budougumi0617/pixela v0.0.5 h1:OKxw9v3ssM5HXAMt5Hpe1HdJ3OY3x+3HPvnE+S0OcnQ= +github.com/budougumi0617/pixela v0.0.5/go.mod h1:kgJTvwAIdlIKuyk0Iuf9SRiLWOCJ5PO1bN3pHeCD5ns= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= @@ -125,8 +126,6 @@ github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQ github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= github.com/dylanmei/iso8601 v0.1.0/go.mod h1:w9KhXSgIyROl1DefbMYIE7UVSIvELTbMrCfx+QkYnoQ= github.com/dylanmei/winrmtest v0.0.0-20190225150635-99b7fe2fddf1/go.mod h1:lcy9/2gH1jn/VCLouHA6tOEwLoNVd4GW6zhuKLmHC2Y= -github.com/ebc-2in2crc/pixela4go v1.3.0 h1:LtLOJAuw19vCHCfZ2wVlQeQVhMOYOHNbkJHbdocy0Fk= -github.com/ebc-2in2crc/pixela4go v1.3.0/go.mod h1:xXDsS5Wis6GQQipkXDQACqDdMd6eUmDfP5tj/dLy5M8= github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= @@ -214,6 +213,8 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= @@ -369,16 +370,12 @@ github.com/masterzen/simplexml v0.0.0-20190410153822-31eea3082786/go.mod h1:kCEb github.com/masterzen/winrm v0.0.0-20200615185753-c42b5136ff88/go.mod h1:a2HXwefeat3evJHxFXSayvRHpYEPJYtErl4uIzfaUqY= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= -github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-shellwords v1.0.4/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/miekg/dns v1.0.8/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= github.com/mitchellh/cli v1.1.1/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= @@ -635,8 +632,6 @@ golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -713,8 +708,6 @@ golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE= -golang.org/x/tools v0.0.0-20201017001424-6003fad69a88 h1:ZB1XYzdDo7c/O48jzjMkvIjnC120Z9/CwgDWhePjQdQ= -golang.org/x/tools v0.0.0-20201017001424-6003fad69a88/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= golang.org/x/tools v0.0.0-20201028111035-eafbe7b904eb h1:KVWk3RW1AZlxWum4tYqegLgwJHb5oouozcGM8HfNQaw= golang.org/x/tools v0.0.0-20201028111035-eafbe7b904eb/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/pixela/data_source_graphs.go b/pixela/data_source_graphs.go index 2c63dac..8e7b43f 100644 --- a/pixela/data_source_graphs.go +++ b/pixela/data_source_graphs.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - pixela "github.com/ebc-2in2crc/pixela4go" + "github.com/budougumi0617/pixela" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -97,12 +97,12 @@ func dataSourceGraphsRead(ctx context.Context, d *schema.ResourceData, m interfa // Warning or errors can be collected in a slice type var diags diag.Diagnostics - result, err := client.Graph().GetAll() + gs, err := client.GetGraphs(ctx) if err != nil { return diag.FromErr(err) } - graphs := flattenGraphsData(&result.Graphs) + graphs := flattenGraphsData(gs) if err := d.Set("graphs", graphs); err != nil { return diag.FromErr(err) } @@ -115,11 +115,11 @@ func dataSourceGraphsRead(ctx context.Context, d *schema.ResourceData, m interfa // to manual mapping because terraform cannot use camel case fields. // Pixela responses has it. -func flattenGraphsData(graphs *[]pixela.GraphDefinition) []interface{} { +func flattenGraphsData(graphs []*pixela.GraphDefinition) []interface{} { if graphs != nil { - gs := make([]interface{}, len(*graphs), len(*graphs)) + gs := make([]interface{}, len(graphs), len(graphs)) - for i, graph := range *graphs { + for i, graph := range graphs { g := make(map[string]interface{}) g["id"] = graph.ID g["name"] = graph.Name diff --git a/pixela/data_source_graphs_test.go b/pixela/data_source_graphs_test.go index 2c51957..3362fd2 100644 --- a/pixela/data_source_graphs_test.go +++ b/pixela/data_source_graphs_test.go @@ -5,7 +5,7 @@ import ( "os" "testing" - pixela "github.com/ebc-2in2crc/pixela4go" + "github.com/budougumi0617/pixela" "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" ) diff --git a/pixela/provider.go b/pixela/provider.go index 239f883..6b21e3e 100644 --- a/pixela/provider.go +++ b/pixela/provider.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - pixela "github.com/ebc-2in2crc/pixela4go" + "github.com/budougumi0617/pixela" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) diff --git a/pixela/resource_graph.go b/pixela/resource_graph.go index b416c79..ec8c725 100644 --- a/pixela/resource_graph.go +++ b/pixela/resource_graph.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - pixela "github.com/ebc-2in2crc/pixela4go" + "github.com/budougumi0617/pixela" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -88,7 +88,7 @@ func resourceGraph() *schema.Resource { } } -func resourceGraphCreate(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceGraphCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { // Warning or errors can be collected in a slice type var diags diag.Diagnostics client := m.(*pixela.Client) @@ -104,17 +104,17 @@ func resourceGraphCreate(_ context.Context, d *schema.ResourceData, m interface{ is := d.Get("is_secret").(bool) pod := d.Get("publish_optional_data").(bool) - result, err := client.Graph().Create(&pixela.GraphCreateInput{ - ID: pixela.String(id), - Name: pixela.String(name), - Unit: pixela.String(unit), - Type: pixela.String(gtype), - Color: pixela.String(color), - TimeZone: pixela.String(timezone), - SelfSufficient: pixela.String(selfSufficient), - IsSecret: pixela.Bool(is), - PublishOptionalData: pixela.Bool(pod), - }) + result, err := client.CreateGraph(ctx, + pixela.GraphID(id), + name, + unit, + pixela.GraphType(gtype), + pixela.GraphColor(color), + pixela.TimeZone(timezone), + pixela.SelfSufficient(pixela.SelfSufficientType(selfSufficient)), + pixela.IsSecret(is), + pixela.PublishOptionalData(pod), + ) if err != nil { return diag.FromErr(err) } @@ -125,12 +125,12 @@ func resourceGraphCreate(_ context.Context, d *schema.ResourceData, m interface{ return diags } -func resourceGraphRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceGraphRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { // Warning or errors can be collected in a slice type var diags diag.Diagnostics client := m.(*pixela.Client) - g, err := client.Graph().Get(&pixela.GraphGetInput{ID: pixela.String(d.Id())}) + g, err := client.GetGraph(ctx, pixela.GraphID(d.Id())) if err != nil { return diag.FromErr(err) } @@ -181,24 +181,25 @@ func resourceGraphUpdate(ctx context.Context, d *schema.ResourceData, m interfac id := d.Get("graph_id").(string) name := d.Get("name").(string) unit := d.Get("unit").(string) + gtype := d.Get("type").(string) // TODO: validate color type color := d.Get("color").(string) timezone := d.Get("timezone").(string) selfSufficient := d.Get("self_sufficient").(string) is := d.Get("is_secret").(bool) pod := d.Get("publish_optional_data").(bool) - - _, err := c.Graph().Update(&pixela.GraphUpdateInput{ - ID: pixela.String(id), - Name: pixela.String(name), - Unit: pixela.String(unit), - Color: pixela.String(color), - TimeZone: pixela.String(timezone), - // PurgeCacheURLs: nil, - SelfSufficient: pixela.String(selfSufficient), - IsSecret: pixela.Bool(is), - PublishOptionalData: pixela.Bool(pod), - }) + gd := &pixela.GraphDefinition{ + ID: pixela.GraphID(id), + Name: name, + Unit: unit, + Type: pixela.GraphType(gtype), + Color: pixela.GraphColor(color), + TimeZone: timezone, + SelfSufficient: pixela.SelfSufficientType(selfSufficient), + IsSecret: is, + PublishOptionalData: pod, + } + _, err := c.UpdateGraph(ctx, gd) if err != nil { return diag.FromErr(err) } @@ -211,7 +212,7 @@ func resourceGraphUpdate(ctx context.Context, d *schema.ResourceData, m interfac return resourceGraphRead(ctx, d, m) } -func resourceGraphDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceGraphDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { c := m.(*pixela.Client) // Warning or errors can be collected in a slice type @@ -219,7 +220,7 @@ func resourceGraphDelete(_ context.Context, d *schema.ResourceData, m interface{ graphID := d.Id() - r, err := c.Graph().Delete(&pixela.GraphDeleteInput{ID: pixela.String(graphID)}) + r, err := c.DeleteGraph(ctx, pixela.GraphID(graphID)) if err != nil { return diag.FromErr(err) } diff --git a/pixela/resource_graph_test.go b/pixela/resource_graph_test.go index 326a3f2..1d74eea 100644 --- a/pixela/resource_graph_test.go +++ b/pixela/resource_graph_test.go @@ -1,11 +1,12 @@ package pixela import ( + "context" "fmt" "os" "testing" - pixela "github.com/ebc-2in2crc/pixela4go" + "github.com/budougumi0617/pixela" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" @@ -53,10 +54,10 @@ func TestAccPixelaGraph_basic(t *testing.T) { func testAccCheckPixelaGraphValues(graph *pixela.GraphDefinition, name, color string) resource.TestCheckFunc { return func(s *terraform.State) error { - if graph.ID != name { + if string(graph.ID) != name { return fmt.Errorf("bad active state, expected \"true\", got: %#v", graph.ID) } - if graph.Color != color { + if string(graph.Color) != color { return fmt.Errorf("bad name, expected \"%s\", got: %#v", name, graph.Color) } return nil @@ -74,9 +75,7 @@ func testAccCheckPixelaGraphExists(n string, graph *pixela.GraphDefinition) reso // retrieve the configured client from the test setup conn := testAccProvider.Meta().(*pixela.Client) - resp, err := conn.Graph().Get(&pixela.GraphGetInput{ - ID: pixela.String(rs.Primary.ID), - }) + resp, err := conn.GetGraph(context.Background(), pixela.GraphID(rs.Primary.ID)) if err != nil { return err @@ -122,20 +121,15 @@ resource "pixela_graph" "basic" { // testAccCheckPixelaGraphDestroy verifies the Widget has been destroyed func testAccCheckPixelaGraphDestroy(s *terraform.State) error { cli := testAccProvider.Meta().(*pixela.Client) + ctx := context.Background() for _, rs := range s.RootModule().Resources { if rs.Type != "pixela_graph" { continue } - request := &pixela.GraphGetInput{ID: pixela.String(rs.Primary.ID)} - - response, err := cli.Graph().Get(request) + _, err := cli.GetGraph(ctx, pixela.GraphID(rs.Primary.ID)) if err != nil { - return err - } - - if response.IsSuccess { return fmt.Errorf("Graph (%s) still exists.", rs.Primary.ID) }