Skip to content

Commit

Permalink
refactor: make embedding easier with internal sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Nov 11, 2022
1 parent a9f6b7f commit e9aa21f
Show file tree
Hide file tree
Showing 585 changed files with 115,060 additions and 596 deletions.
19 changes: 17 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,26 @@ sdk: .bin/swagger .bin/ory node_modules
-g go \
-o "internal/httpclient" \
--git-user-id ory \
--git-repo-id kratos-client-go \
--git-repo-id client-go \
--git-host github.com \
-t .schema/openapi/templates/go \
-c .schema/openapi/gen.go.yml

(cd internal/httpclient; rm -rf go.mod go.sum test api docs)

rm -rf internal/httpclient-central
mkdir -p internal/httpclient-central/
npm run openapi-generator-cli -- generate -i "spec/api.json" \
-g go \
-o "internal/client-go" \
--git-user-id ory \
--git-repo-id client-go \
--git-host github.com \
-t .schema/openapi/templates/go \
-c .schema/openapi/gen.go.yml

(cd internal/client-go; go mod edit -module github.com/ory/client-go go.mod; rm -rf test api docs)

make format

.PHONY: quickstart
Expand All @@ -135,7 +150,7 @@ authors: # updates the AUTHORS file
# Formats the code
.PHONY: format
format: .bin/goimports .bin/ory node_modules
.bin/ory dev headers license --exclude=internal/httpclient
.bin/ory dev headers license --exclude=internal/httpclient --exclude=internal/httpclient-ory
goimports -w -local github.com/ory .
npm exec -- prettier --write 'test/e2e/**/*{.ts,.js}'
npm exec -- prettier --write '.github'
Expand Down
20 changes: 17 additions & 3 deletions cmd/cliclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cliclient

import (
"fmt"
"net/http"
"net/url"
"os"
"time"
Expand All @@ -17,7 +18,7 @@ import (

"github.com/spf13/pflag"

kratos "github.com/ory/kratos-client-go"
kratos "github.com/ory/kratos/internal/httpclient"
)

const (
Expand All @@ -31,9 +32,22 @@ const (
ClientContextKey ContextKey = iota + 1
)

type ClientContext struct {
Endpoint string
HTTPClient *http.Client
}

func NewClient(cmd *cobra.Command) (*kratos.APIClient, error) {
if f, ok := cmd.Context().Value(ClientContextKey).(func(cmd *cobra.Command) (*kratos.APIClient, error)); ok {
return f(cmd)
if f, ok := cmd.Context().Value(ClientContextKey).(func(cmd *cobra.Command) (*ClientContext, error)); ok {
cc, err := f(cmd)
if err != nil {
return nil, err
}

conf := kratos.NewConfiguration()
conf.HTTPClient = cc.HTTPClient
conf.Servers = kratos.ServerConfigurations{{URL: cc.Endpoint}}
return kratos.NewAPIClient(conf), nil
} else if f != nil {
return nil, errors.Errorf("ClientContextKey was expected to be *client.OryKratos but it contained an invalid type %T ", f)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/identities/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package identities
import (
"strings"

kratos "github.com/ory/kratos-client-go"
kratos "github.com/ory/kratos/internal/httpclient"

"github.com/ory/x/cmdx"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/identities/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package identities
import (
"fmt"

kratos "github.com/ory/kratos-client-go"
kratos "github.com/ory/kratos/internal/httpclient"
"github.com/ory/kratos/x"
"github.com/ory/x/cmdx"
"github.com/ory/x/stringsx"
Expand Down
2 changes: 1 addition & 1 deletion cmd/identities/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"encoding/json"
"fmt"

kratos "github.com/ory/kratos-client-go"
kratos "github.com/ory/kratos/internal/httpclient"

"github.com/ory/x/cmdx"

Expand Down
2 changes: 1 addition & 1 deletion cmd/identities/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"

kratos "github.com/ory/kratos-client-go"
"github.com/ory/kratos/driver/config"
kratos "github.com/ory/kratos/internal/httpclient"
)

func TestImportCmd(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion examples/go/identity/create/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main
import (
"context"

ory "github.com/ory/kratos-client-go"
ory "github.com/ory/client-go"
"github.com/ory/kratos/examples/go/pkg"
"github.com/ory/kratos/x"
)
Expand Down
2 changes: 1 addition & 1 deletion examples/go/identity/get/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main
import (
"context"

ory "github.com/ory/kratos-client-go"
ory "github.com/ory/client-go"
"github.com/ory/kratos/examples/go/pkg"
)

Expand Down
2 changes: 1 addition & 1 deletion examples/go/identity/update/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main
import (
"context"

ory "github.com/ory/kratos-client-go"
ory "github.com/ory/client-go"
"github.com/ory/kratos/examples/go/pkg"
"github.com/ory/kratos/x"
)
Expand Down
2 changes: 1 addition & 1 deletion examples/go/pkg/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"github.com/ory/kratos/internal/testhelpers"

ory "github.com/ory/kratos-client-go"
ory "github.com/ory/client-go"
)

func PrintJSONPretty(v interface{}) {
Expand Down
2 changes: 1 addition & 1 deletion examples/go/pkg/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/google/uuid"

ory "github.com/ory/kratos-client-go"
ory "github.com/ory/client-go"
)

func RandomCredentials() (email, password string) {
Expand Down
2 changes: 1 addition & 1 deletion examples/go/selfservice/error/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main
import (
"github.com/ory/kratos/examples/go/pkg"

ory "github.com/ory/kratos-client-go"
ory "github.com/ory/client-go"
)

// If you use Open Source this would be:
Expand Down
2 changes: 1 addition & 1 deletion examples/go/selfservice/login/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/ory/kratos/examples/go/pkg"

ory "github.com/ory/kratos-client-go"
ory "github.com/ory/client-go"
)

// If you use Open Source this would be:
Expand Down
2 changes: 1 addition & 1 deletion examples/go/selfservice/logout/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/ory/kratos/examples/go/pkg"

ory "github.com/ory/kratos-client-go"
ory "github.com/ory/client-go"
)

// If you use Open Source this would be:
Expand Down
2 changes: 1 addition & 1 deletion examples/go/selfservice/recovery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/ory/kratos/examples/go/pkg"

ory "github.com/ory/kratos-client-go"
ory "github.com/ory/client-go"
)

// If you use Open Source this would be:
Expand Down
14 changes: 5 additions & 9 deletions examples/go/selfservice/recovery/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ package main
import (
"testing"

ory "github.com/ory/kratos-client-go"

"github.com/stretchr/testify/assert"

"github.com/google/uuid"

"github.com/ory/kratos/internal/testhelpers"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ory/kratos/examples/go/pkg"

"github.com/stretchr/testify/require"
ory "github.com/ory/kratos/internal/httpclient"
"github.com/ory/kratos/internal/testhelpers"
)

func TestFunc(t *testing.T) {
Expand All @@ -25,5 +21,5 @@ func TestFunc(t *testing.T) {

flow := performRecovery("dev+" + uuid.New().String() + "@ory.sh")
require.NotEmpty(t, flow.Id)
assert.Equal(t, ory.SELFSERVICERECOVERYFLOWSTATE_SENT_EMAIL, flow.State)
assert.EqualValues(t, ory.SELFSERVICERECOVERYFLOWSTATE_SENT_EMAIL, flow.State)
}
2 changes: 1 addition & 1 deletion examples/go/selfservice/registration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/ory/kratos/examples/go/pkg"

ory "github.com/ory/kratos-client-go"
ory "github.com/ory/client-go"
)

// If you use Open Source this would be:
Expand Down
2 changes: 1 addition & 1 deletion examples/go/selfservice/settings/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/ory/kratos/examples/go/pkg"

ory "github.com/ory/kratos-client-go"
ory "github.com/ory/client-go"
)

// If you use Open Source this would be:
Expand Down
6 changes: 3 additions & 3 deletions examples/go/selfservice/settings/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main
import (
"testing"

ory "github.com/ory/kratos-client-go"
ory "github.com/ory/kratos/internal/httpclient"

"github.com/stretchr/testify/assert"

Expand All @@ -24,11 +24,11 @@ func TestSettings(t *testing.T) {
email, password := pkg.RandomCredentials()
result := changePassword(email, password)
require.NotEmpty(t, result.Id)
assert.Equal(t, ory.SELFSERVICESETTINGSFLOWSTATE_SUCCESS, result.State)
assert.EqualValues(t, ory.SELFSERVICESETTINGSFLOWSTATE_SUCCESS, result.State)

email, password = pkg.RandomCredentials()
result = changeTraits(email, password)
require.NotEmpty(t, result.Id)
assert.Equal(t, ory.SELFSERVICESETTINGSFLOWSTATE_SUCCESS, result.State)
assert.EqualValues(t, ory.SELFSERVICESETTINGSFLOWSTATE_SUCCESS, result.State)
assert.Equal(t, "not-"+email, result.Identity.Traits.(map[string]interface{})["email"].(string))
}
2 changes: 1 addition & 1 deletion examples/go/selfservice/verification/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/ory/kratos/examples/go/pkg"

ory "github.com/ory/kratos-client-go"
ory "github.com/ory/client-go"
)

// If you use Open Source this would be:
Expand Down
14 changes: 5 additions & 9 deletions examples/go/selfservice/verification/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ package main
import (
"testing"

ory "github.com/ory/kratos-client-go"

"github.com/stretchr/testify/assert"

"github.com/google/uuid"

"github.com/ory/kratos/internal/testhelpers"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ory/kratos/examples/go/pkg"

"github.com/stretchr/testify/require"
ory "github.com/ory/kratos/internal/httpclient"
"github.com/ory/kratos/internal/testhelpers"
)

func TestFunc(t *testing.T) {
Expand All @@ -25,5 +21,5 @@ func TestFunc(t *testing.T) {

flow := performVerification("dev+" + uuid.New().String() + "@ory.sh")
require.NotEmpty(t, flow.Id)
assert.Equal(t, ory.SELFSERVICEVERIFICATIONFLOWSTATE_SENT_EMAIL, flow.State)
assert.EqualValues(t, ory.SELFSERVICEVERIFICATIONFLOWSTATE_SENT_EMAIL, flow.State)
}
2 changes: 1 addition & 1 deletion examples/go/session/tosession/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main
import (
"github.com/ory/kratos/examples/go/pkg"

ory "github.com/ory/kratos-client-go"
ory "github.com/ory/client-go"
)

// If you use Open Source this would be:
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ replace (
github.com/bradleyjkemp/cupaloy/v2 => github.com/aeneasr/cupaloy/v2 v2.6.1-0.20210924214125-3dfdd01210a3
github.com/gorilla/sessions => github.com/ory/sessions v1.2.2-0.20220110165800-b09c17334dc2
github.com/knadh/koanf => github.com/aeneasr/koanf v0.14.1-0.20211230115640-aa3902b3267a
// github.com/luna-duclos/instrumentedsql => github.com/ory/instrumentedsql v1.2.0
// github.com/luna-duclos/instrumentedsql/opentracing => github.com/ory/instrumentedsql/opentracing v0.0.0-20210903114257-c8963b546c5c

github.com/mattn/go-sqlite3 => github.com/mattn/go-sqlite3 v1.14.7-0.20210414154423-1157a4212dcb
github.com/oleiade/reflections => github.com/oleiade/reflections v1.0.1

github.com/ory/client-go => ./internal/httpclient-ory

// Use the internal httpclient which can be generated in this codebase but mark it as the
// official SDK, allowing for the Ory CLI to consume Ory Kratos' CLI commands.
github.com/ory/kratos-client-go => ./internal/httpclient

go.mongodb.org/mongo-driver => go.mongodb.org/mongo-driver v1.4.6
golang.org/x/sys => golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8
gopkg.in/DataDog/dd-trace-go.v1 => gopkg.in/DataDog/dd-trace-go.v1 v1.27.1-0.20201005154917-54b73b3e126a
Expand Down Expand Up @@ -67,14 +67,14 @@ require (
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe
github.com/ory/analytics-go/v4 v4.0.3
github.com/ory/client-go v0.2.0-alpha.60
github.com/ory/dockertest/v3 v3.9.1
github.com/ory/go-acc v0.2.8
github.com/ory/go-convenience v0.1.0
github.com/ory/graceful v0.1.3
github.com/ory/herodot v0.9.13
github.com/ory/hydra-client-go v1.11.8
github.com/ory/hydra-client-go v1.11.9-0.20221102130300-f558e85344c8
github.com/ory/jsonschema/v3 v3.0.7
github.com/ory/kratos-client-go v0.6.3-alpha.1
github.com/ory/mail/v3 v3.0.0
github.com/ory/nosurf v1.2.7
github.com/ory/x v0.0.513
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1126,8 +1126,8 @@ github.com/ory/graceful v0.1.3 h1:FaeXcHZh168WzS+bqruqWEw/HgXWLdNv2nJ+fbhxbhc=
github.com/ory/graceful v0.1.3/go.mod h1:4zFz687IAF7oNHHiB586U4iL+/4aV09o/PYLE34t2bA=
github.com/ory/herodot v0.9.13 h1:cN/Z4eOkErl/9W7hDIDLb79IO/bfsH+8yscBjRpB4IU=
github.com/ory/herodot v0.9.13/go.mod h1:IWDs9kSvFQqw/cQ8zi5ksyYvITiUU4dI7glUrhZcJYo=
github.com/ory/hydra-client-go v1.11.8 h1:GwJjvH/DBcfYzoST4vUpi4pIRzDGH5oODKpIVuhwVyc=
github.com/ory/hydra-client-go v1.11.8/go.mod h1:4YuBuwUEC4yiyDrnKjGYc1tB3gUXan4ZiUYMjXJbfxA=
github.com/ory/hydra-client-go v1.11.9-0.20221102130300-f558e85344c8 h1:lxE11nBH6k0DvE1GMhWnZewGLAqVMSDj7cUhdHr9BHI=
github.com/ory/hydra-client-go v1.11.9-0.20221102130300-f558e85344c8/go.mod h1:4YuBuwUEC4yiyDrnKjGYc1tB3gUXan4ZiUYMjXJbfxA=
github.com/ory/jsonschema/v3 v3.0.7 h1:GQ9qfZDiJqs4l2d3p56dozCChvejQFZyLKGHYzDzOSo=
github.com/ory/jsonschema/v3 v3.0.7/go.mod h1:g8c8YOtN4TrR2wYeMdT02GDmzJDI0fEW2nI26BECafY=
github.com/ory/mail v2.3.1+incompatible/go.mod h1:87D9/1gB6ewElQoN0lXJ0ayfqcj3cW3qCTXh+5E9mfU=
Expand All @@ -1139,8 +1139,8 @@ github.com/ory/sessions v1.2.2-0.20220110165800-b09c17334dc2 h1:zm6sDvHy/U9XrGpi
github.com/ory/sessions v1.2.2-0.20220110165800-b09c17334dc2/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/ory/viper v1.7.5 h1:+xVdq7SU3e1vNaCsk/ixsfxE4zylk1TJUiJrY647jUE=
github.com/ory/viper v1.7.5/go.mod h1:ypOuyJmEUb3oENywQZRgeAMwqgOyDqwboO1tj3DjTaM=
github.com/ory/x v0.0.513 h1:45AruNHDwqhTvNtMnQy2/wYooMv+raVhuOP454mV/Os=
github.com/ory/x v0.0.513/go.mod h1:xUtRpoiRARyJNPVk/fcCNKzyp25Foxt9GPlj8pd7egY=
github.com/ory/x v0.0.511-0.20221108105728-3fed9bc99daf h1:sPEIGYHzmEu4tPiRUYgKfXPOAqneNuB1aaKvrT6aBXE=
github.com/ory/x v0.0.511-0.20221108105728-3fed9bc99daf/go.mod h1:xUtRpoiRARyJNPVk/fcCNKzyp25Foxt9GPlj8pd7egY=
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
Expand Down
6 changes: 3 additions & 3 deletions hydra/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ func (h *FakeHydra) AcceptLoginRequest(ctx context.Context, hlc uuid.UUID, sub s
}
}

func (h *FakeHydra) GetLoginRequest(ctx context.Context, hlc uuid.NullUUID) (*hydraclientgo.LoginRequest, error) {
func (h *FakeHydra) GetLoginRequest(ctx context.Context, hlc uuid.NullUUID) (*hydraclientgo.OAuth2LoginRequest, error) {
switch hlc.UUID.String() {
case FAKE_ACCEPT_REQUEST_FAIL:
return &hydraclientgo.LoginRequest{}, nil
return &hydraclientgo.OAuth2LoginRequest{}, nil
case FAKE_SUCCESS:
return &hydraclientgo.LoginRequest{}, nil
return &hydraclientgo.OAuth2LoginRequest{}, nil
default:
panic("unknown fake login_challenge " + hlc.UUID.String())
}
Expand Down
Loading

0 comments on commit e9aa21f

Please sign in to comment.