Skip to content

Commit

Permalink
Update to 0.8.9 (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyiliev authored Sep 30, 2024
1 parent 0638021 commit 03e2f60
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 56 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
CHANGELOG
=========
## 0.3.9 2024-09-30
Update to Terraform Provider [0.8.9](https://github.com/MaterializeInc/terraform-provider-materialize/releases/tag/v0.8.9).

## 0.3.8 2024-08-26
Update to Terraform Provider [0.8.8](https://github.com/MaterializeInc/terraform-provider-materialize/releases/tag/v0.8.8).

Expand Down
4 changes: 2 additions & 2 deletions examples/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ services:
healthcheck: {test: curl -f localhost:6878/api/readyz, interval: 1s, start_period: 35s}

test-certs:
image: materialize/test-certs:devel-67251c0eb77e76eb6ef81bb78e2fb128dea2b1fb
image: materialize/test-certs:v0.116.0
volumes:
- certs:/secrets

frontegg:
image: materialize/frontegg-mock:devel-67251c0eb77e76eb6ef81bb78e2fb128dea2b1fb
image: materialize/frontegg-mock:v0.116.0
depends_on:
- test-certs
ports:
Expand Down
4 changes: 2 additions & 2 deletions examples/mocks/cloud/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Start from the official Golang base image
FROM golang:1.20 as builder
FROM golang:1.22 as builder

# Set the Current Working Directory inside the container
WORKDIR /app
Expand Down Expand Up @@ -27,4 +27,4 @@ WORKDIR /root/
COPY --from=builder /app/mockserver .

# Command to run the executable
CMD ["./mockserver"]
CMD ["./mockserver"]
2 changes: 1 addition & 1 deletion examples/mocks/cloud/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module cloud-mockserver

go 1.20
go 1.22
2 changes: 0 additions & 2 deletions examples/mocks/cloud/go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
github.com/golang-jwt/jwt/v5 v5.1.0 h1:UGKbA/IPjtS6zLcdB7i5TyACMgSbOTiR8qzXgw8HWQU=
github.com/golang-jwt/jwt/v5 v5.1.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
173 changes: 128 additions & 45 deletions examples/mocks/cloud/mock_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,25 @@ import (
"fmt"
"log"
"net/http"
"os"
"time"
)

type RegionConfig struct {
ID string
Name string
Hostname string
SqlPort string
HttpPort string
EnabledAt time.Time
}

type Config struct {
CloudHostname string
CloudPort string
Regions []RegionConfig
}

type Region struct {
ID string `json:"id"`
Name string `json:"name"`
Expand All @@ -31,62 +48,128 @@ type CloudProviderResponse struct {
NextCursor string `json:"nextCursor,omitempty"`
}

// Mock data
var regions = []Region{
{
ID: "aws/us-east-1",
Name: "us-east-1",
CloudProvider: "aws",
URL: "http://cloud:3001",
RegionInfo: &RegionInfo{
SqlAddress: "materialized:6877",
HttpAddress: "materialized:6875",
Resolvable: true,
EnabledAt: "2023-01-01T00:00:00Z",
},
},
// Add more mock regions if needed later
func getEnv(key, fallback string) string {
if value, exists := os.LookupEnv(key); exists {
return value
}
return fallback
}

func main() {
http.HandleFunc("/api/region", regionHandler)
http.HandleFunc("/api/cloud-regions", cloudRegionsHandler)

fmt.Println("Mock Cloud API server is running at http://localhost:3001")
log.Fatal(http.ListenAndServe(":3001", nil))
func loadConfig() Config {
return Config{
CloudHostname: getEnv("CLOUD_HOSTNAME", "localhost"),
CloudPort: getEnv("CLOUD_PORT", "3001"),
Regions: []RegionConfig{
{
ID: "aws/us-east-1",
Name: "us-east-1",
Hostname: getEnv("US_EAST_1_HOSTNAME", "materialized"),
SqlPort: getEnv("US_EAST_1_SQL_PORT", "6877"),
HttpPort: getEnv("US_EAST_1_HTTP_PORT", "6875"),
EnabledAt: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC),
},
{
ID: "aws/us-west-2",
Name: "us-west-2",
Hostname: getEnv("US_WEST_2_HOSTNAME", "materialized2"),
SqlPort: getEnv("US_WEST_2_SQL_PORT", "7877"),
HttpPort: getEnv("US_WEST_2_HTTP_PORT", "7875"),
EnabledAt: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC),
},
},
}
}

func regionHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
mockRegion := CloudRegion{
func createRegions(config Config) []Region {
regions := make([]Region, len(config.Regions))
for i, r := range config.Regions {
regions[i] = Region{
ID: r.ID,
Name: r.Name,
CloudProvider: "aws",
URL: fmt.Sprintf("http://%s:%s/%s", config.CloudHostname, config.CloudPort, r.Name),
RegionInfo: &RegionInfo{
SqlAddress: "materialized:6877",
HttpAddress: "materialized:6875",
SqlAddress: fmt.Sprintf("%s:%s", r.Hostname, r.SqlPort),
HttpAddress: fmt.Sprintf("%s:%s", r.Hostname, r.HttpPort),
Resolvable: true,
EnabledAt: "2023-01-01T00:00:00Z",
EnabledAt: r.EnabledAt.Format(time.RFC3339),
},
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(mockRegion)
case http.MethodPatch:
enabledRegion := CloudRegion{RegionInfo: nil}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(enabledRegion)
case http.MethodDelete:
w.WriteHeader(http.StatusAccepted)
default:
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
}
return regions
}

func cloudRegionsHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
func main() {
config := loadConfig()
regions := createRegions(config)

http.HandleFunc("/api/cloud-regions", cloudRegionsHandler(regions))
for _, region := range regions {
http.HandleFunc(fmt.Sprintf("/%s/api/region", region.Name), regionHandler(region.ID, regions))
}
response := CloudProviderResponse{
Data: regions,

fmt.Printf("Mock Cloud API server is running at http://%s:%s\n", config.CloudHostname, config.CloudPort)
log.Fatal(http.ListenAndServe(":"+config.CloudPort, nil))
}

func regionHandler(regionID string, regions []Region) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
log.Printf("Received %s request to %s", r.Method, r.URL.Path)

var selectedRegion *Region
for _, region := range regions {
if region.ID == regionID {
selectedRegion = &region
break
}
}

if selectedRegion == nil {
http.Error(w, "Region not found", http.StatusNotFound)
return
}

switch r.Method {
case http.MethodGet:
mockRegion := CloudRegion{
RegionInfo: selectedRegion.RegionInfo,
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(mockRegion); err != nil {
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
}

case http.MethodPatch:
var updatedRegion RegionInfo
if err := json.NewDecoder(r.Body).Decode(&updatedRegion); err != nil {
http.Error(w, "Invalid request body", http.StatusBadRequest)
return
}
selectedRegion.RegionInfo = &updatedRegion
w.WriteHeader(http.StatusOK)

case http.MethodDelete:
selectedRegion.RegionInfo = nil
w.WriteHeader(http.StatusAccepted)

default:
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
}
}
}

func cloudRegionsHandler(regions []Region) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
response := CloudProviderResponse{
Data: regions,
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(response); err != nil {
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
}
}
json.NewEncoder(w).Encode(response)
}
4 changes: 2 additions & 2 deletions provider/go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module github.com/MaterializeInc/pulumi-materialize/provider

go 1.20
go 1.22

replace github.com/hashicorp/terraform-plugin-sdk/v2 => github.com/pulumi/terraform-plugin-sdk/v2 v2.0.0-20240520223432-0c0bf0d65f10

require (
github.com/MaterializeInc/terraform-provider-materialize v0.8.8
github.com/MaterializeInc/terraform-provider-materialize v0.8.9
github.com/pulumi/pulumi-terraform-bridge/v3 v3.59.0
github.com/pulumi/pulumi/sdk/v3 v3.81.0
)
Expand Down
Loading

0 comments on commit 03e2f60

Please sign in to comment.