From 0e2dedb28bc8ad1e5ca088fe192599c2cbef8281 Mon Sep 17 00:00:00 2001 From: Max Thomson Date: Mon, 22 Aug 2022 22:25:23 -0400 Subject: [PATCH 01/10] [R-Order] Setup order implementation --- Makefile | 5 +- internal/provider/provider.go | 3 + internal/provider/resource_order.go | 126 ++++++++++++++++++++++++++-- internal/utils/utils.go | 44 ++++++++++ 4 files changed, 168 insertions(+), 10 deletions(-) create mode 100644 internal/utils/utils.go diff --git a/Makefile b/Makefile index 83beae9..05a275b 100644 --- a/Makefile +++ b/Makefile @@ -8,11 +8,12 @@ run: rm -rf .terraform.lock.hcl make build terraform init -plugin-dir .terraform.d/plugins/ - TF_LOG=INFO terraform plan + TF_LOG=INFO terraform apply -auto-approve + rm -rf terraform.tfstat* watch: while true; do \ - inotifywait -e modify,create,delete -r internal/provider/*.go && make run; \ + inotifywait -e modify,create,delete -r internal/provider/*.go && make run; \ done localSetup: diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 24ecdf1..99217c3 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -32,6 +32,8 @@ type dominosProvider struct { // provider is built and ran locally, and "test" when running acceptance // testing. version string + + providerdata providerData } type providerData struct { @@ -61,6 +63,7 @@ func (p *dominosProvider) Configure(ctx context.Context, req provider.ConfigureR data.CreditCard.CardType = types.String{Value: string("VISA")} + p.providerdata = data p.configured = true } diff --git a/internal/provider/resource_order.go b/internal/provider/resource_order.go index 7489659..4942c8c 100644 --- a/internal/provider/resource_order.go +++ b/internal/provider/resource_order.go @@ -2,6 +2,9 @@ package provider import ( "context" + "encoding/json" + "fmt" + "strconv" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" @@ -9,6 +12,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/mnthomson/terraform-provider-dominos/internal/utils" ) // Ensure provider defined types fully satisfy framework interfaces @@ -28,7 +33,7 @@ As far as I know there is no way to cancel a dominos order programmatically, so You should receive an email confirmation almost instantly, and that email will have the store's phone number in it. `, Attributes: map[string]tfsdk.Attribute{ - "api_object": { + "address_api_object": { Description: "The computed json payload for the specified address.", Required: true, Type: types.StringType, @@ -45,11 +50,6 @@ You should receive an email confirmation almost instantly, and that email will h Required: true, Type: types.Int64Type, }, - "price_only": { - Description: "DRY RUN: This will only display the total price of the order (and not actually order).", - Optional: true, - Type: types.BoolType, - }, "total_price": { Description: "The computed total price of the order.", Computed: true, @@ -73,7 +73,6 @@ type resourceOrderData struct { AddressAPIObj types.String `tfsdk:"address_api_object"` ItemCodes types.List `tfsdk:"item_codes"` StoreID types.Int64 `tfsdk:"store_id"` - PriceOnly types.Bool `tfsdk:"price_only"` TotalPrice types.Number `tfsdk:"total_price"` } @@ -81,16 +80,127 @@ type resourceOrder struct { provider dominosProvider } +type Address struct { + Street string `json:"Street"` + City string `json:"City"` + Region string `json:"Region"` + PostalCode string `json:"PostalCode"` + Type string `json:"Type" default:"House"` + DeliveryInstructions string `json:"DeliveryInstructions"` +} + +type Payment struct { + Type string `json:"Type" default:"DoorCredit"` + Amount float64 `json:"Amount"` + Number string `json:"Number" default:""` + CardType string `json:"CardType" default:""` + Expiration string `json:"Expiration" default:""` + SecurityCode string `json:"SecurityCode" default:""` + PostalCode string `json:"PostalCode" default:""` + ProviderID string `json:"ProviderID" default:""` + // PaymentMethodID string `json:"PaymentMethodID"` + // OTP string `json:"OTP"` + // GpmPaymentType string `json:"gpmPaymentType"` +} + +type Product interface{} + +type DominosOrderData struct { + Order struct { + Address Address `json:"Address"` + Coupons []struct{} `json:"Coupons"` + CustomerID string `json:"CustomerID" default:""` + Email string `json:"Email"` + Extension string `json:"Extension" default:""` + FirstName string `json:"FirstName"` + LastName string `json:"LastName"` + LanguageCode string `json:"LanguageCode" default:"en"` + OrderChannel string `json:"OrderChannel" default:"OLO"` + OrderID string `json:"OrderID" default:""` + OrderMethod string `json:"OrderMethod" default:"Web"` + OrderTaker struct{} `json:"OrderTaker"` + Payments []Payment `json:"Payments"` + Phone string `json:"Phone"` + PhonePrefix string `json:"PhonePrefix" default:""` + Products []Product `json:"Products"` + ServiceMethod string `json:"ServiceMethod" default:"Delivery"` + SourceOrganizationURI string `json:"SourceOrganizationURI" default:"order.dominos.com"` + StoreID string `json:"StoreID"` + Tags struct{} `json:"Tags"` + Version string `json:"Version" default:"1.0"` + NoCombine bool `json:"NoCombine" default:"true"` + Partners struct{} `json:"Partners"` + HotspotsLite bool `json:"HotspotsLite" default:"false"` + OrderInfoCollection []struct{} `json:"OrderInfoCollection"` + NewUser bool `json:"NewUser" default:"true"` + } `json:"Order"` +} + func (r resourceOrder) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var data resourceOrderData + var providerdata providerData diags := req.Config.Get(ctx, &data) - resp.Diagnostics.Append(diags...) + resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { return } + providerdata = r.provider.providerdata + order_data := &DominosOrderData{} + + // Order data defaults + err := utils.Set(&(order_data.Order), "default") + if err != nil { + resp.Diagnostics.AddError("Error Setting Defaults", fmt.Sprintf("%s", err)) + return + } + + // Address defaults + err = utils.Set(&(order_data.Order.Address), "default") + if err != nil { + resp.Diagnostics.AddError("Error Setting Defaults", fmt.Sprintf("%s", err)) + return + } + + // Provided address data + err = json.Unmarshal([]byte(data.AddressAPIObj.Value), &(order_data.Order.Address)) + if err != nil { + resp.Diagnostics.AddError("Error unmarshalling AddressAPIObj", fmt.Sprintf("%s", err)) + return + } + + // Provided personal data + order_data.Order.FirstName = providerdata.FirstName.Value + order_data.Order.LastName = providerdata.LastName.Value + order_data.Order.Email = providerdata.EmailAddr.Value + order_data.Order.Phone = providerdata.PhoneNumber.Value + + // Misc + order_data.Order.StoreID = strconv.FormatInt(data.StoreID.Value, 10) + + /* Validate Order */ + + /* Price Order */ + + /* Order order */ + // Add Payment details + + // Payment defaults + err = utils.Set(&(order_data.Order.Address), "default") + if err != nil { + resp.Diagnostics.AddError("Error Setting Defaults", fmt.Sprintf("%s", err)) + return + } + + // Set price + + //Printing output + output_bytes, _ := json.Marshal(order_data) + output := string(output_bytes) + fmt.Println(output) + diags = resp.State.Set(ctx, &data) resp.Diagnostics.Append(diags...) } diff --git a/internal/utils/utils.go b/internal/utils/utils.go new file mode 100644 index 0000000..7a96441 --- /dev/null +++ b/internal/utils/utils.go @@ -0,0 +1,44 @@ +package utils + +import ( + "fmt" + "reflect" + "strconv" +) + +func setField(field reflect.Value, defaultVal string) error { + + if !field.CanSet() { + return fmt.Errorf("Can't set value\n") + } + + switch field.Kind() { + + case reflect.Int: + if val, err := strconv.ParseInt(defaultVal, 10, 64); err == nil { + field.Set(reflect.ValueOf(int(val)).Convert(field.Type())) + } + case reflect.String: + field.Set(reflect.ValueOf(defaultVal).Convert(field.Type())) + } + return nil +} + +func Set(ptr interface{}, tag string) error { + if reflect.TypeOf(ptr).Kind() != reflect.Ptr { + return fmt.Errorf("Not a pointer") + } + + v := reflect.ValueOf(ptr).Elem() + t := v.Type() + + for i := 0; i < t.NumField(); i++ { + if defaultVal := t.Field(i).Tag.Get(tag); defaultVal != "-" { + if err := setField(v.Field(i), defaultVal); err != nil { + return err + } + + } + } + return nil +} From 184f5cbdb42edaf4a96be0508957f8f01e6823b2 Mon Sep 17 00:00:00 2001 From: Max Thomson Date: Wed, 24 Aug 2022 17:37:13 -0400 Subject: [PATCH 02/10] Remove Credit Card --- examples/example.tf | 9 +----- internal/provider/provider.go | 52 +++-------------------------------- 2 files changed, 5 insertions(+), 56 deletions(-) diff --git a/examples/example.tf b/examples/example.tf index ec0607b..fb5d103 100644 --- a/examples/example.tf +++ b/examples/example.tf @@ -1,7 +1,7 @@ terraform { required_providers { dominos = { - source = "MNThomson/dominos" + source = "MNThomson/dominos" } } } @@ -11,13 +11,6 @@ provider "dominos" { last_name = "Name" email_address = "my@name.com" phone_number = "15555555555" - - credit_card = { - number = 123456789101112 - cvv = 1314 - date = "15/16" - postal_code = "18192" - } } data "dominos_address" "addr" { diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 99217c3..8fbe9d2 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -37,19 +37,10 @@ type dominosProvider struct { } type providerData struct { - FirstName types.String `tfsdk:"first_name"` - LastName types.String `tfsdk:"last_name"` - EmailAddr types.String `tfsdk:"email_address"` - PhoneNumber types.String `tfsdk:"phone_number"` - CreditCard *creditCardData `tfsdk:"credit_card"` -} - -type creditCardData struct { - CreditCardNumber types.Int64 `tfsdk:"number"` - Cvv types.Int64 `tfsdk:"cvv"` - ExprDate types.String `tfsdk:"date"` - PostalCode types.String `tfsdk:"postal_code"` - CardType types.String `tfsdk:"card_type"` + FirstName types.String `tfsdk:"first_name"` + LastName types.String `tfsdk:"last_name"` + EmailAddr types.String `tfsdk:"email_address"` + PhoneNumber types.String `tfsdk:"phone_number"` } func (p *dominosProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { @@ -61,8 +52,6 @@ func (p *dominosProvider) Configure(ctx context.Context, req provider.ConfigureR return } - data.CreditCard.CardType = types.String{Value: string("VISA")} - p.providerdata = data p.configured = true } @@ -86,7 +75,6 @@ func (p *dominosProvider) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Dia return tfsdk.Schema{ Description: ` The Dominos provider is used to interact with resources supported by Dominos Pizza. -The provider needs to be configured with a credit card for ordering. Use the navigation to the right to read about the available resources. `, @@ -111,38 +99,6 @@ Use the navigation to the right to read about the available resources. Required: true, Type: types.StringType, }, - "credit_card": { - Description: "Your actual credit card THAT WILL GET CHARGED.", - Optional: true, - Sensitive: true, - Attributes: tfsdk.SingleNestedAttributes(map[string]tfsdk.Attribute{ - "number": { - Description: "The credit card number.", - Type: types.Int64Type, - Required: true, - }, - "cvv": { - Description: "The credit card CVV.", - Type: types.Int64Type, - Required: true, - }, - "date": { - Description: "The credit card expiration date.", - Type: types.StringType, - Required: true, - }, - "postal_code": { - Description: "The postal code attached to the credit card.", - Type: types.StringType, - Required: true, - }, - "card_type": { - Description: "The credit card type. Default: 'VISA'.", - Type: types.StringType, - Optional: true, - }, - }), - }, }, }, nil } From 4883476e7ce3fabaec5095383962ca92cff2f666 Mon Sep 17 00:00:00 2001 From: Max Thomson Date: Wed, 24 Aug 2022 22:19:24 -0400 Subject: [PATCH 03/10] Add Pizza options --- internal/provider/resource_order.go | 60 ++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/internal/provider/resource_order.go b/internal/provider/resource_order.go index 4942c8c..75435e6 100644 --- a/internal/provider/resource_order.go +++ b/internal/provider/resource_order.go @@ -103,7 +103,65 @@ type Payment struct { // GpmPaymentType string `json:"gpmPaymentType"` } -type Product interface{} +type Product struct { + Code string `json:"Code"` + Qty int `json:"Qty" default:"1"` + ID int `json:"ID"` + IsNew bool `json:"isNew" default:"true"` + ShowBestPriceMessage bool `json:"ShowBestPriceMessage" default:"false"` + Options PizzaOptions `json:"Options"` +} + +/* + * Light: "0.5" + * Normal: "1" + * Extra: "1.5" + */ +type PizzaOptions struct { + Cheese Option `json:"C,omitempty"` + + // Pizza Sauces + PizzaSauce Option `json:"X" default:"1"` + BBQSauce Option `json:"Q,omitempty"` + AlfredoSauce Option `json:"Xf,omitempty"` + HeartyMarinaraSauce Option `json:"Xm,omitempty"` + RanchDressing Option `json:"Rd,omitempty"` + GarlicParmesanSauce Option `json:"Xw,omitempty"` + + // Meats + Bacon Option `json:"K,omitempty"` + BeefCrumble Option `json:"B,omitempty"` + BrooklynPepperoni Option `json:"Xp,omitempty"` + Chicken Option `json:"D,omitempty"` + Ham Option `json:"H,omitempty"` + Pepperoni Option `json:"P,omitempty"` + PhillySteak Option `json:"St,omitempty"` + Salami Option `json:"L,omitempty"` + Sausage Option `json:"S,omitempty"` + + // Non-meats + BabySpinach Option `json:"Sp,omitempty"` + BlackOlives Option `json:"R,omitempty"` + Cheddar Option `json:"E,omitempty"` + Feta Option `json:"Fe,omitempty"` + GreenOlives Option `json:"V,omitempty"` + GreenPepper Option `json:"G,omitempty"` + HotBananaPeppers Option `json:"Z,omitempty"` + JalapenoPeppers Option `json:"J,omitempty"` + Mushroom Option `json:"M,omitempty"` + Onion Option `json:"O,omitempty"` + ParmesanAsiago Option `json:"Pa,omitempty"` + Pineapple Option `json:"N,omitempty"` + Provolone Option `json:"Cp,omitempty"` + RoastedRedPeppers Option `json:"Rp,omitempty"` + Tomatoes Option `json:"T,omitempty"` +} + +type Option struct { + Left string `json:"1/2"` + All string `json:"1/1"` + Right string `json:"2/2"` +} type DominosOrderData struct { Order struct { From b9af0ea51242f505d767240338a73202304a7958 Mon Sep 17 00:00:00 2001 From: Max Thomson Date: Thu, 25 Aug 2022 16:53:46 -0400 Subject: [PATCH 04/10] Update all error handling --- go.mod | 2 +- go.sum | 37 ----------- internal/provider/data_source_address.go | 8 +-- internal/provider/data_source_menu.go | 6 +- internal/provider/data_source_menu_item.go | 4 +- internal/provider/data_source_store.go | 12 ++-- internal/provider/data_source_tracking.go | 4 +- internal/provider/resource_order.go | 76 ++++++++++++++++++++-- main.go | 1 + 9 files changed, 89 insertions(+), 61 deletions(-) diff --git a/go.mod b/go.mod index a047652..75f91a3 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.18 require ( github.com/hashicorp/terraform-plugin-docs v0.10.1 github.com/hashicorp/terraform-plugin-framework v0.11.1 + github.com/hashicorp/terraform-plugin-log v0.7.0 ) require ( @@ -29,7 +30,6 @@ require ( github.com/hashicorp/terraform-exec v0.16.1 // indirect github.com/hashicorp/terraform-json v0.14.0 // indirect github.com/hashicorp/terraform-plugin-go v0.14.0 // indirect - github.com/hashicorp/terraform-plugin-log v0.7.0 // indirect github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c // indirect github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect github.com/hashicorp/yamux v0.1.1 // indirect diff --git a/go.sum b/go.sum index da520e2..1e9efd5 100644 --- a/go.sum +++ b/go.sum @@ -52,7 +52,6 @@ github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= -github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4= @@ -89,7 +88,6 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -106,8 +104,6 @@ github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtng github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= -github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= -github.com/hashicorp/go-hclog v1.2.1/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= github.com/hashicorp/go-hclog v1.2.2 h1:ihRI7YFwcZdiSD7SIenIhHfQH3OuDvWerAUBZbeQS3M= github.com/hashicorp/go-hclog v1.2.2/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= @@ -119,16 +115,13 @@ github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.4.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.5.0 h1:O293SZ2Eg+AAYijkVK3jR786Am1bhDEh2GHT0tIVE5E= github.com/hashicorp/go-version v1.5.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/hc-install v0.3.1/go.mod h1:3LCdWcCDS1gaHC9mhHCGbkYfoY6vdsKohGjugbZdZak= github.com/hashicorp/hc-install v0.3.2 h1:oiQdJZvXmkNcRcEOOfM5n+VTsvNjWQeOjfAoO6dKSH8= github.com/hashicorp/hc-install v0.3.2/go.mod h1:xMG6Tr8Fw1WFjlxH0A9v61cW15pFwgEGqEz0V4jisHs= github.com/hashicorp/terraform-exec v0.16.1 h1:NAwZFJW2L2SaCBVZoVaH8LPImLOGbPLkSHy0IYbs2uE= github.com/hashicorp/terraform-exec v0.16.1/go.mod h1:aj0lVshy8l+MHhFNoijNHtqTJQI3Xlowv5EOsEaGO7M= -github.com/hashicorp/terraform-json v0.13.0/go.mod h1:y5OdLBCT+rxbwnpxZs9kGL7R9ExU76+cpdY8zHwoazk= github.com/hashicorp/terraform-json v0.14.0 h1:sh9iZ1Y8IFJLx+xQiKHGud6/TSUCM0N8e17dKDpqV7s= github.com/hashicorp/terraform-json v0.14.0/go.mod h1:5A9HIWPkk4e5aeeXIBbkcOvaZbIYnAIkEyqP2pNSckM= github.com/hashicorp/terraform-plugin-docs v0.10.1 h1:jiVYfhJ/hVXDAQN2XjLK3WH1A/YHgFCrFXPpxibvmjc= @@ -143,7 +136,6 @@ github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b57 github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c/go.mod h1:Wn3Na71knbXc1G8Lh+yu/dQWWJeFQEpDeJMtWMtlmNI= github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0= github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg= -github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= @@ -157,14 +149,12 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE= -github.com/jhump/protoreflect v1.6.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74= github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 h1:DowS9hvgyYSX4TO5NpyC606/Z4SxnNYbT+WX27or6Ck= github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -172,14 +162,11 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -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-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= @@ -191,7 +178,6 @@ github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa1 github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU= github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= @@ -199,8 +185,6 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k+Mg7cowZ8yv4Trqw9UsJby758= -github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce/go.mod h1:uFMI8w+ref4v2r9jz+c9i1IfIttS/OkmLfrk1jne5hs= -github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -213,13 +197,11 @@ github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSg github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= -github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww= github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY= github.com/sebdah/goldie v1.0.0/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= -github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= @@ -237,7 +219,6 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -github.com/vmihailenco/msgpack v3.3.3+incompatible h1:wapg9xDUZDzGCNFlwc5SqI1rvcciqcxEHac4CYj89xI= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack/v4 v4.3.12 h1:07s4sz9IReOgdikxLTKNbBdqDMLsjPKXwvCazn8G65U= github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= @@ -248,7 +229,6 @@ github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0= github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s= github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= -github.com/zclconf/go-cty v1.9.1/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= github.com/zclconf/go-cty v1.10.0 h1:mp9ZXQeIcN8kAwuqorjH+Q+njbJKjLrvB2yIh4q7U+0= github.com/zclconf/go-cty v1.10.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= @@ -267,7 +247,6 @@ golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/net v0.0.0-20180530234432-1e491301e022/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -283,8 +262,6 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220812174116-3211cb980234 h1:RDqmgfe7SvlMWoqC3xwQ2blLO3fcWcxMa3eBLRdRW7E= golang.org/x/net v0.0.0-20220812174116-3211cb980234/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -297,11 +274,9 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -311,26 +286,19 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2 h1:fqTvyMIIj+HRzMmnzr9NtpHP6uVpvB5fkHcgPDC4nu8= golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -345,24 +313,20 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/genproto v0.0.0-20170818010345-ee236bd376b0/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20220817144833-d7fd3f11b9b1 h1:C2UVWqrgLYKrT5nh5oU6hLRm1AeEklCK5eloQA1NtFY= google.golang.org/genproto v0.0.0-20220817144833-d7fd3f11b9b1/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= -google.golang.org/grpc v1.8.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.48.0 h1:rQOsyJ/8+ufEDJd/Gdsz7HG220Mh9HAhFHRGnIjda0w= google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= -google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0/go.mod h1:DNq5QpG7LJqD2AamLZ7zvKE0DEpVl2BSEVjFycAAjRY= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -383,7 +347,6 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/internal/provider/data_source_address.go b/internal/provider/data_source_address.go index 88206e3..2312960 100644 --- a/internal/provider/data_source_address.go +++ b/internal/provider/data_source_address.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "log" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/diag" @@ -113,15 +112,16 @@ func (d dataSourceAddress) Read(ctx context.Context, req datasource.ReadRequest, } url_json, err := json.Marshal(urlobj) if err != nil { - log.Fatalf("Cannot unmarshall urlobj") - + resp.Diagnostics.AddError("Cannot unmarshall urlobj", fmt.Sprintf("%s", err)) + return } data.URLObject = types.String{Value: string(url_json)} api_json, err := json.Marshal(apiobj) if err != nil { - log.Fatalf("Cannot unmarshall apiobj") + resp.Diagnostics.AddError("Cannot unmarshall apiobj", fmt.Sprintf("%s", err)) + return } data.APIObject = types.String{Value: string(api_json)} diff --git a/internal/provider/data_source_menu.go b/internal/provider/data_source_menu.go index 439aad3..2b4470d 100644 --- a/internal/provider/data_source_menu.go +++ b/internal/provider/data_source_menu.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "log" "net/http" "sort" "strconv" @@ -97,9 +96,10 @@ func (d dataSourceMenu) Read(ctx context.Context, req datasource.ReadRequest, re var client = &http.Client{Timeout: 10 * time.Second} - menuitems, err := getAllMenuItems(fmt.Sprintf("https://order.dominos.com/power/store/%d/menu?lang=en&structured=true", data.StoreID.Value), client) + menuitems, err := getAllMenuItems(fmt.Sprintf("https://order.dominos.ca/power/store/%d/menu?lang=en&structured=true", data.StoreID.Value), client) if err != nil { - log.Fatalf("Cannot get all menu items: %v", err) + resp.Diagnostics.AddError("Cannot get all menu items", fmt.Sprintf("%s", err)) + return } for i := range menuitems { diff --git a/internal/provider/data_source_menu_item.go b/internal/provider/data_source_menu_item.go index 86cf108..6cf7350 100644 --- a/internal/provider/data_source_menu_item.go +++ b/internal/provider/data_source_menu_item.go @@ -3,7 +3,6 @@ package provider import ( "context" "fmt" - "log" "net/http" "strings" "time" @@ -107,7 +106,8 @@ func (d dataSourceMenuItem) Read(ctx context.Context, req datasource.ReadRequest var client = &http.Client{Timeout: 10 * time.Second} menuitems, err := getAllMenuItems(fmt.Sprintf("https://order.dominos.com/power/store/%d/menu?lang=en&structured=true", data.StoreID.Value), client) if err != nil { - log.Fatalf("Cannot get all menu items: %v", err) + resp.Diagnostics.AddError("Cannot get all menu items", fmt.Sprintf("%s", err)) + return } queries := data.QueryString diff --git a/internal/provider/data_source_store.go b/internal/provider/data_source_store.go index 8e96f8c..4114ec9 100644 --- a/internal/provider/data_source_store.go +++ b/internal/provider/data_source_store.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "log" "net/http" "net/url" "strconv" @@ -81,16 +80,19 @@ func (d dataSourceStore) Read(ctx context.Context, req datasource.ReadRequest, r address_url_obj := make(map[string]string) err := json.Unmarshal([]byte(data.AddressURLObj.Value), &address_url_obj) if err != nil { - log.Fatalf("Cannot unmarshall address_url_obj") + resp.Diagnostics.AddError("Cannot unmarshall address_url_obj", fmt.Sprintf("%s", err)) + return } line1 := url.QueryEscape(address_url_obj["line1"]) line2 := url.QueryEscape(address_url_obj["line2"]) - stores, err := getStores(fmt.Sprintf("https://order.dominos.com/power/store-locator?s=%s&c=%s&s=Delivery", line1, line2), client) + stores, err := getStores(fmt.Sprintf("https://order.dominos.ca/power/store-locator?s=%s&c=%s&s=Delivery", line1, line2), client) if err != nil { - log.Fatalf("Cannot get stores: %v", err) + resp.Diagnostics.AddError("Cannot get stores", fmt.Sprintf("%s", err)) + return } if len(stores) == 0 { - log.Fatalf("No stores near the address %#v", address_url_obj) + resp.Diagnostics.AddError("No stores near the address", fmt.Sprintf("%s", err)) + return } storeID, _ := strconv.ParseInt(stores[0].StoreID, 10, 64) data.StoreID = types.Int64{Value: storeID} diff --git a/internal/provider/data_source_tracking.go b/internal/provider/data_source_tracking.go index bbd2306..fd8c543 100644 --- a/internal/provider/data_source_tracking.go +++ b/internal/provider/data_source_tracking.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "log" "net/http" "time" @@ -73,7 +72,8 @@ func (d dataSourceTracking) Read(ctx context.Context, req datasource.ReadRequest _, err := getTrackingApiObject(fmt.Sprintf("https://trkweb.dominos.com/orderstorage/GetTrackerData?StoreID=%d&OrderKey=%d", data.StoreID.Value, data.OrderID.Value), client) if err != nil { - log.Fatalf("Cannot get tracking api object: %v", err) + resp.Diagnostics.AddError("Cannot get tracking api object", fmt.Sprintf("%s", err)) + return } diags = resp.State.Set(ctx, &data) diff --git a/internal/provider/resource_order.go b/internal/provider/resource_order.go index 75435e6..c7b8af0 100644 --- a/internal/provider/resource_order.go +++ b/internal/provider/resource_order.go @@ -4,7 +4,11 @@ import ( "context" "encoding/json" "fmt" + "net/http" + "net/http/httputil" "strconv" + "strings" + "time" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" @@ -12,6 +16,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/mnthomson/terraform-provider-dominos/internal/utils" ) @@ -112,11 +117,6 @@ type Product struct { Options PizzaOptions `json:"Options"` } -/* - * Light: "0.5" - * Normal: "1" - * Extra: "1.5" - */ type PizzaOptions struct { Cheese Option `json:"C,omitempty"` @@ -157,6 +157,11 @@ type PizzaOptions struct { Tomatoes Option `json:"T,omitempty"` } +/* + * Light: "0.5" + * Normal: "1" + * Extra: "1.5" + */ type Option struct { Left string `json:"1/2"` All string `json:"1/1"` @@ -197,6 +202,7 @@ type DominosOrderData struct { func (r resourceOrder) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var data resourceOrderData var providerdata providerData + var client = &http.Client{Timeout: 10 * time.Second} diags := req.Config.Get(ctx, &data) @@ -239,6 +245,55 @@ func (r resourceOrder) Create(ctx context.Context, req resource.CreateRequest, r order_data.Order.StoreID = strconv.FormatInt(data.StoreID.Value, 10) /* Validate Order */ + output_bytes, err := json.Marshal(order_data) + if err != nil { + resp.Diagnostics.AddError("Error Marshalling Order Data", fmt.Sprintf("%s", err)) + return + } + + val_req, err := http.NewRequest("POST", "https://order.dominos.ca/power/validate-order", strings.NewReader(string(output_bytes))) + if err != nil { + resp.Diagnostics.AddError("HTTP Error", fmt.Sprintf("%s", err)) + return + } + + val_req.Header.Set("Referer", "https://order.dominos.com/en/pages/order/") + val_req.Header.Set("Content-Type", "application/json") + + dumpreq, err := httputil.DumpRequest(val_req, true) + if err != nil { + resp.Diagnostics.AddError("HTTP Error", fmt.Sprintf("%s", err)) + return + } + + tflog.Info(ctx, "http request: "+string(dumpreq)) + + val_rsp, err := client.Do(val_req) + if err != nil { + resp.Diagnostics.AddError("HTTP Error", fmt.Sprintf("%s", err)) + return + } + + dumprsp, err := httputil.DumpResponse(val_rsp, true) + if err != nil { + resp.Diagnostics.AddError("HTTP Error", fmt.Sprintf("%s", err)) + return + } + + tflog.Info(ctx, "http response: %#v"+string(dumprsp)) + validate_response_obj := make(map[string]interface{}) + err = json.NewDecoder(val_rsp.Body).Decode(&validate_response_obj) + + if validate_response_obj["Status"].(float64) == -1 { + resp.Diagnostics.AddError("The Dominos API didn't like this request", fmt.Sprintf("%s", validate_response_obj["StatusItems"])) + return + } + + // for k, v := range validate_response_obj["Order"].(map[string]interface{}) { + // if list, ok := v.([]interface{}); !ok || len(list) > 0 { + // order_data[k] = v + // } + // } /* Price Order */ @@ -246,7 +301,9 @@ func (r resourceOrder) Create(ctx context.Context, req resource.CreateRequest, r // Add Payment details // Payment defaults - err = utils.Set(&(order_data.Order.Address), "default") + var payment Payment + order_data.Order.Payments = append(order_data.Order.Payments, payment) + err = utils.Set(&(order_data.Order.Payments[0]), "default") if err != nil { resp.Diagnostics.AddError("Error Setting Defaults", fmt.Sprintf("%s", err)) return @@ -255,7 +312,12 @@ func (r resourceOrder) Create(ctx context.Context, req resource.CreateRequest, r // Set price //Printing output - output_bytes, _ := json.Marshal(order_data) + // output_bytes, err := json.Marshal(order_data) + // if err != nil { + // resp.Diagnostics.AddError("Error Marshalling Order Data", fmt.Sprintf("%s", err)) + // return + // } + output := string(output_bytes) fmt.Println(output) diff --git a/main.go b/main.go index c38a321..3d307d8 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "log" "github.com/hashicorp/terraform-plugin-framework/providerserver" + "github.com/mnthomson/terraform-provider-dominos/internal/provider" ) From 785c1c245bb1c79cf3886f45062f66b1801ef03f Mon Sep 17 00:00:00 2001 From: Max Thomson Date: Sat, 27 Aug 2022 02:36:55 -0400 Subject: [PATCH 05/10] Price Order & Initial Pizza DS --- .gitignore | 2 + go.sum | 22 +++ internal/provider/data_source_menu_item.go | 2 +- internal/provider/data_source_pizza.go | 100 +++++++++++++ internal/provider/data_source_tracking.go | 2 +- internal/provider/generated.go | 63 ++++++++ internal/provider/provider.go | 1 + internal/provider/resource_order.go | 165 +++++++++------------ 8 files changed, 257 insertions(+), 100 deletions(-) create mode 100644 internal/provider/data_source_pizza.go create mode 100644 internal/provider/generated.go diff --git a/.gitignore b/.gitignore index a545b14..be77b2d 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ terraform-provider-dominos # Randon _*.* +data +NOTES.md diff --git a/go.sum b/go.sum index 1e9efd5..31eaf8a 100644 --- a/go.sum +++ b/go.sum @@ -111,6 +111,8 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/go-plugin v1.4.4 h1:NVdrSdFRt3SkZtNckJ6tog7gbpRrcbOjQi/rgF7JYWQ= github.com/hashicorp/go-plugin v1.4.4/go.mod h1:viDMjcLJuDui6pXb8U4HVfb8AamCWhHGUjr2IrTF67s= +github.com/hashicorp/go-plugin v1.4.5 h1:oTE/oQR4eghggRg8VY7PAz3dr++VwDNBGCcOfIvHpBo= +github.com/hashicorp/go-plugin v1.4.5/go.mod h1:viDMjcLJuDui6pXb8U4HVfb8AamCWhHGUjr2IrTF67s= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= @@ -118,14 +120,22 @@ github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09 github.com/hashicorp/go-version v1.4.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.5.0 h1:O293SZ2Eg+AAYijkVK3jR786Am1bhDEh2GHT0tIVE5E= github.com/hashicorp/go-version v1.5.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= +github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/hc-install v0.3.2 h1:oiQdJZvXmkNcRcEOOfM5n+VTsvNjWQeOjfAoO6dKSH8= github.com/hashicorp/hc-install v0.3.2/go.mod h1:xMG6Tr8Fw1WFjlxH0A9v61cW15pFwgEGqEz0V4jisHs= +github.com/hashicorp/hc-install v0.4.0 h1:cZkRFr1WVa0Ty6x5fTvL1TuO1flul231rWkGH92oYYk= +github.com/hashicorp/hc-install v0.4.0/go.mod h1:5d155H8EC5ewegao9A4PUTMNPZaq+TbOzkJJZ4vrXeI= github.com/hashicorp/terraform-exec v0.16.1 h1:NAwZFJW2L2SaCBVZoVaH8LPImLOGbPLkSHy0IYbs2uE= github.com/hashicorp/terraform-exec v0.16.1/go.mod h1:aj0lVshy8l+MHhFNoijNHtqTJQI3Xlowv5EOsEaGO7M= +github.com/hashicorp/terraform-exec v0.17.2 h1:EU7i3Fh7vDUI9nNRdMATCEfnm9axzTnad8zszYZ73Go= +github.com/hashicorp/terraform-exec v0.17.2/go.mod h1:tuIbsL2l4MlwwIZx9HPM+LOV9vVyEfBYu2GsO1uH3/8= github.com/hashicorp/terraform-json v0.14.0 h1:sh9iZ1Y8IFJLx+xQiKHGud6/TSUCM0N8e17dKDpqV7s= github.com/hashicorp/terraform-json v0.14.0/go.mod h1:5A9HIWPkk4e5aeeXIBbkcOvaZbIYnAIkEyqP2pNSckM= github.com/hashicorp/terraform-plugin-docs v0.10.1 h1:jiVYfhJ/hVXDAQN2XjLK3WH1A/YHgFCrFXPpxibvmjc= github.com/hashicorp/terraform-plugin-docs v0.10.1/go.mod h1:47ZcsxMUJxAjGzHf+dZ9q78oYf4PeJxO1N+i5XDtXBc= +github.com/hashicorp/terraform-plugin-docs v0.13.0 h1:6e+VIWsVGb6jYJewfzq2ok2smPzZrt1Wlm9koLeKazY= +github.com/hashicorp/terraform-plugin-docs v0.13.0/go.mod h1:W0oCmHAjIlTHBbvtppWHe8fLfZ2BznQbuv8+UD8OucQ= github.com/hashicorp/terraform-plugin-framework v0.11.1 h1:rq8f+TLDO4tJu+n9mMYlDrcRoIdrg0gTUvV2Jr0Ya24= github.com/hashicorp/terraform-plugin-framework v0.11.1/go.mod h1:GENReHOz6GEt8Jk3UN94vk8BdC6irEHFgN3Z9HPhPUU= github.com/hashicorp/terraform-plugin-go v0.14.0 h1:ttnSlS8bz3ZPYbMb84DpcPhY4F5DsQtcAS7cHo8uvP4= @@ -231,6 +241,8 @@ github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLE github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= github.com/zclconf/go-cty v1.10.0 h1:mp9ZXQeIcN8kAwuqorjH+Q+njbJKjLrvB2yIh4q7U+0= github.com/zclconf/go-cty v1.10.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= +github.com/zclconf/go-cty v1.11.0 h1:726SxLdi2SDnjY+BStqB9J1hNp4+2WlzyXLuimibIe0= +github.com/zclconf/go-cty v1.11.0/go.mod h1:s9IfD1LK5ccNMSWCVFCE2rJfHiZgi7JijgeWIMfhLvA= github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -243,6 +255,8 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e h1:T8NU3HyQ8ClP4SEE+KbFlg6n0NhuTsN4MyznaarGsZM= golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d h1:3qF+Z8Hkrw9sOhrFHti9TlB1Hkac1x+DNRkv0XQiFjo= +golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -264,6 +278,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k= golang.org/x/net v0.0.0-20220812174116-3211cb980234 h1:RDqmgfe7SvlMWoqC3xwQ2blLO3fcWcxMa3eBLRdRW7E= golang.org/x/net v0.0.0-20220812174116-3211cb980234/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= +golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b h1:ZmngSVLe/wycRns9MKikG9OWIEjGcGAkacif7oYQaUY= +golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -294,6 +310,8 @@ golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2 h1:fqTvyMIIj+HRzMmnzr9NtpHP6uVpvB5fkHcgPDC4nu8= golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 h1:UiNENfZ8gDvpiWw7IpOMQ27spWmThO1RwwdQVbJahJM= +golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -319,6 +337,8 @@ google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfG google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20220817144833-d7fd3f11b9b1 h1:C2UVWqrgLYKrT5nh5oU6hLRm1AeEklCK5eloQA1NtFY= google.golang.org/genproto v0.0.0-20220817144833-d7fd3f11b9b1/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= +google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc h1:Nf+EdcTLHR8qDNN/KfkQL0u0ssxt9OhbaWCl5C0ucEI= +google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= @@ -327,6 +347,8 @@ google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTp google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.48.0 h1:rQOsyJ/8+ufEDJd/Gdsz7HG220Mh9HAhFHRGnIjda0w= google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.49.0 h1:WTLtQzmQori5FUH25Pq4WT22oCsv8USpQ+F6rqtsmxw= +google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/internal/provider/data_source_menu_item.go b/internal/provider/data_source_menu_item.go index 6cf7350..723a6a3 100644 --- a/internal/provider/data_source_menu_item.go +++ b/internal/provider/data_source_menu_item.go @@ -104,7 +104,7 @@ func (d dataSourceMenuItem) Read(ctx context.Context, req datasource.ReadRequest } var client = &http.Client{Timeout: 10 * time.Second} - menuitems, err := getAllMenuItems(fmt.Sprintf("https://order.dominos.com/power/store/%d/menu?lang=en&structured=true", data.StoreID.Value), client) + menuitems, err := getAllMenuItems(fmt.Sprintf("https://order.dominos.ca/power/store/%d/menu?lang=en&structured=true", data.StoreID.Value), client) if err != nil { resp.Diagnostics.AddError("Cannot get all menu items", fmt.Sprintf("%s", err)) return diff --git a/internal/provider/data_source_pizza.go b/internal/provider/data_source_pizza.go new file mode 100644 index 0000000..73f9a17 --- /dev/null +++ b/internal/provider/data_source_pizza.go @@ -0,0 +1,100 @@ +package provider + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +// Ensure provider defined types fully satisfy framework interfaces +var _ provider.DataSourceType = dataSourcePizzaType{} +var _ datasource.DataSource = dataSourcePizza{} + +type dataSourcePizzaType struct{} + +var itemOptionsAttributes = tfsdk.SingleNestedAttributes(map[string]tfsdk.Attribute{ + "portion": { + Description: "", + Optional: true, + Type: types.StringType, + }, + "weight": { + Description: "", + Optional: true, + Type: types.StringType, + }, +}) + +func (t dataSourcePizzaType) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { + return tfsdk.Schema{ + Description: ` +Provided a Dominos address, this data source returns the store_id of the closest Dominos store, and, in case it's useful to you somehow, the delivery_minutes, an integer showing the estimated minutes until your pizza will be delivered. + `, + Attributes: map[string]tfsdk.Attribute{ + "size": { + Description: "", + Type: types.StringType, + Required: true, + }, + "crust": { + Description: "", + Type: types.StringType, + Required: true, + }, + "options": { + Description: "", + Optional: true, + Attributes: optionsAttributes, + }, + "pizza_json": { + Description: "The json for the pizza Product.", + Type: types.StringType, + Computed: true, + }, + }, + }, nil +} + +func (t dataSourcePizzaType) NewDataSource(ctx context.Context, in provider.Provider) (datasource.DataSource, diag.Diagnostics) { + provider, diags := convertProviderType(in) + + return dataSourcePizza{ + provider: provider, + }, diags +} + +type dataSourcePizzaData struct { + Size types.String `tfsdk:"size"` + Crust types.String `tfsdk:"crust"` + Options types.Object `tfsdk:"options"` + PizzaJson types.String `tfsdk:"pizza_json"` +} + +type dataSourcePizza struct { + provider dominosProvider +} + +func (d dataSourcePizza) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var data dataSourcePizzaData + + diags := req.Config.Get(ctx, &data) + + resp.Diagnostics.Append(diags...) + + if resp.Diagnostics.HasError() { + return + } + + // for key, val := range data.Options.Attrs { + // fmt.Printf("Key: %s, Value: %s\n", key, val) + // } + + data.PizzaJson = types.String{Value: data.Options.String()} + + diags = resp.State.Set(ctx, &data) + resp.Diagnostics.Append(diags...) +} diff --git a/internal/provider/data_source_tracking.go b/internal/provider/data_source_tracking.go index fd8c543..963fccd 100644 --- a/internal/provider/data_source_tracking.go +++ b/internal/provider/data_source_tracking.go @@ -70,7 +70,7 @@ func (d dataSourceTracking) Read(ctx context.Context, req datasource.ReadRequest var client = &http.Client{Timeout: 10 * time.Second} - _, err := getTrackingApiObject(fmt.Sprintf("https://trkweb.dominos.com/orderstorage/GetTrackerData?StoreID=%d&OrderKey=%d", data.StoreID.Value, data.OrderID.Value), client) + _, err := getTrackingApiObject(fmt.Sprintf("https://trkweb.dominos.ca/orderstorage/GetTrackerData?StoreID=%d&OrderKey=%d", data.StoreID.Value, data.OrderID.Value), client) if err != nil { resp.Diagnostics.AddError("Cannot get tracking api object", fmt.Sprintf("%s", err)) return diff --git a/internal/provider/generated.go b/internal/provider/generated.go new file mode 100644 index 0000000..eee4849 --- /dev/null +++ b/internal/provider/generated.go @@ -0,0 +1,63 @@ +// AUTOGENERATED: DO NOT EDIT +// Update this file from the /tools folder + +package provider + + +import ( + "github.com/hashicorp/terraform-plugin-framework/tfsdk" +) + +// TODO: Implement https://github.com/hashicorp/terraform-plugin-framework-validators +var optionsAttributes = tfsdk.SingleNestedAttributes(map[string]tfsdk.Attribute{ + "cheese": { + Description: "", + Optional: true, + Attributes: itemOptionsAttributes, + }, + "sauce": { + Description: "", + Optional: true, + Attributes: itemOptionsAttributes, + }, +}) + +type PizzaOptions struct { + Cheese Option `json:"C"` + + // Pizza Sauces + PizzaSauce Option `json:"X,omitempty"` + BBQSauce Option `json:"Q,omitempty"` + AlfredoSauce Option `json:"Xf,omitempty"` + HeartyMarinaraSauce Option `json:"Xm,omitempty"` + RanchDressing Option `json:"Rd,omitempty"` + GarlicParmesanSauce Option `json:"Xw,omitempty"` + + // Meats + Bacon Option `json:"K,omitempty"` + BeefCrumble Option `json:"B,omitempty"` + BrooklynPepperoni Option `json:"Xp,omitempty"` + Chicken Option `json:"D,omitempty"` + Ham Option `json:"H,omitempty"` + Pepperoni Option `json:"P,omitempty"` + PhillySteak Option `json:"St,omitempty"` + Salami Option `json:"L,omitempty"` + Sausage Option `json:"S,omitempty"` + + // Non-meats + BabySpinach Option `json:"Sp,omitempty"` + BlackOlives Option `json:"R,omitempty"` + Cheddar Option `json:"E,omitempty"` + Feta Option `json:"Fe,omitempty"` + GreenOlives Option `json:"V,omitempty"` + GreenPepper Option `json:"G,omitempty"` + HotBananaPeppers Option `json:"Z,omitempty"` + JalapenoPeppers Option `json:"J,omitempty"` + Mushroom Option `json:"M,omitempty"` + Onion Option `json:"O,omitempty"` + ParmesanAsiago Option `json:"Pa,omitempty"` + Pineapple Option `json:"N,omitempty"` + Provolone Option `json:"Cp,omitempty"` + RoastedRedPeppers Option `json:"Rp,omitempty"` + Tomatoes Option `json:"T,omitempty"` +} diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 8fbe9d2..b8c5737 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -68,6 +68,7 @@ func (p *dominosProvider) GetDataSources(ctx context.Context) (map[string]provid "dominos_store": dataSourceStoreType{}, "dominos_menu": dataSourceMenuType{}, "dominos_menu_item": dataSourceMenuItemType{}, + "dominos_pizza": dataSourcePizzaType{}, }, nil } diff --git a/internal/provider/resource_order.go b/internal/provider/resource_order.go index c7b8af0..e40caa6 100644 --- a/internal/provider/resource_order.go +++ b/internal/provider/resource_order.go @@ -58,9 +58,7 @@ You should receive an email confirmation almost instantly, and that email will h "total_price": { Description: "The computed total price of the order.", Computed: true, - PlanModifiers: tfsdk.AttributePlanModifiers{ - resource.UseStateForUnknown()}, - Type: types.NumberType, + Type: types.NumberType, }, }, }, nil @@ -117,46 +115,6 @@ type Product struct { Options PizzaOptions `json:"Options"` } -type PizzaOptions struct { - Cheese Option `json:"C,omitempty"` - - // Pizza Sauces - PizzaSauce Option `json:"X" default:"1"` - BBQSauce Option `json:"Q,omitempty"` - AlfredoSauce Option `json:"Xf,omitempty"` - HeartyMarinaraSauce Option `json:"Xm,omitempty"` - RanchDressing Option `json:"Rd,omitempty"` - GarlicParmesanSauce Option `json:"Xw,omitempty"` - - // Meats - Bacon Option `json:"K,omitempty"` - BeefCrumble Option `json:"B,omitempty"` - BrooklynPepperoni Option `json:"Xp,omitempty"` - Chicken Option `json:"D,omitempty"` - Ham Option `json:"H,omitempty"` - Pepperoni Option `json:"P,omitempty"` - PhillySteak Option `json:"St,omitempty"` - Salami Option `json:"L,omitempty"` - Sausage Option `json:"S,omitempty"` - - // Non-meats - BabySpinach Option `json:"Sp,omitempty"` - BlackOlives Option `json:"R,omitempty"` - Cheddar Option `json:"E,omitempty"` - Feta Option `json:"Fe,omitempty"` - GreenOlives Option `json:"V,omitempty"` - GreenPepper Option `json:"G,omitempty"` - HotBananaPeppers Option `json:"Z,omitempty"` - JalapenoPeppers Option `json:"J,omitempty"` - Mushroom Option `json:"M,omitempty"` - Onion Option `json:"O,omitempty"` - ParmesanAsiago Option `json:"Pa,omitempty"` - Pineapple Option `json:"N,omitempty"` - Provolone Option `json:"Cp,omitempty"` - RoastedRedPeppers Option `json:"Rp,omitempty"` - Tomatoes Option `json:"T,omitempty"` -} - /* * Light: "0.5" * Normal: "1" @@ -199,6 +157,47 @@ type DominosOrderData struct { } `json:"Order"` } +func price_order(ctx context.Context, order_data DominosOrderData, client *http.Client) (string, error) { + output_bytes, err := json.Marshal(order_data) + if err != nil { + return "", fmt.Errorf("Error Marshalling Order Data: %s", err) + } + + val_req, err := http.NewRequest("POST", "https://order.dominos.ca/power/price-order", strings.NewReader(string(output_bytes))) + if err != nil { + return "", fmt.Errorf("HTTP Error: %s", err) + } + + val_req.Header.Set("Referer", "https://order.dominos.ca/en/pages/order/") + val_req.Header.Set("Content-Type", "application/json") + + dumpreq, err := httputil.DumpRequest(val_req, true) + if err != nil { + return "", fmt.Errorf("HTTP Error: %s", err) + } + + tflog.Info(ctx, "http request:\n"+string(dumpreq)+"\n") + + val_rsp, err := client.Do(val_req) + if err != nil { + return "", fmt.Errorf("HTTP Error: %s", err) + } + + dumprsp, err := httputil.DumpResponse(val_rsp, true) + if err != nil { + return "", fmt.Errorf("HTTP Error: %s", err) + } + + tflog.Info(ctx, "http response:\n"+string(dumprsp)+"\n") + validate_response_obj := make(map[string]interface{}) + err = json.NewDecoder(val_rsp.Body).Decode(&validate_response_obj) + + if validate_response_obj["Status"].(float64) == -1 { + return "", fmt.Errorf("The Dominos API didn't like this request: %s", validate_response_obj["StatusItems"]) + } + return "Hello", nil +} + func (r resourceOrder) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { var data resourceOrderData var providerdata providerData @@ -217,14 +216,14 @@ func (r resourceOrder) Create(ctx context.Context, req resource.CreateRequest, r // Order data defaults err := utils.Set(&(order_data.Order), "default") if err != nil { - resp.Diagnostics.AddError("Error Setting Defaults", fmt.Sprintf("%s", err)) + resp.Diagnostics.AddError("Error Setting Order Defaults", fmt.Sprintf("%s", err)) return } // Address defaults err = utils.Set(&(order_data.Order.Address), "default") if err != nil { - resp.Diagnostics.AddError("Error Setting Defaults", fmt.Sprintf("%s", err)) + resp.Diagnostics.AddError("Error Setting Address Defaults", fmt.Sprintf("%s", err)) return } @@ -244,60 +243,23 @@ func (r resourceOrder) Create(ctx context.Context, req resource.CreateRequest, r // Misc order_data.Order.StoreID = strconv.FormatInt(data.StoreID.Value, 10) - /* Validate Order */ - output_bytes, err := json.Marshal(order_data) - if err != nil { - resp.Diagnostics.AddError("Error Marshalling Order Data", fmt.Sprintf("%s", err)) - return - } + /* + * Add items to Products + */ - val_req, err := http.NewRequest("POST", "https://order.dominos.ca/power/validate-order", strings.NewReader(string(output_bytes))) + /* + * Price Order + */ + price_res, err := price_order(ctx, *order_data, client) if err != nil { - resp.Diagnostics.AddError("HTTP Error", fmt.Sprintf("%s", err)) + resp.Diagnostics.AddError("Error Pricing Order", fmt.Sprintf("%s", err)) return } + fmt.Println(price_res) - val_req.Header.Set("Referer", "https://order.dominos.com/en/pages/order/") - val_req.Header.Set("Content-Type", "application/json") - - dumpreq, err := httputil.DumpRequest(val_req, true) - if err != nil { - resp.Diagnostics.AddError("HTTP Error", fmt.Sprintf("%s", err)) - return - } - - tflog.Info(ctx, "http request: "+string(dumpreq)) - - val_rsp, err := client.Do(val_req) - if err != nil { - resp.Diagnostics.AddError("HTTP Error", fmt.Sprintf("%s", err)) - return - } - - dumprsp, err := httputil.DumpResponse(val_rsp, true) - if err != nil { - resp.Diagnostics.AddError("HTTP Error", fmt.Sprintf("%s", err)) - return - } - - tflog.Info(ctx, "http response: %#v"+string(dumprsp)) - validate_response_obj := make(map[string]interface{}) - err = json.NewDecoder(val_rsp.Body).Decode(&validate_response_obj) - - if validate_response_obj["Status"].(float64) == -1 { - resp.Diagnostics.AddError("The Dominos API didn't like this request", fmt.Sprintf("%s", validate_response_obj["StatusItems"])) - return - } - - // for k, v := range validate_response_obj["Order"].(map[string]interface{}) { - // if list, ok := v.([]interface{}); !ok || len(list) > 0 { - // order_data[k] = v - // } - // } - - /* Price Order */ - - /* Order order */ + /* + * Order order + */ // Add Payment details // Payment defaults @@ -305,21 +267,28 @@ func (r resourceOrder) Create(ctx context.Context, req resource.CreateRequest, r order_data.Order.Payments = append(order_data.Order.Payments, payment) err = utils.Set(&(order_data.Order.Payments[0]), "default") if err != nil { - resp.Diagnostics.AddError("Error Setting Defaults", fmt.Sprintf("%s", err)) + resp.Diagnostics.AddError("Error Setting Payment Defaults", fmt.Sprintf("%s", err)) return } // Set price + //Place Order + // place_res, err := place_order(*order_data, client) + // if err != nil { + // return + // } + // fmt.Println(place_res) + //Printing output // output_bytes, err := json.Marshal(order_data) // if err != nil { - // resp.Diagnostics.AddError("Error Marshalling Order Data", fmt.Sprintf("%s", err)) + // resp.Diagnostics.AddError("Error Placing Order", fmt.Sprintf("%s", err)) // return // } - output := string(output_bytes) - fmt.Println(output) + // output := string(output_bytes) + // fmt.Println(output) diags = resp.State.Set(ctx, &data) resp.Diagnostics.Append(diags...) From aea2a9aaf6d8714f076aa0edd4bb5aa19955118a Mon Sep 17 00:00:00 2001 From: Max Thomson Date: Wed, 31 Aug 2022 16:24:58 -0700 Subject: [PATCH 06/10] Dynamic PizzaOptionsAttributes --- internal/provider/data_source_pizza.go | 32 +++++++-- internal/provider/generated.go | 95 +++++++++++++------------- internal/provider/resource_order.go | 9 ++- 3 files changed, 82 insertions(+), 54 deletions(-) diff --git a/internal/provider/data_source_pizza.go b/internal/provider/data_source_pizza.go index 73f9a17..1f2f0bc 100644 --- a/internal/provider/data_source_pizza.go +++ b/internal/provider/data_source_pizza.go @@ -2,12 +2,14 @@ package provider import ( "context" + "encoding/json" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" ) // Ensure provider defined types fully satisfy framework interfaces @@ -18,12 +20,12 @@ type dataSourcePizzaType struct{} var itemOptionsAttributes = tfsdk.SingleNestedAttributes(map[string]tfsdk.Attribute{ "portion": { - Description: "", + Description: "Choose:", Optional: true, Type: types.StringType, }, "weight": { - Description: "", + Description: "Choose:", Optional: true, Type: types.StringType, }, @@ -48,13 +50,18 @@ Provided a Dominos address, this data source returns the store_id of the closest "options": { Description: "", Optional: true, - Attributes: optionsAttributes, + Attributes: tfsdk.SingleNestedAttributes(pizzaOptionsAttributes()), }, "pizza_json": { Description: "The json for the pizza Product.", Type: types.StringType, Computed: true, }, + "quantity": { + Description: "", + Type: types.NumberType, + Optional: true, + }, }, }, nil } @@ -72,6 +79,7 @@ type dataSourcePizzaData struct { Crust types.String `tfsdk:"crust"` Options types.Object `tfsdk:"options"` PizzaJson types.String `tfsdk:"pizza_json"` + Quantity types.Number `tfsdk:"quantity"` } type dataSourcePizza struct { @@ -80,6 +88,7 @@ type dataSourcePizza struct { func (d dataSourcePizza) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { var data dataSourcePizzaData + var PizzaJson Product diags := req.Config.Get(ctx, &data) @@ -93,7 +102,22 @@ func (d dataSourcePizza) Read(ctx context.Context, req datasource.ReadRequest, r // fmt.Printf("Key: %s, Value: %s\n", key, val) // } - data.PizzaJson = types.String{Value: data.Options.String()} + // Pizza Code + // TODO: Validate crust is offered + PizzaJson.Code = data.Size.Value + data.Crust.Value + if data.Quantity.Null { + PizzaJson.Qty = 1 + } else { + qty, _ := data.Quantity.Value.Int64() + PizzaJson.Qty = int(qty) + } + + out, _ := json.Marshal(PizzaJson) + output := string(out) + + tflog.Info(ctx, string(out)) + + data.PizzaJson = types.String{Value: output} diags = resp.State.Set(ctx, &data) resp.Diagnostics.Append(diags...) diff --git a/internal/provider/generated.go b/internal/provider/generated.go index eee4849..3d63c28 100644 --- a/internal/provider/generated.go +++ b/internal/provider/generated.go @@ -1,63 +1,64 @@ -// AUTOGENERATED: DO NOT EDIT -// Update this file from the /tools folder - package provider - import ( + "reflect" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" ) // TODO: Implement https://github.com/hashicorp/terraform-plugin-framework-validators -var optionsAttributes = tfsdk.SingleNestedAttributes(map[string]tfsdk.Attribute{ - "cheese": { - Description: "", - Optional: true, - Attributes: itemOptionsAttributes, - }, - "sauce": { - Description: "", - Optional: true, - Attributes: itemOptionsAttributes, - }, -}) +func pizzaOptionsAttributes() map[string]tfsdk.Attribute { + tmp := &PizzaOptions{} + pizzaOptions := make(map[string]tfsdk.Attribute) + + val := reflect.ValueOf(tmp).Elem() + for i := 0; i < val.NumField(); i++ { + pizzaOptions[val.Type().Field(i).Name] = tfsdk.Attribute{ + Description: val.Type().Field(i).Name + " DESC", + Optional: true, + Attributes: itemOptionsAttributes, + } + } + + return pizzaOptions +} type PizzaOptions struct { - Cheese Option `json:"C"` + Cheese *Option `json:"C,omitempty"` // Pizza Sauces - PizzaSauce Option `json:"X,omitempty"` - BBQSauce Option `json:"Q,omitempty"` - AlfredoSauce Option `json:"Xf,omitempty"` - HeartyMarinaraSauce Option `json:"Xm,omitempty"` - RanchDressing Option `json:"Rd,omitempty"` - GarlicParmesanSauce Option `json:"Xw,omitempty"` + PizzaSauce *Option `json:"X,omitempty"` + BBQSauce *Option `json:"Q,omitempty"` + AlfredoSauce *Option `json:"Xf,omitempty"` + HeartyMarinaraSauce *Option `json:"Xm,omitempty"` + RanchDressing *Option `json:"Rd,omitempty"` + GarlicParmesanSauce *Option `json:"Xw,omitempty"` // Meats - Bacon Option `json:"K,omitempty"` - BeefCrumble Option `json:"B,omitempty"` - BrooklynPepperoni Option `json:"Xp,omitempty"` - Chicken Option `json:"D,omitempty"` - Ham Option `json:"H,omitempty"` - Pepperoni Option `json:"P,omitempty"` - PhillySteak Option `json:"St,omitempty"` - Salami Option `json:"L,omitempty"` - Sausage Option `json:"S,omitempty"` + Bacon *Option `json:"K,omitempty"` + BeefCrumble *Option `json:"B,omitempty"` + BrooklynPepperoni *Option `json:"Xp,omitempty"` + Chicken *Option `json:"D,omitempty"` + Ham *Option `json:"H,omitempty"` + Pepperoni *Option `json:"P,omitempty"` + PhillySteak *Option `json:"St,omitempty"` + Salami *Option `json:"L,omitempty"` + Sausage *Option `json:"S,omitempty"` // Non-meats - BabySpinach Option `json:"Sp,omitempty"` - BlackOlives Option `json:"R,omitempty"` - Cheddar Option `json:"E,omitempty"` - Feta Option `json:"Fe,omitempty"` - GreenOlives Option `json:"V,omitempty"` - GreenPepper Option `json:"G,omitempty"` - HotBananaPeppers Option `json:"Z,omitempty"` - JalapenoPeppers Option `json:"J,omitempty"` - Mushroom Option `json:"M,omitempty"` - Onion Option `json:"O,omitempty"` - ParmesanAsiago Option `json:"Pa,omitempty"` - Pineapple Option `json:"N,omitempty"` - Provolone Option `json:"Cp,omitempty"` - RoastedRedPeppers Option `json:"Rp,omitempty"` - Tomatoes Option `json:"T,omitempty"` + BabySpinach *Option `json:"Sp,omitempty"` + BlackOlives *Option `json:"R,omitempty"` + Cheddar *Option `json:"E,omitempty"` + Feta *Option `json:"Fe,omitempty"` + GreenOlives *Option `json:"V,omitempty"` + GreenPepper *Option `json:"G,omitempty"` + HotBananaPeppers *Option `json:"Z,omitempty"` + JalapenoPeppers *Option `json:"J,omitempty"` + Mushroom *Option `json:"M,omitempty"` + Onion *Option `json:"O,omitempty"` + ParmesanAsiago *Option `json:"Pa,omitempty"` + Pineapple *Option `json:"N,omitempty"` + Provolone *Option `json:"Cp,omitempty"` + RoastedRedPeppers *Option `json:"Rp,omitempty"` + Tomatoes *Option `json:"T,omitempty"` } diff --git a/internal/provider/resource_order.go b/internal/provider/resource_order.go index e40caa6..8ef1c50 100644 --- a/internal/provider/resource_order.go +++ b/internal/provider/resource_order.go @@ -121,9 +121,9 @@ type Product struct { * Extra: "1.5" */ type Option struct { - Left string `json:"1/2"` - All string `json:"1/1"` - Right string `json:"2/2"` + Left string `json:"1/2,omitempty"` + All string `json:"1/1,omitempty"` + Right string `json:"2/2,omitempty"` } type DominosOrderData struct { @@ -191,6 +191,9 @@ func price_order(ctx context.Context, order_data DominosOrderData, client *http. tflog.Info(ctx, "http response:\n"+string(dumprsp)+"\n") validate_response_obj := make(map[string]interface{}) err = json.NewDecoder(val_rsp.Body).Decode(&validate_response_obj) + if err != nil { + return "", fmt.Errorf("JSON Decoder error: %s", err) + } if validate_response_obj["Status"].(float64) == -1 { return "", fmt.Errorf("The Dominos API didn't like this request: %s", validate_response_obj["StatusItems"]) From 29528af90b8c07c31967a2feca5d30ba962edd79 Mon Sep 17 00:00:00 2001 From: Max Thomson Date: Wed, 31 Aug 2022 17:13:34 -0700 Subject: [PATCH 07/10] Beginngins of JSON options --- go.sum | 22 -------- internal/provider/data_source_pizza.go | 69 ++++++++++++++++++++++++-- internal/provider/resource_order.go | 5 ++ 3 files changed, 69 insertions(+), 27 deletions(-) diff --git a/go.sum b/go.sum index 31eaf8a..1e9efd5 100644 --- a/go.sum +++ b/go.sum @@ -111,8 +111,6 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/go-plugin v1.4.4 h1:NVdrSdFRt3SkZtNckJ6tog7gbpRrcbOjQi/rgF7JYWQ= github.com/hashicorp/go-plugin v1.4.4/go.mod h1:viDMjcLJuDui6pXb8U4HVfb8AamCWhHGUjr2IrTF67s= -github.com/hashicorp/go-plugin v1.4.5 h1:oTE/oQR4eghggRg8VY7PAz3dr++VwDNBGCcOfIvHpBo= -github.com/hashicorp/go-plugin v1.4.5/go.mod h1:viDMjcLJuDui6pXb8U4HVfb8AamCWhHGUjr2IrTF67s= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= @@ -120,22 +118,14 @@ github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09 github.com/hashicorp/go-version v1.4.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.5.0 h1:O293SZ2Eg+AAYijkVK3jR786Am1bhDEh2GHT0tIVE5E= github.com/hashicorp/go-version v1.5.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= -github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/hc-install v0.3.2 h1:oiQdJZvXmkNcRcEOOfM5n+VTsvNjWQeOjfAoO6dKSH8= github.com/hashicorp/hc-install v0.3.2/go.mod h1:xMG6Tr8Fw1WFjlxH0A9v61cW15pFwgEGqEz0V4jisHs= -github.com/hashicorp/hc-install v0.4.0 h1:cZkRFr1WVa0Ty6x5fTvL1TuO1flul231rWkGH92oYYk= -github.com/hashicorp/hc-install v0.4.0/go.mod h1:5d155H8EC5ewegao9A4PUTMNPZaq+TbOzkJJZ4vrXeI= github.com/hashicorp/terraform-exec v0.16.1 h1:NAwZFJW2L2SaCBVZoVaH8LPImLOGbPLkSHy0IYbs2uE= github.com/hashicorp/terraform-exec v0.16.1/go.mod h1:aj0lVshy8l+MHhFNoijNHtqTJQI3Xlowv5EOsEaGO7M= -github.com/hashicorp/terraform-exec v0.17.2 h1:EU7i3Fh7vDUI9nNRdMATCEfnm9axzTnad8zszYZ73Go= -github.com/hashicorp/terraform-exec v0.17.2/go.mod h1:tuIbsL2l4MlwwIZx9HPM+LOV9vVyEfBYu2GsO1uH3/8= github.com/hashicorp/terraform-json v0.14.0 h1:sh9iZ1Y8IFJLx+xQiKHGud6/TSUCM0N8e17dKDpqV7s= github.com/hashicorp/terraform-json v0.14.0/go.mod h1:5A9HIWPkk4e5aeeXIBbkcOvaZbIYnAIkEyqP2pNSckM= github.com/hashicorp/terraform-plugin-docs v0.10.1 h1:jiVYfhJ/hVXDAQN2XjLK3WH1A/YHgFCrFXPpxibvmjc= github.com/hashicorp/terraform-plugin-docs v0.10.1/go.mod h1:47ZcsxMUJxAjGzHf+dZ9q78oYf4PeJxO1N+i5XDtXBc= -github.com/hashicorp/terraform-plugin-docs v0.13.0 h1:6e+VIWsVGb6jYJewfzq2ok2smPzZrt1Wlm9koLeKazY= -github.com/hashicorp/terraform-plugin-docs v0.13.0/go.mod h1:W0oCmHAjIlTHBbvtppWHe8fLfZ2BznQbuv8+UD8OucQ= github.com/hashicorp/terraform-plugin-framework v0.11.1 h1:rq8f+TLDO4tJu+n9mMYlDrcRoIdrg0gTUvV2Jr0Ya24= github.com/hashicorp/terraform-plugin-framework v0.11.1/go.mod h1:GENReHOz6GEt8Jk3UN94vk8BdC6irEHFgN3Z9HPhPUU= github.com/hashicorp/terraform-plugin-go v0.14.0 h1:ttnSlS8bz3ZPYbMb84DpcPhY4F5DsQtcAS7cHo8uvP4= @@ -241,8 +231,6 @@ github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLE github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= github.com/zclconf/go-cty v1.10.0 h1:mp9ZXQeIcN8kAwuqorjH+Q+njbJKjLrvB2yIh4q7U+0= github.com/zclconf/go-cty v1.10.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= -github.com/zclconf/go-cty v1.11.0 h1:726SxLdi2SDnjY+BStqB9J1hNp4+2WlzyXLuimibIe0= -github.com/zclconf/go-cty v1.11.0/go.mod h1:s9IfD1LK5ccNMSWCVFCE2rJfHiZgi7JijgeWIMfhLvA= github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -255,8 +243,6 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e h1:T8NU3HyQ8ClP4SEE+KbFlg6n0NhuTsN4MyznaarGsZM= golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d h1:3qF+Z8Hkrw9sOhrFHti9TlB1Hkac1x+DNRkv0XQiFjo= -golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -278,8 +264,6 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k= golang.org/x/net v0.0.0-20220812174116-3211cb980234 h1:RDqmgfe7SvlMWoqC3xwQ2blLO3fcWcxMa3eBLRdRW7E= golang.org/x/net v0.0.0-20220812174116-3211cb980234/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= -golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b h1:ZmngSVLe/wycRns9MKikG9OWIEjGcGAkacif7oYQaUY= -golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -310,8 +294,6 @@ golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2 h1:fqTvyMIIj+HRzMmnzr9NtpHP6uVpvB5fkHcgPDC4nu8= golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 h1:UiNENfZ8gDvpiWw7IpOMQ27spWmThO1RwwdQVbJahJM= -golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -337,8 +319,6 @@ google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfG google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20220817144833-d7fd3f11b9b1 h1:C2UVWqrgLYKrT5nh5oU6hLRm1AeEklCK5eloQA1NtFY= google.golang.org/genproto v0.0.0-20220817144833-d7fd3f11b9b1/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= -google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc h1:Nf+EdcTLHR8qDNN/KfkQL0u0ssxt9OhbaWCl5C0ucEI= -google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= @@ -347,8 +327,6 @@ google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTp google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.48.0 h1:rQOsyJ/8+ufEDJd/Gdsz7HG220Mh9HAhFHRGnIjda0w= google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= -google.golang.org/grpc v1.49.0 h1:WTLtQzmQori5FUH25Pq4WT22oCsv8USpQ+F6rqtsmxw= -google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/internal/provider/data_source_pizza.go b/internal/provider/data_source_pizza.go index 1f2f0bc..507b5ba 100644 --- a/internal/provider/data_source_pizza.go +++ b/internal/provider/data_source_pizza.go @@ -3,6 +3,7 @@ package provider import ( "context" "encoding/json" + "fmt" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/diag" @@ -88,7 +89,7 @@ type dataSourcePizza struct { func (d dataSourcePizza) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { var data dataSourcePizzaData - var PizzaJson Product + var pizzaJson Product diags := req.Config.Get(ctx, &data) @@ -104,15 +105,73 @@ func (d dataSourcePizza) Read(ctx context.Context, req datasource.ReadRequest, r // Pizza Code // TODO: Validate crust is offered - PizzaJson.Code = data.Size.Value + data.Crust.Value + pizzaJson.Code = data.Size.Value + data.Crust.Value if data.Quantity.Null { - PizzaJson.Qty = 1 + pizzaJson.Qty = 1 } else { qty, _ := data.Quantity.Value.Int64() - PizzaJson.Qty = int(qty) + pizzaJson.Qty = int(qty) } - out, _ := json.Marshal(PizzaJson) + if !data.Options.IsNull() { + var tmp1 TFPizzaOption + mapTest := make(map[string]string) + + // data.Options.AttrTypes["salami"] = types.String{Value: "TELKSLKFSDKLJFSDLK"} + + // salami, potion/weight + for optionName, optionVal := range data.Options.Attrs { + if optionVal.IsNull() { + continue + } + + err := json.Unmarshal([]byte(optionVal.String()), &tmp1) + if err != nil { + resp.Diagnostics.AddError("Cannot unmarshall Stuff", fmt.Sprintf("%s", err)) + return + } + + var key string + if tmp1.Portion != nil { + switch *tmp1.Portion { + case "all": + key = "1/1" + case "left": + key = "1/2" + case "right": + key = "2/2" + default: + resp.Diagnostics.AddError("Portion not valid:", fmt.Sprintf("%s", *tmp1.Portion)) + return + } + } else { + key = "1/1" + } + + var weight string + if tmp1.Weight != nil { + switch *tmp1.Weight { + case "light": + weight = "0.5" + case "normal": + weight = "1" + case "extra": + weight = "1.5" + default: + resp.Diagnostics.AddError("Weight not valid:", fmt.Sprintf("%s", *tmp1.Weight)) + return + } + } else { + weight = "1" + } + + mapTest[optionName] = fmt.Sprintf("{\"%s\":\"%s\"}", key, weight) + // tflog.Info(ctx, key+val.String()) + } + tflog.Info(ctx, fmt.Sprint(mapTest)) + } + + out, _ := json.Marshal(pizzaJson) output := string(out) tflog.Info(ctx, string(out)) diff --git a/internal/provider/resource_order.go b/internal/provider/resource_order.go index 8ef1c50..23fd409 100644 --- a/internal/provider/resource_order.go +++ b/internal/provider/resource_order.go @@ -126,6 +126,11 @@ type Option struct { Right string `json:"2/2,omitempty"` } +type TFPizzaOption struct { + Portion *string `json:"portion,omitempty"` + Weight *string `json:"weight,omitempty"` +} + type DominosOrderData struct { Order struct { Address Address `json:"Address"` From ce6c79c4c1620504d5e101e652cacf3763980352 Mon Sep 17 00:00:00 2001 From: Max Thomson Date: Wed, 31 Aug 2022 17:33:18 -0700 Subject: [PATCH 08/10] CUSTOM PIZZA WORKS!!! --- go.mod | 1 + go.sum | 2 ++ internal/provider/data_source_pizza.go | 35 ++++++++++---------------- internal/provider/resource_order.go | 6 ++--- 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index 75f91a3..849e3b1 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/hashicorp/terraform-plugin-docs v0.10.1 github.com/hashicorp/terraform-plugin-framework v0.11.1 github.com/hashicorp/terraform-plugin-log v0.7.0 + github.com/mitchellh/mapstructure v1.5.0 ) require ( diff --git a/go.sum b/go.sum index 1e9efd5..9c2832e 100644 --- a/go.sum +++ b/go.sum @@ -180,6 +180,8 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU= github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= diff --git a/internal/provider/data_source_pizza.go b/internal/provider/data_source_pizza.go index 507b5ba..dc9bbaf 100644 --- a/internal/provider/data_source_pizza.go +++ b/internal/provider/data_source_pizza.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/mitchellh/mapstructure" ) // Ensure provider defined types fully satisfy framework interfaces @@ -99,10 +100,6 @@ func (d dataSourcePizza) Read(ctx context.Context, req datasource.ReadRequest, r return } - // for key, val := range data.Options.Attrs { - // fmt.Printf("Key: %s, Value: %s\n", key, val) - // } - // Pizza Code // TODO: Validate crust is offered pizzaJson.Code = data.Size.Value + data.Crust.Value @@ -115,11 +112,10 @@ func (d dataSourcePizza) Read(ctx context.Context, req datasource.ReadRequest, r if !data.Options.IsNull() { var tmp1 TFPizzaOption - mapTest := make(map[string]string) + mapTest := make(map[string]Option) - // data.Options.AttrTypes["salami"] = types.String{Value: "TELKSLKFSDKLJFSDLK"} + pizzaOptionMap := make(map[string]string) - // salami, potion/weight for optionName, optionVal := range data.Options.Attrs { if optionVal.IsNull() { continue @@ -132,20 +128,10 @@ func (d dataSourcePizza) Read(ctx context.Context, req datasource.ReadRequest, r } var key string - if tmp1.Portion != nil { - switch *tmp1.Portion { - case "all": - key = "1/1" - case "left": - key = "1/2" - case "right": - key = "2/2" - default: - resp.Diagnostics.AddError("Portion not valid:", fmt.Sprintf("%s", *tmp1.Portion)) - return - } + if tmp1.Portion == nil { + key = "all" } else { - key = "1/1" + key = *tmp1.Portion } var weight string @@ -165,10 +151,15 @@ func (d dataSourcePizza) Read(ctx context.Context, req datasource.ReadRequest, r weight = "1" } - mapTest[optionName] = fmt.Sprintf("{\"%s\":\"%s\"}", key, weight) - // tflog.Info(ctx, key+val.String()) + pizzaOptionMap[key] = weight + var pizzaOption Option + mapstructure.Decode(pizzaOptionMap, &pizzaOption) + + mapTest[optionName] = pizzaOption } tflog.Info(ctx, fmt.Sprint(mapTest)) + + mapstructure.Decode(mapTest, &pizzaJson.Options) } out, _ := json.Marshal(pizzaJson) diff --git a/internal/provider/resource_order.go b/internal/provider/resource_order.go index 23fd409..9d862dd 100644 --- a/internal/provider/resource_order.go +++ b/internal/provider/resource_order.go @@ -121,9 +121,9 @@ type Product struct { * Extra: "1.5" */ type Option struct { - Left string `json:"1/2,omitempty"` - All string `json:"1/1,omitempty"` - Right string `json:"2/2,omitempty"` + Left string `json:"1/2,omitempty" mapstructure:"left"` + All string `json:"1/1,omitempty" mapstructure:"all"` + Right string `json:"2/2,omitempty" mapstructure:"right"` } type TFPizzaOption struct { From 42cbf06e78ec6defbcb72e70126d404c4ff9899a Mon Sep 17 00:00:00 2001 From: Max Thomson Date: Wed, 31 Aug 2022 18:09:14 -0700 Subject: [PATCH 09/10] ORDERS WORKKKKKKK, WOOOOOOOOOOOOOOOOOT --- Makefile | 4 ++-- internal/provider/resource_order.go | 24 ++++++++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 05a275b..e1493bd 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,11 @@ build: *.go run: clear - rm -rf .terraform.lock.hcl + rm -rf .terraform.lock.hcl terraform.tfstat* make build terraform init -plugin-dir .terraform.d/plugins/ TF_LOG=INFO terraform apply -auto-approve - rm -rf terraform.tfstat* + rm -rf .terraform.lock.hcl terraform.tfstat* watch: while true; do \ diff --git a/internal/provider/resource_order.go b/internal/provider/resource_order.go index 9d862dd..ab7eddf 100644 --- a/internal/provider/resource_order.go +++ b/internal/provider/resource_order.go @@ -43,8 +43,8 @@ You should receive an email confirmation almost instantly, and that email will h Required: true, Type: types.StringType, }, - "item_codes": { - Description: "An array of menu items to order.", + "items": { + Description: "An array of menu item objects to order.", Required: true, Type: types.ListType{ ElemType: types.StringType, @@ -74,7 +74,7 @@ func (t resourceOrderType) NewResource(ctx context.Context, in provider.Provider type resourceOrderData struct { AddressAPIObj types.String `tfsdk:"address_api_object"` - ItemCodes types.List `tfsdk:"item_codes"` + Items types.List `tfsdk:"items"` StoreID types.Int64 `tfsdk:"store_id"` TotalPrice types.Number `tfsdk:"total_price"` } @@ -149,7 +149,7 @@ type DominosOrderData struct { Phone string `json:"Phone"` PhonePrefix string `json:"PhonePrefix" default:""` Products []Product `json:"Products"` - ServiceMethod string `json:"ServiceMethod" default:"Delivery"` + ServiceMethod string `json:"ServiceMethod" default:"Carryout"` // TODO: Option for Delivery SourceOrganizationURI string `json:"SourceOrganizationURI" default:"order.dominos.com"` StoreID string `json:"StoreID"` Tags struct{} `json:"Tags"` @@ -255,6 +255,22 @@ func (r resourceOrder) Create(ctx context.Context, req resource.CreateRequest, r * Add items to Products */ + for _, jsonString := range data.Items.Elems { + jsonUnquoted := jsonString.String()[1 : len(jsonString.String())-1] + + jsonCleaned := strings.ReplaceAll(jsonUnquoted, "\\", "") + + tflog.Info(ctx, jsonCleaned) + + var tmpProduct Product + err := json.Unmarshal([]byte(jsonCleaned), &tmpProduct) + if err != nil { + resp.Diagnostics.AddError("Cannot unmarshall Stuff", fmt.Sprintf("%s", err)) + return + } + order_data.Order.Products = append(order_data.Order.Products, tmpProduct) + } + /* * Price Order */ From 486bec668226b5c3552b01e3990748100fe604c8 Mon Sep 17 00:00:00 2001 From: Max Thomson Date: Sat, 3 Sep 2022 19:22:00 -0700 Subject: [PATCH 10/10] Empty options + error handling --- internal/provider/data_source_pizza.go | 30 ++++++++++++++++++-------- internal/provider/resource_order.go | 10 ++++----- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/internal/provider/data_source_pizza.go b/internal/provider/data_source_pizza.go index dc9bbaf..6338e15 100644 --- a/internal/provider/data_source_pizza.go +++ b/internal/provider/data_source_pizza.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "strings" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/diag" @@ -114,27 +115,39 @@ func (d dataSourcePizza) Read(ctx context.Context, req datasource.ReadRequest, r var tmp1 TFPizzaOption mapTest := make(map[string]Option) - pizzaOptionMap := make(map[string]string) - for optionName, optionVal := range data.Options.Attrs { + pizzaOptionMap := make(map[string]string) + var key string + var weight string + + optionValStr := strings.ReplaceAll(optionVal.String(), "", "null") + if optionVal.IsNull() { continue } - err := json.Unmarshal([]byte(optionVal.String()), &tmp1) + err := json.Unmarshal([]byte(optionValStr), &tmp1) if err != nil { resp.Diagnostics.AddError("Cannot unmarshall Stuff", fmt.Sprintf("%s", err)) return } - var key string - if tmp1.Portion == nil { - key = "all" + if tmp1.Portion != nil { + switch *tmp1.Portion { + case "left": + key = "left" + case "all": + key = "all" + case "right": + key = "right" + default: + resp.Diagnostics.AddError("Portion not valid:", fmt.Sprintf("%s", *tmp1.Weight)) + return + } } else { - key = *tmp1.Portion + key = "all" } - var weight string if tmp1.Weight != nil { switch *tmp1.Weight { case "light": @@ -157,7 +170,6 @@ func (d dataSourcePizza) Read(ctx context.Context, req datasource.ReadRequest, r mapTest[optionName] = pizzaOption } - tflog.Info(ctx, fmt.Sprint(mapTest)) mapstructure.Decode(mapTest, &pizzaJson.Options) } diff --git a/internal/provider/resource_order.go b/internal/provider/resource_order.go index ab7eddf..bb15dae 100644 --- a/internal/provider/resource_order.go +++ b/internal/provider/resource_order.go @@ -170,7 +170,7 @@ func price_order(ctx context.Context, order_data DominosOrderData, client *http. val_req, err := http.NewRequest("POST", "https://order.dominos.ca/power/price-order", strings.NewReader(string(output_bytes))) if err != nil { - return "", fmt.Errorf("HTTP Error: %s", err) + return "", fmt.Errorf("HTTP NewRequest Error: %s", err) } val_req.Header.Set("Referer", "https://order.dominos.ca/en/pages/order/") @@ -178,19 +178,19 @@ func price_order(ctx context.Context, order_data DominosOrderData, client *http. dumpreq, err := httputil.DumpRequest(val_req, true) if err != nil { - return "", fmt.Errorf("HTTP Error: %s", err) + return "", fmt.Errorf("HTTP Dump Request Error: %s", err) } tflog.Info(ctx, "http request:\n"+string(dumpreq)+"\n") val_rsp, err := client.Do(val_req) if err != nil { - return "", fmt.Errorf("HTTP Error: %s", err) + return "", fmt.Errorf("HTTP Request Error: %s", err) } dumprsp, err := httputil.DumpResponse(val_rsp, true) if err != nil { - return "", fmt.Errorf("HTTP Error: %s", err) + return "", fmt.Errorf("HTTP Dump Response Error: %s", err) } tflog.Info(ctx, "http response:\n"+string(dumprsp)+"\n") @@ -260,8 +260,6 @@ func (r resourceOrder) Create(ctx context.Context, req resource.CreateRequest, r jsonCleaned := strings.ReplaceAll(jsonUnquoted, "\\", "") - tflog.Info(ctx, jsonCleaned) - var tmpProduct Product err := json.Unmarshal([]byte(jsonCleaned), &tmpProduct) if err != nil {