Skip to content

Commit

Permalink
Merge pull request #96 from pinpt/GOLD-106
Browse files Browse the repository at this point in the history
GOLD-106 add app service
  • Loading branch information
Robin Diddams authored Jun 22, 2020
2 parents 9de4dc7 + d95c0c6 commit ffe0e24
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
6 changes: 6 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ func isDNSNameTrusted(names ...string) bool {
const (
// AgentService is the agent service endpoint
AgentService = "agent.api"
// AppService is the web app endpoint
AppService = "app"
// AuthService is the auth service endpoint
AuthService = "auth.api"
// EventService is the event service endpoint
Expand All @@ -100,6 +102,8 @@ func BackendURL(subdomain string, channel string) string {
switch subdomain {
case AgentService:
return os.Getenv("PP_AGENT_SERVICE")
case AppService:
return os.Getenv("PP_APP_SERVICE")
case AuthService:
return os.Getenv("PP_AUTH_SERVICE")
case EventService:
Expand All @@ -115,6 +119,8 @@ func BackendURL(subdomain string, channel string) string {
switch subdomain {
case AgentService:
return fmt.Sprintf("https://%s.%s:3004/", subdomain, devbaseURL)
case AppService:
return fmt.Sprintf("https://%s.%s:3001/", subdomain, devbaseURL)
case AuthService:
return fmt.Sprintf("https://%s.%s:3000/", subdomain, devbaseURL)
case EventService:
Expand Down
2 changes: 2 additions & 0 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func TestBackendURL(t *testing.T) {
assert := assert.New(t)
assert.Equal("https://auth.api.edge.pinpoint.com/", BackendURL(AuthService, "edge"))
assert.Equal("https://auth.api.pinpoint.com/", BackendURL(AuthService, "stable"))
assert.Equal("https://app.pinpoint.com/", BackendURL(AppService, "stable"))
assert.Equal("https://app.edge.pinpoint.com/", BackendURL(AppService, "edge"))
}

func TestSetHeaders(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions hash/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func ChecksumFrom(r io.Reader, hasher hash.Hash) (int64, []byte, error) {
for {
buf := make([]byte, 8096)
n, err := r.Read(buf)
written += n
if err == io.EOF || n == 0 {
break
} else if err != nil {
Expand All @@ -177,13 +178,11 @@ func ChecksumFrom(r io.Reader, hasher hash.Hash) (int64, []byte, error) {
if err != nil {
return 0, nil, err
}
written += n
}
return int64(written), hasher.Sum(nil), nil
}

// ChecksumCopy will do the same as io.Copy, but also returns a sha256 checksum for the data read
func ChecksumCopy(dst io.Writer, src io.Reader) (int64, []byte, error) {
r := io.TeeReader(src, dst)
return ChecksumFrom(r, sha256.New())
return ChecksumFrom(io.TeeReader(src, dst), sha256.New())
}
22 changes: 22 additions & 0 deletions hash/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package hash
import (
"bytes"
"encoding/hex"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"

Expand Down Expand Up @@ -173,3 +176,22 @@ func TestChecksumCopy(t *testing.T) {
assert.Equal("eb201af5aaf0d60629d3d2a61e466cfc0fedb517add831ecac5235e1daa963d6", sum)
assert.Equal("hash me", w.String())
}

func TestChecksumCopyToFile(t *testing.T) {
assert := assert.New(t)
r := bytes.NewReader([]byte("hash me"))
count := r.Len()
fn := filepath.Join(os.TempDir(), "hashChecksum")
of, err := os.Create(fn)
assert.NoError(err)
defer os.Remove(fn)
n, buf, err := ChecksumCopy(of, r)
assert.NoError(err)
assert.EqualValues(count, n)
sum := hex.EncodeToString(buf)
// shasum -a 256 hashChecksum
assert.Equal("eb201af5aaf0d60629d3d2a61e466cfc0fedb517add831ecac5235e1daa963d6", sum)
of.Close()
buf, _ = ioutil.ReadFile(fn)
assert.Equal("hash me", string(buf))
}

0 comments on commit ffe0e24

Please sign in to comment.