Skip to content

Commit

Permalink
u
Browse files Browse the repository at this point in the history
Signed-off-by: aeneasr <aeneas.rekkas@serlo.org>
  • Loading branch information
aeneasr committed Oct 23, 2018
1 parent 145f319 commit 541c026
Show file tree
Hide file tree
Showing 225 changed files with 698 additions and 1,001 deletions.
1 change: 1 addition & 0 deletions .goimportsignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/
47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
init:
go get -u \
github.com/x/tools/listx \
github.com/sqs/goreturns \
github.com/golang/mock \
github.com/go-swagger/go-swagger/cmd/swagger

format:
goreturns -w -local github.com/ory $$(listx .)
# goimports -w -v -local github.com/ory $$(listx .)

mockgen:
mockgen -package oauth2_test -destination oauth2/oauth2_provider_mock_test.go github.com/ory/fosite OAuth2Provider

sdk:
swagger generate spec -m -o ./docs/api.swagger.json

rm -rf ./sdk/go/hydra/swagger
rm -rf ./sdk/js/swagger
rm -rf ./sdk/php/swagger
rm -rf ./sdk/java

# swagger generate client -f ./docs/api.swagger.json -t sdk/go
java -jar scripts/swagger-codegen-cli-2.2.3.jar generate -i ./docs/api.swagger.json -l go -o ./sdk/go/hydra/swagger
java -jar scripts/swagger-codegen-cli-2.2.3.jar generate -i ./docs/api.swagger.json -l javascript -o ./sdk/js/swagger
java -jar scripts/swagger-codegen-cli-2.2.3.jar generate -i ./docs/api.swagger.json -l php -o sdk/php/ \
--invoker-package Hydra\\SDK --git-repo-id swagger --git-user-id ory --additional-properties "packagePath=swagger,description=Client for Hydra"
java -DapiTests=false -DmodelTests=false -jar scripts/swagger-codegen-cli-2.2.3.jar generate \
--input-spec ./docs/api.swagger.json \
--lang java \
--library resttemplate \
--group-id com.github.ory \
--artifact-id hydra-client-resttemplate \
--invoker-package com.github.ory.hydra \
--api-package com.github.ory.hydra.api \
--model-package com.github.ory.hydra.model \
--output ./sdk/java/hydra-client-resttemplate

goreturns -w -i -local github.com/ory $$(listx ./sdk/go)

git checkout HEAD -- sdk/go/hydra/swagger/configuration.go
git checkout HEAD -- sdk/go/hydra/swagger/api_client.go

rm -f ./sdk/js/swagger/package.json
rm -rf ./sdk/js/swagger/test
rm -f ./sdk/php/swagger/composer.json ./sdk/php/swagger/phpunit.xml.dist
rm -rf ./sdk/php/swagger/test
3 changes: 2 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ package client
import (
"strings"

"github.com/ory/fosite" // Naming the dependency jose is important for go-swagger to work, see https://github.com/go-swagger/go-swagger/issues/1587
jose "gopkg.in/square/go-jose.v2"

"github.com/ory/fosite" // Naming the dependency jose is important for go-swagger to work, see https://github.com/go-swagger/go-swagger/issues/1587
)

// Client represents an OAuth 2.0 Client.
Expand Down
3 changes: 2 additions & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ package client
import (
"testing"

"github.com/ory/fosite"
"github.com/stretchr/testify/assert"

"github.com/ory/fosite"
)

var _ fosite.OpenIDConnectClient = new(Client)
Expand Down
8 changes: 4 additions & 4 deletions client/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (
"net/http"

"github.com/julienschmidt/httprouter"
"github.com/ory/herodot"
"github.com/ory/x/pagination"
"github.com/pkg/errors"

"github.com/ory/hydra/rand/sequence"
"github.com/ory/herodot"
"github.com/ory/x/pagination"
"github.com/ory/x/randx"
)

type Handler struct {
Expand Down Expand Up @@ -94,7 +94,7 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request, _ httprouter.Pa
}

if len(c.Secret) == 0 {
secret, err := sequence.RuneSequence(12, []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-.~"))
secret, err := randx.RuneSequence(12, []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-.~"))
if err != nil {
h.H.WriteError(w, r, errors.WithStack(err))
return
Expand Down
4 changes: 2 additions & 2 deletions client/manager_0_sql_migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import (
"testing"

"github.com/jmoiron/sqlx"
"github.com/ory/fosite"
"github.com/ory/x/sqlcon/dockertest"
"github.com/rubenv/sql-migrate"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ory/fosite"
"github.com/ory/hydra/client"
"github.com/ory/x/sqlcon/dockertest"
)

var createClientMigrations = []*migrate.Migration{
Expand Down
3 changes: 2 additions & 1 deletion client/manager_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import (
"sync"

"github.com/imdario/mergo"
"github.com/pkg/errors"

"github.com/ory/fosite"
"github.com/ory/x/pagination"
"github.com/ory/x/sqlcon"
"github.com/pkg/errors"
)

type MemoryManager struct {
Expand Down
7 changes: 4 additions & 3 deletions client/manager_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ import (
"strings"

"github.com/jmoiron/sqlx"
"github.com/ory/fosite"
"github.com/ory/go-convenience/stringsx"
"github.com/ory/x/sqlcon"
"github.com/pkg/errors"
"github.com/rubenv/sql-migrate"
"gopkg.in/square/go-jose.v2"

"github.com/ory/fosite"
"github.com/ory/go-convenience/stringsx"
"github.com/ory/x/sqlcon"
)

var sharedMigrations = []*migrate.Migration{
Expand Down
4 changes: 2 additions & 2 deletions client/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ import (

_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
"github.com/ory/fosite"
"github.com/ory/x/sqlcon/dockertest"
"github.com/stretchr/testify/require"

"github.com/ory/fosite"
. "github.com/ory/hydra/client"
"github.com/ory/x/sqlcon/dockertest"
)

var clientManagers = map[string]Manager{}
Expand Down
3 changes: 2 additions & 1 deletion client/manager_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import (
"crypto/x509"
"testing"

"github.com/ory/fosite"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/square/go-jose.v2"

"github.com/ory/fosite"
)

func TestHelperClientAutoGenerateKey(k string, m Storage) func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion client/sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import (
"testing"

"github.com/julienschmidt/httprouter"
"github.com/ory/herodot"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ory/herodot"
"github.com/ory/hydra/client"
hydra "github.com/ory/hydra/sdk/go/hydra/swagger"
)
Expand Down
5 changes: 3 additions & 2 deletions client/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ import (
"net/url"
"strings"

"github.com/pborman/uuid"
"github.com/pkg/errors"

"github.com/ory/fosite"
"github.com/ory/go-convenience/stringslice"
"github.com/ory/go-convenience/stringsx"
"github.com/pborman/uuid"
"github.com/pkg/errors"
)

type Validator struct {
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/handler_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import (
"os"
"strings"

"github.com/ory/x/cmdx"
"github.com/ory/x/flagx"
"github.com/spf13/cobra"

"github.com/ory/hydra/config"
"github.com/ory/hydra/pkg"
hydra "github.com/ory/hydra/sdk/go/hydra/swagger"
"github.com/ory/x/cmdx"
"github.com/ory/x/flagx"
)

type ClientHandler struct {
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/handler_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
"io/ioutil"
"net/http"

"github.com/ory/x/cmdx"
"github.com/ory/x/flagx"
"github.com/spf13/cobra"

hydra "github.com/ory/hydra/sdk/go/hydra/swagger"
"github.com/ory/x/cmdx"
"github.com/ory/x/flagx"
)

func configureClient(cmd *cobra.Command, c *hydra.Configuration) *hydra.Configuration {
Expand Down
7 changes: 3 additions & 4 deletions cmd/cli/handler_introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ package cli
import (
"fmt"
"net/http"
"strings"
"strings" //"encoding/json"

"github.com/ory/x/cmdx"
"github.com/ory/x/flagx" //"context"
//"encoding/json"
"github.com/ory/hydra/config" //"github.com/ory/hydra/oauth2"
hydra "github.com/ory/hydra/sdk/go/hydra/swagger"
"github.com/ory/x/cmdx"
"github.com/ory/x/flagx" //"context"
"github.com/spf13/cobra"
)

Expand Down
12 changes: 6 additions & 6 deletions cmd/cli/handler_jwk.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ import (
"net/http"

"github.com/mendsley/gojwk"
"github.com/ory/x/cmdx"
"github.com/ory/x/flagx"
"github.com/pborman/uuid"
"github.com/spf13/cobra"
"gopkg.in/square/go-jose.v2"

"github.com/ory/hydra/config"
"github.com/ory/hydra/pkg"
hydra "github.com/ory/hydra/sdk/go/hydra/swagger"
"github.com/ory/x/cmdx"
"github.com/ory/x/flagx"
"github.com/ory/x/josex"
)

type JWKHandler struct {
Expand Down Expand Up @@ -105,7 +105,7 @@ func (h *JWKHandler) ImportKeys(cmd *cobra.Command, args []string) {
cmdx.MinArgs(cmd, args, 2)

id := args[0]
use, _ := cmd.Flags().GetString("use")
use := flagx.MustGetString(cmd, "use")
client := &http.Client{}

client.Transport = &http.Transport{
Expand Down Expand Up @@ -142,8 +142,8 @@ func (h *JWKHandler) ImportKeys(cmd *cobra.Command, args []string) {
file, err := ioutil.ReadFile(path)
cmdx.Must(err, "Unable to read file %s", path)

if key, privateErr := pkg.LoadPrivateKey(file); privateErr != nil {
key, publicErr := pkg.LoadPublicKey(file)
if key, privateErr := josex.LoadPrivateKey(file); privateErr != nil {
key, publicErr := josex.LoadPublicKey(file)
cmdx.Must(publicErr, `Unable to read key from file %s. Decoding file to private key failed with reason "%s" and decoding it to public key failed with reason: %s`, path, privateErr, publicErr)

set.Keys = append(set.Keys, toSDKFriendlyJSONWebKey(key, "public:"+uuid.New(), use, true))
Expand Down
9 changes: 5 additions & 4 deletions cmd/cli/handler_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"time"

"github.com/jmoiron/sqlx"
"github.com/ory/x/cmdx"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -38,7 +37,9 @@ import (
"github.com/ory/hydra/consent"
"github.com/ory/hydra/jwk"
"github.com/ory/hydra/oauth2"
"github.com/ory/hydra/pkg"
"github.com/ory/x/cmdx"
"github.com/ory/x/flagx"
"github.com/ory/x/resilience"
)

type MigrateHandler struct {
Expand All @@ -61,7 +62,7 @@ func (h *MigrateHandler) connectToSql(dsn string) (*sqlx.DB, error) {
return nil, errors.Errorf("could not parse DATABASE_URL: %s", err)
}

if err := pkg.Retry(h.c.GetLogger(), time.Second*15, time.Minute*2, func() error {
if err := resilience.Retry(h.c.GetLogger(), time.Second*15, time.Minute*2, func() error {
if u.Scheme == "mysql" {
dsn = strings.Replace(dsn, "mysql://", "", -1)
}
Expand All @@ -81,7 +82,7 @@ func (h *MigrateHandler) connectToSql(dsn string) (*sqlx.DB, error) {
}

func getDBUrl(cmd *cobra.Command, args []string, position int) (dburl string) {
if readFromEnv, _ := cmd.Flags().GetBool("read-from-env"); readFromEnv {
if flagx.MustGetBool(cmd, "read-from-env") {
if len(viper.GetString("DATABASE_URL")) == 0 {
fmt.Println(cmd.UsageString())
fmt.Println("")
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/handler_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import (
"net/http"
"time"

"github.com/ory/x/cmdx"
"github.com/ory/x/flagx"
"github.com/spf13/cobra"

"github.com/ory/hydra/config"
hydra "github.com/ory/hydra/sdk/go/hydra/swagger"
"github.com/ory/x/cmdx"
"github.com/ory/x/flagx"
)

type TokenHandler struct {
Expand Down
3 changes: 2 additions & 1 deletion cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ package cmd
import (
"crypto/tls"
"fmt"
"github.com/ory/x/healthx"
"net/http"
"os"
"testing"
"time"

"github.com/phayes/freeport"
"github.com/stretchr/testify/assert"

"github.com/ory/x/healthx"
)

var frontendPort, backendPort int
Expand Down
3 changes: 2 additions & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import (
"os"
"strconv"

"github.com/spf13/cobra"

"github.com/ory/x/corsx"
"github.com/ory/x/profilex"
"github.com/ory/x/tlsx"
"github.com/spf13/cobra"
)

var serveControls = `CORE CONTROLS
Expand Down
14 changes: 7 additions & 7 deletions cmd/server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@ import (
"github.com/gorilla/context"
"github.com/julienschmidt/httprouter"
"github.com/meatballhat/negroni-logrus"
"github.com/ory/graceful"
"github.com/ory/herodot"
"github.com/ory/x/cmdx"
"github.com/ory/x/corsx"
"github.com/ory/x/flagx"
"github.com/ory/x/healthx"
"github.com/ory/x/metricsx"
"github.com/pkg/errors"
"github.com/rs/cors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/urfave/negroni"

"github.com/ory/graceful"
"github.com/ory/herodot"
"github.com/ory/hydra/client"
"github.com/ory/hydra/config"
"github.com/ory/hydra/consent"
"github.com/ory/hydra/jwk"
"github.com/ory/hydra/oauth2"
"github.com/ory/x/cmdx"
"github.com/ory/x/corsx"
"github.com/ory/x/flagx"
"github.com/ory/x/healthx"
"github.com/ory/x/metricsx"
)

var _ = &consent.Handler{}
Expand Down

0 comments on commit 541c026

Please sign in to comment.