Skip to content

Commit

Permalink
cleanup + review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
danawillow committed May 17, 2018
1 parent 86b5cc9 commit 40a38d5
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ overrides: !ruby/object:Provider::ResourceOverrides
required: false # the provider-default value will be used if not specified
default: !ruby/object:Provider::Terraform::Default
from_api: true
custom_flatten: 'templates/terraform/custom_flatten/region_name_only.erb'
custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb'
forwardingRules: !ruby/object:Provider::Terraform::PropertyOverride
exclude: true
tunnels: !ruby/object:Provider::Terraform::PropertyOverride
Expand Down
18 changes: 13 additions & 5 deletions products/redis/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ versions:
name: beta
base_url: https://redis.googleapis.com/v1beta1/
scopes:
# TODO this is fake and made up but MM requires it
- https://www.googleapis.com/auth/redis
- https://www.googleapis.com/auth/cloud-platform
objects:
- !ruby/object:Api::Resource
name: 'Instance'
Expand All @@ -30,7 +29,12 @@ objects:
self_link: projects/{{project}}/locations/{{region}}/instances/{{name}}
description: |
A Google Cloud Redis instance.
input: true
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Official Documentation':
'https://cloud.google.com/memorystore/docs/redis/'
api: 'https://cloud.google.com/memorystore/docs/redis/reference/rest/'
input: true # TODO(danawillow): support for updates
<%= indent(compile_file({}, 'templates/regional_async.yaml.erb'), 4) %>
parameters:
- !ruby/object:Api::Type::String # TODO: resourceref?
Expand Down Expand Up @@ -120,8 +124,12 @@ objects:
network.
- !ruby/object:Api::Type::Enum
name: tier
description: The service tier of the instance. #TODO describe values
description: |
The service tier of the instance. Must be one of these values:
- BASIC: standalone instance
- STANDARD_HA: highly available primary/replica instances
values:
- :BASIC
- :STANDARD_HA
required: true
default_value: :BASIC
9 changes: 3 additions & 6 deletions products/redis/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ overrides: !ruby/object:Provider::ResourceOverrides
Instance: !ruby/object:Provider::Terraform::ResourceOverride
id_format: "{{project}}/{{region}}/{{name}}"
custom_code: !ruby/object:Provider::Terraform::CustomCode
decoder: 'templates/terraform/redis/instance_decoder.erb'
decoder: 'templates/terraform/decoders/redis_instance.erb'
properties:
authorizedNetwork: !ruby/object:Provider::Terraform::PropertyOverride
default: !ruby/object:Provider::Terraform::Default
Expand All @@ -25,11 +25,8 @@ overrides: !ruby/object:Provider::ResourceOverrides
default: !ruby/object:Provider::Terraform::Default
from_api: true
name: !ruby/object:Provider::Terraform::PropertyOverride
custom_expand: 'templates/terraform/redis/expand_name.erb'
custom_flatten: 'templates/terraform/redis/flatten_name.erb'
redisVersion: !ruby/object:Provider::Terraform::PropertyOverride
default: !ruby/object:Provider::Terraform::Default
from_api: true
custom_expand: 'templates/terraform/custom_expand/redis_instance_name.erb'
custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb'
region: !ruby/object:Provider::Terraform::PropertyOverride
required: false
default: !ruby/object:Provider::Terraform::Default
Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions templates/terraform/redis/flatten_name.erb

This file was deleted.

30 changes: 14 additions & 16 deletions templates/terraform/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"net/http"
urllib "net/url"
"reflect"
"regexp"
"strings"
Expand Down Expand Up @@ -76,23 +75,23 @@ func isEmptyValue(v reflect.Value) bool {
return false
}

func Post(config *Config, url string, body map[string]interface{}) (map[string]interface{}, error) {
return sendRequest(config, "POST", url, body)
func Post(config *Config, rawurl string, body map[string]interface{}) (map[string]interface{}, error) {
return sendRequest(config, "POST", raw, body)
}

func Get(config *Config, url string) (map[string]interface{}, error) {
return sendRequest(config, "GET", url, nil)
func Get(config *Config, rawurl string) (map[string]interface{}, error) {
return sendRequest(config, "GET", rawurl, nil)
}

func Put(config *Config, url string, body map[string]interface{}) (map[string]interface{}, error) {
return sendRequest(config, "PUT", url, body)
func Put(config *Config, rawurl string, body map[string]interface{}) (map[string]interface{}, error) {
return sendRequest(config, "PUT", rawurl, body)
}

func Delete(config *Config, url string) (map[string]interface{}, error) {
return sendRequest(config, "DELETE", url, nil)
func Delete(config *Config, rawurl string) (map[string]interface{}, error) {
return sendRequest(config, "DELETE", rawurl, nil)
}

func sendRequest(config *Config, method, url string, body map[string]interface{}) (map[string]interface{}, error) {
func sendRequest(config *Config, method, rawurl string, body map[string]interface{}) (map[string]interface{}, error) {
reqHeaders := make(http.Header)
reqHeaders.Set("User-Agent", config.userAgent)
reqHeaders.Set("Content-Type", "application/json")
Expand All @@ -106,16 +105,15 @@ func sendRequest(config *Config, method, url string, body map[string]interface{}
}
}

u, err := urllib.Parse(url)
u, err := urllib.Parse(rawurl)
if err != nil {
return nil, err
}
q := u.Query()
q.Set("alt", "json")
u.RawQuery = q.Encode()

queries := u.Query()
queries.Add("alt", "json")
newUrl := u.Scheme + "://" + u.Host + u.Path + "?" + queries.Encode()

req, err := http.NewRequest(method, newUrl, &buf)
req, err := http.NewRequest(method, u.String(), &buf)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 40a38d5

Please sign in to comment.