-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
217 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,5 @@ node_modules/ | |
.vscode/ | ||
|
||
assay-it/ | ||
|
||
cdk.context.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/aws/aws-sdk-go-v2/config" | ||
"github.com/fogfish/blueprint-serverless-golang/http/curl" | ||
"github.com/fogfish/gurl/awsapi" | ||
"github.com/fogfish/gurl/v2/http" | ||
) | ||
|
||
// go run main.go https://XXXXXXXXXX.execute-api.eu-west-1.amazonaws.com | ||
func main() { | ||
fmt.Println(os.Args) | ||
|
||
cfg, err := config.LoadDefaultConfig(context.Background()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
curl := curl.NewPetShop( | ||
http.New(awsapi.WithSignatureV4(cfg)), | ||
os.Args[1], | ||
) | ||
|
||
pets, err := curl.List(context.Background()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
output(pets) | ||
|
||
if pets.Next != nil { | ||
pets, err = curl.Continue(context.Background(), *pets.Next) | ||
if err != nil { | ||
panic(err) | ||
} | ||
output(pets) | ||
} | ||
|
||
if len(pets.Pets) > 0 { | ||
pet, err := curl.Pet(context.Background(), pets.Pets[0].Url) | ||
if err != nil { | ||
panic(err) | ||
} | ||
output(pet) | ||
} | ||
} | ||
|
||
func output(x any) { | ||
b, _ := json.MarshalIndent(x, "|", " ") | ||
os.Stdout.Write(b) | ||
os.Stdout.Write([]byte("\n\n")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package curl | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/fogfish/blueprint-serverless-golang/http/api" | ||
"github.com/fogfish/gurl/v2/http" | ||
ƒ "github.com/fogfish/gurl/v2/http/recv" | ||
ø "github.com/fogfish/gurl/v2/http/send" | ||
"github.com/fogfish/schemaorg" | ||
) | ||
|
||
type PetShop struct { | ||
http.Stack | ||
host ø.Authority | ||
} | ||
|
||
func NewPetShop(stack http.Stack, host string) *PetShop { | ||
return &PetShop{ | ||
Stack: stack, | ||
host: ø.Authority(host), | ||
} | ||
} | ||
|
||
func (c *PetShop) List(ctx context.Context) (*api.Pets, error) { | ||
return http.IO[api.Pets](c.WithContext(ctx), | ||
http.GET( | ||
ø.URI("%s/petshop/pets", c.host), | ||
ø.Accept.ApplicationJSON, | ||
ƒ.Status.OK, | ||
), | ||
) | ||
} | ||
|
||
func (c *PetShop) Continue(ctx context.Context, cursor schemaorg.Url) (*api.Pets, error) { | ||
return http.IO[api.Pets](c.WithContext(ctx), | ||
http.GET( | ||
ø.URI("%s%s", c.host, ø.Path(cursor)), | ||
ø.Accept.ApplicationJSON, | ||
ƒ.Status.OK, | ||
), | ||
) | ||
} | ||
|
||
func (c *PetShop) Pet(ctx context.Context, url schemaorg.Url) (*api.Pet, error) { | ||
return http.IO[api.Pet](c.WithContext(ctx), | ||
http.GET( | ||
ø.URI("%s%s", c.host, ø.Path(url)), | ||
ø.Accept.ApplicationJSON, | ||
ƒ.Status.OK, | ||
), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
package http | ||
|
||
import ( | ||
"fmt" | ||
µ "github.com/fogfish/gouldian/v2" | ||
"net/http" | ||
) | ||
|
||
// Customer Endpoint | ||
func AllowSecretCode() µ.Endpoint { | ||
return µ.Authorization( | ||
func(kind, digest string) error { | ||
if kind != "Basic" { | ||
return µ.ErrNoMatch | ||
} | ||
return func(ctx *µ.Context) error { | ||
code := ctx.Request.Header.Get("X-Secret-Code") | ||
if code == "" { | ||
out := µ.NewOutput(http.StatusUnauthorized) | ||
out.SetIssue(fmt.Errorf("unauthorized %s", ctx.Request.URL.Path)) | ||
return out | ||
} | ||
|
||
if digest != "cGV0c3RvcmU6b3duZXIK" { | ||
return µ.ErrNoMatch | ||
} | ||
if code != "cGV0c3RvcmU6b3duZXIK" { | ||
return µ.ErrNoMatch | ||
} | ||
|
||
return nil | ||
}, | ||
) | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.