Skip to content

Commit

Permalink
Merge branch 'master' into refactor/remove-symlinks
Browse files Browse the repository at this point in the history
Conflicts:
	openapi/openapiutils/openapi_utils.go
  • Loading branch information
dikhan committed Oct 7, 2018
2 parents a8b2482 + 0023591 commit d0b7cbb
Show file tree
Hide file tree
Showing 59 changed files with 10,303 additions and 381 deletions.
4 changes: 2 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Proposed changes

Please add as many details as possible about the change here. Does this Pull Request resolve any open issue? If so, please
make sure to link to that issue:
Please add as many details as possible about the change here. Does this Pull Request resolve any open issue?
If so, please make sure to link to that issue:

Fixes: #

Expand Down
17 changes: 16 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@
[[constraint]]
branch = "master"
name = "github.com/iancoleman/strcase"

[[constraint]]
name = "github.com/hashicorp/logutils"
version = "1.0.0"
10 changes: 2 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ fmt:
# make vet
vet:
@echo "[INFO] Running go vet on the current directory"
@go vet $(TEST_PACKAGES) ; if [ $$? -eq 1 ]; then \
echo "[ERROR] Vet found suspicious constructs. Please fix the reported constructs before submitting code for review"; \
exit 1; \
fi
@go vet $(TEST_PACKAGES)

# make lint
lint:
Expand All @@ -40,10 +37,7 @@ lint:
# make test
test: fmt vet lint
@echo "[INFO] Testing $(TF_OPENAPI_PROVIDER_PLUGIN_NAME)"
@go test -v -cover $(TEST_PACKAGES) ; if [ $$? -eq 1 ]; then \
echo "[ERROR] Test returned with failures. Please go through the different scenarios and fix the tests that are failing"; \
exit 1; \
fi
@go test -v -cover $(TEST_PACKAGES)

pre-requirements:
@echo "[INFO] Creating $(TF_INSTALLED_PLUGINS_PATH) if it does not exist"
Expand Down
309 changes: 308 additions & 1 deletion docs/how_to.md

Large diffs are not rendered by default.

30 changes: 18 additions & 12 deletions examples/swaggercodegen/api/api/cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@ import (
"log"
)

var db = map[string]*ContentDeliveryNetwork{}
var db = map[string]*ContentDeliveryNetworkV1{}

func ContentDeliveryNetworkCreateV1(w http.ResponseWriter, r *http.Request) {
if AuthenticateRequest(r, w) != nil {
return
}
xRequestID := r.Header.Get("X-Request-ID")
log.Printf("Header [X-Request-ID]: %s", xRequestID)
cdn := &ContentDeliveryNetwork{}
cdn := &ContentDeliveryNetworkV1{}
err := readRequest(r, cdn)
if err != nil {
sendErrorResponse(http.StatusBadRequest, err.Error(), w)
return
}
cdn.Id = uuid.New()
cdn.ObjectNestedSchemeProperty = &ContentDeliveryNetworkV1ObjectNestedSchemeProperty{
Name: "autogenerated name",
}
db[cdn.Id] = cdn
log.Printf("POST [%+v\n]", cdn)
sendResponse(http.StatusCreated, w, cdn)
}

Expand All @@ -34,7 +36,6 @@ func ContentDeliveryNetworkGetV1(w http.ResponseWriter, r *http.Request) {
return
}
cdn, err := retrieveCdn(r)
log.Printf("GET [%+v\n]", cdn)
if err != nil {
sendErrorResponse(http.StatusNotFound, err.Error(), w)
return
Expand All @@ -51,16 +52,22 @@ func ContentDeliveryNetworkUpdateV1(w http.ResponseWriter, r *http.Request) {
sendErrorResponse(http.StatusNotFound, err.Error(), w)
return
}
newCDN := &ContentDeliveryNetwork{}
newCDN := &ContentDeliveryNetworkV1{}
err = readRequest(r, newCDN)
if err != nil {
sendErrorResponse(http.StatusBadRequest, err.Error(), w)
return
}
log.Printf("UPDATE [%+v\n]", newCDN)
cdn.Id = cdn.Id
db[cdn.Id] = newCDN
sendResponse(http.StatusOK, w, newCDN)

cdn.Ips = newCDN.Ips
cdn.Hostnames = newCDN.Hostnames
cdn.ExampleInt = newCDN.ExampleInt
cdn.ExampleNumber = newCDN.ExampleNumber
cdn.ExampleBoolean = newCDN.ExampleBoolean
cdn.ObjectProperty = newCDN.ObjectProperty

db[cdn.Id] = cdn
sendResponse(http.StatusOK, w, cdn)
}

func ContentDeliveryNetworkDeleteV1(w http.ResponseWriter, r *http.Request) {
Expand All @@ -73,11 +80,10 @@ func ContentDeliveryNetworkDeleteV1(w http.ResponseWriter, r *http.Request) {
return
}
delete(db, cdn.Id)
log.Printf("DELETE [%s]", cdn.Id)
updateResponseHeaders(http.StatusNoContent, w)
sendResponse(http.StatusNoContent, w, nil)
}

func retrieveCdn(r *http.Request) (*ContentDeliveryNetwork, error) {
func retrieveCdn(r *http.Request) (*ContentDeliveryNetworkV1, error) {
id := strings.TrimPrefix(r.URL.Path, "/v1/cdns/")
if id == "" {
return nil, fmt.Errorf("cdn id path param not provided")
Expand Down
8 changes: 6 additions & 2 deletions examples/swaggercodegen/api/api/content_delivery_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

package api

type ContentDeliveryNetwork struct {
type ContentDeliveryNetworkV1 struct {

Id string `json:"id,omitempty"`

Expand All @@ -25,4 +25,8 @@ type ContentDeliveryNetwork struct {
ExampleNumber float32 `json:"exampleNumber,omitempty"`

ExampleBoolean bool `json:"example_boolean,omitempty"`
}

ObjectProperty *ObjectProperty `json:"object_property"`

ObjectNestedSchemeProperty *ContentDeliveryNetworkV1ObjectNestedSchemeProperty `json:"object_nested_scheme_property,omitempty"`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Dummy Service Provider generated using 'swaggercodegen' that has two resources 'cdns' and 'lbs' which are terraform compliant
*
* This service provider allows the creation of fake 'cdns' and 'lbs' resources
*
* API version: 1.0.0
* Contact: [email protected]
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/

package api

type ContentDeliveryNetworkV1ObjectNestedSchemeProperty struct {

Name string `json:"name"`
}
20 changes: 14 additions & 6 deletions examples/swaggercodegen/api/api/http_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
)

func readRequest(r *http.Request, in interface{}) error {
Expand All @@ -21,17 +22,24 @@ func readRequest(r *http.Request, in interface{}) error {
func sendResponse(httpResponseStatusCode int, w http.ResponseWriter, out interface{}) {
var resBody []byte
var err error
if resBody, err = json.Marshal(out); err != nil {
msg := fmt.Sprintf("internal server error - %s", err)
sendErrorResponse(http.StatusInternalServerError, msg, w)
if out != nil {
if resBody, err = json.Marshal(out); err != nil {
msg := fmt.Sprintf("internal server error - %s", err)
sendErrorResponse(http.StatusInternalServerError, msg, w)
}
}
w.WriteHeader(httpResponseStatusCode)
w.Write(resBody)
updateResponseHeaders(httpResponseStatusCode, w)
if len(resBody) > 0 {
w.Write(resBody)
}
log.Printf("Response sent '%+v'", out)
}

func sendErrorResponse(httpStatusCode int, message string, w http.ResponseWriter) {
updateResponseHeaders(httpStatusCode, w)
w.Write([]byte(fmt.Sprintf(`{"code":"%d", "message": "%s"}`, httpStatusCode, message)))
err := fmt.Sprintf(`{"code":"%d", "message": "%s"}`, httpStatusCode, message)
w.Write([]byte(err))
log.Printf("Error Response sent '%s'", err)
}

func updateResponseHeaders(httpStatusCode int, w http.ResponseWriter) {
Expand Down
Loading

0 comments on commit d0b7cbb

Please sign in to comment.