Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/consumer-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ jobs:
golangci-lint:
runs-on: ubuntu-latest
steps:
- name: Install golangci
uses: actions/checkout@v2
- uses: golangci/golangci-lint-action@v2
- uses: actions/setup-go@v3
with:
go-version: 1.16.x
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.29
working-directory: consumer
working-directory: consumer
20 changes: 11 additions & 9 deletions .github/workflows/producer-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ on:
- producer/**/*.*
- .github/workflows/producer-ci.yml
defaults:
run:
working-directory: producer
run:
working-directory: producer
jobs:

lint-test-build:
runs-on: ubuntu-latest
steps:
Expand All @@ -32,17 +31,20 @@ jobs:
- uses: actions/setup-python@v2
- uses: pre-commit/[email protected]
- name: Build
run: |
run: |
go build ./...
working-directory: producer
- name: Test
run: ./test.sh
run: ./test.sh
golangci-lint:
runs-on: ubuntu-latest
steps:
- name: Install golangci
uses: actions/checkout@v2
- uses: golangci/golangci-lint-action@v2
- uses: actions/setup-go@v3
with:
go-version: 1.16.x
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.29
working-directory: producer
working-directory: producer
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ exclude: '^gqlgen'
fail_fast: true
repos:
- repo: https://github.com/tekwizely/pre-commit-golang
rev: master
rev: v1.0.0-beta.5
hooks:
- id: golangci-lint-mod
- id: go-build-repo-mod
Expand Down
6 changes: 6 additions & 0 deletions consumer/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,12 @@ github.com/lib/pq v1.10.0 h1:Zx5DJFEYQXio93kgXnQ09fXNiUKsqv4OUEu2UtGcB1E=
github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/lyft/protoc-gen-star v0.5.3/go.mod h1:V0xaHgaf5oCCqmcxYcWiDfTiKsZsRc87/1qhoTACD8w=
github.com/machinebox/graphql v0.2.2 h1:dWKpJligYKhYKO5A2gvNhkJdQMNZeChZYyBbrZkBZfo=
github.com/machinebox/graphql v0.2.2/go.mod h1:F+kbVMHuwrQ5tYgU9JXlnskM8nOaFxCAEolaQybkjWA=
github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls=
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE=
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
github.com/matryer/moq v0.0.0-20200106131100-75d0ddfc0007/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
Expand Down Expand Up @@ -356,6 +360,8 @@ github.com/pierrec/lz4 v2.6.0+incompatible h1:Ix9yFKn1nSPBLFl/yZknTp8TU5G4Ps0JDm
github.com/pierrec/lz4 v2.6.0+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
1 change: 1 addition & 0 deletions consumer/internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func New() *echo.Echo {
e.Use(middleware.Logger(), middleware.Recover(), secure.CORS(), secure.Headers())
e.GET("/", healthCheck)
e.GET("ping", producerclient.What)
e.POST("producer-login", producerclient.LoginPassthrough)
e.Validator = &CustomValidator{V: validator.New()}
custErr := &customErrHandler{e: e}
e.HTTPErrorHandler = custErr.handler
Expand Down
3 changes: 3 additions & 0 deletions libs/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ go 1.14
require (
github.com/labstack/echo v3.3.10+incompatible
github.com/labstack/gommon v0.3.1 // indirect
github.com/machinebox/graphql v0.2.2
github.com/matryer/is v1.4.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/stretchr/testify v1.7.1 // indirect
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064 // indirect
)
6 changes: 6 additions & 0 deletions libs/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8
github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
github.com/labstack/gommon v0.3.1 h1:OomWaJXm7xR6L1HmEtGyQf26TEn7V6X88mktX9kee9o=
github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
github.com/machinebox/graphql v0.2.2 h1:dWKpJligYKhYKO5A2gvNhkJdQMNZeChZYyBbrZkBZfo=
github.com/machinebox/graphql v0.2.2/go.mod h1:F+kbVMHuwrQ5tYgU9JXlnskM8nOaFxCAEolaQybkjWA=
github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE=
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs=
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
46 changes: 45 additions & 1 deletion libs/producerclient/main.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package producerclient

import (
"context"
"encoding/json"
"fmt"
"github.com/labstack/echo"
client "libs/restclient"
"net/http"
"os"

"github.com/machinebox/graphql"
)

type PongResponse struct {
Ok string `json:"ok"`
}

// What handles GET requests to the /ping-what endpoint of the producer service
// What handles GET requests to the /ping endpoint of the consumer service
func What(ctx echo.Context) error {
producerServiceURL := os.Getenv("PRODUCER_SVC_ENDPOINT") + "/ping-what"
var pongJson PongResponse
Expand All @@ -22,3 +26,43 @@ func What(ctx echo.Context) error {
}
return ctx.JSON(http.StatusOK, pongJson)
}

type LoginResponse struct {
Token string `json:"token"`
}

type TokenResponse struct {
Login LoginResponse `json:"login"`
}

type Credentials struct {
Username string `json:"username"`
Password string `json:"password"`
}

// LoginPassthrough handles POST requests to the /producer-login endpoint of the consumer service
func LoginPassthrough(ctx echo.Context) error {
producerServiceURL := os.Getenv("PRODUCER_SVC_ENDPOINT") + "/graphql"
graphqlClient := graphql.NewClient(producerServiceURL)

req := graphql.NewRequest(`
mutation login($username: String!, $password: String!) {
login (username: $username, password: $password) {
token
}
}
`)
var credentials Credentials
if err := json.NewDecoder(ctx.Request().Body).Decode(&credentials); err != nil {
return fmt.Errorf("LoginPassthrough::failed to decode request body::%w", err)
}

req.Var("username", credentials.Username)
req.Var("password", credentials.Password)

var tokenResponse TokenResponse
if err := graphqlClient.Run(context.Background(), req, &tokenResponse); err != nil {
return fmt.Errorf("%w", err)
}
return ctx.JSON(http.StatusOK, &tokenResponse)
}
2 changes: 1 addition & 1 deletion producer/internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package server
import (
"context"
"fmt"
"github.com/go-playground/validator"
"net/http"
"os"
"os/signal"
"time"

"producer/internal/middleware/secure"

"github.com/go-playground/validator"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
Expand Down