Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support OAuth 2.0 client credentials flow #33

Merged
merged 5 commits into from
Nov 30, 2024
Merged
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
3 changes: 3 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ jobs:
go-version: ${{ env.GO_VERSION }}
- name: Run Go unit tests
run: |
docker compose up -d hydra hydra-migrate
sleep 5
go test -v -coverpkg=./... -race -timeout 3m -coverprofile=coverage.out.tmp ./...
docker compose down -v
cat coverage.out.tmp | grep -v "main.go" > coverage.out
- name: Run integration tests
run: |
Expand Down
43 changes: 43 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,47 @@ services:
- local.hasura.dev=host-gateway
environment:
OTEL_EXPORTER_OTLP_ENDPOINT: http://local.hasura.dev:4317
HYDRA_PUBLIC_SERVER_URL: http://hydra:4444
HYDRA_ADMIN_SERVER_URL: http://hydra:4445
HASURA_LOG_LEVEL: debug

hydra:
image: oryd/hydra:v2.2.0
ports:
- "4444:4444" # Public port
- "4445:4445" # Admin port
- "5555:5555" # Port for hydra token user
command: serve -c /etc/config/hydra/hydra.yml all --dev
volumes:
- type: volume
source: hydra-sqlite
target: /var/lib/sqlite
read_only: false
- type: bind
source: ./tests/hydra.yml
target: /etc/config/hydra/hydra.yml
environment:
- DSN=sqlite:///var/lib/sqlite/db.sqlite?_fk=true
restart: unless-stopped
depends_on:
hydra-migrate:
required: true
condition: service_completed_successfully

hydra-migrate:
image: oryd/hydra:v2.2.0
environment:
- DSN=sqlite:///var/lib/sqlite/db.sqlite?_fk=true
command: migrate -c /etc/config/hydra/hydra.yml sql -e --yes
volumes:
- type: volume
source: hydra-sqlite
target: /var/lib/sqlite
read_only: false
- type: bind
source: ./tests/hydra.yml
target: /etc/config/hydra/hydra.yml
restart: on-failure

volumes:
hydra-sqlite:
14 changes: 8 additions & 6 deletions connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"net/http"

"github.com/hasura/ndc-http/connector/internal"
"github.com/hasura/ndc-http/ndc-http-schema/configuration"
Expand All @@ -19,7 +20,8 @@ type HTTPConnector struct {
capabilities *schema.RawCapabilitiesResponse
rawSchema *schema.RawSchemaResponse
schema *rest.NDCHttpSchema
client internal.Doer
httpClient *http.Client
upstreams *internal.UpstreamManager
}

// NewHTTPConnector creates a HTTP connector instance
Expand All @@ -29,7 +31,7 @@ func NewHTTPConnector(opts ...Option) *HTTPConnector {
}

return &HTTPConnector{
client: defaultOptions.client,
httpClient: defaultOptions.client,
}
}

Expand Down Expand Up @@ -76,11 +78,11 @@ func (c *HTTPConnector) ParseConfiguration(ctx context.Context, configurationDir
}
}

if err := c.ApplyNDCHttpSchemas(config, schemas, logger); err != nil {
return nil, errInvalidSchema
}

c.config = config
c.upstreams = internal.NewUpstreamManager(c.httpClient, config)
if err := c.ApplyNDCHttpSchemas(ctx, config, schemas, logger); err != nil {
return nil, fmt.Errorf("failed to validate NDC HTTP schema: %w", err)
}

return config, nil
}
Expand Down
Loading