Skip to content

Commit

Permalink
all: goimports
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeneas Rekkas (arekkas) authored and arekkas committed May 7, 2017
1 parent 5cd1253 commit 91dc026
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 144 deletions.
28 changes: 14 additions & 14 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,67 +11,67 @@ import (
// swagger:model oauthClient
type Client struct {
// ID is the id for this client.
ID string `json:"id" gorethink:"id"`
ID string `json:"id" gorethink:"id"`

// Name is the human-readable string name of the client to be presented to the
// end-user during authorization.
Name string `json:"client_name" gorethink:"client_name"`
Name string `json:"client_name" gorethink:"client_name"`

// Secret is the client's secret. The secret will be included in the create request as cleartext, and then
// never again. The secret is stored using BCrypt so it is impossible to recover it. Tell your users
// that they need to write the secret down as it will not be made available again.
Secret string `json:"client_secret,omitempty" gorethink:"client_secret"`
Secret string `json:"client_secret,omitempty" gorethink:"client_secret"`

// RedirectURIs is an array of allowed redirect urls for the client, for example: http://mydomain/oauth/callback .
RedirectURIs []string `json:"redirect_uris" gorethink:"redirect_uris"`
RedirectURIs []string `json:"redirect_uris" gorethink:"redirect_uris"`

// GrantTypes is an array of grant types the client is allowed to use.
//
// Pattern: client_credentials|authorize_code|implicit|refresh_token
GrantTypes []string `json:"grant_types" gorethink:"grant_types"`
GrantTypes []string `json:"grant_types" gorethink:"grant_types"`

// ResponseTypes is an array of the OAuth 2.0 response type strings that the client can
// use at the authorization endpoint.
//
// Pattern: id_token|code|token
ResponseTypes []string `json:"response_types" gorethink:"response_types"`
ResponseTypes []string `json:"response_types" gorethink:"response_types"`

// Scope is a string containing a space-separated list of scope values (as
// described in Section 3.3 of OAuth 2.0 [RFC6749]) that the client
// can use when requesting access tokens.
//
// Pattern: ([a-zA-Z0-9\.]+\s)+
Scope string `json:"scope" gorethink:"scope"`
Scope string `json:"scope" gorethink:"scope"`

// Owner is a string identifying the owner of the OAuth 2.0 Client.
Owner string `json:"owner" gorethink:"owner"`
Owner string `json:"owner" gorethink:"owner"`

// PolicyURI is a URL string that points to a human-readable privacy policy document
// that describes how the deployment organization collects, uses,
// retains, and discloses personal data.
PolicyURI string `json:"policy_uri" gorethink:"policy_uri"`
PolicyURI string `json:"policy_uri" gorethink:"policy_uri"`

// TermsOfServiceURI is a URL string that points to a human-readable terms of service
// document for the client that describes a contractual relationship
// between the end-user and the client that the end-user accepts when
// authorizing the client.
TermsOfServiceURI string `json:"tos_uri" gorethink:"tos_uri"`
TermsOfServiceURI string `json:"tos_uri" gorethink:"tos_uri"`

// ClientURI is an URL string of a web page providing information about the client.
// If present, the server SHOULD display this URL to the end-user in
// a clickable fashion.
ClientURI string `json:"client_uri" gorethink:"client_uri"`
ClientURI string `json:"client_uri" gorethink:"client_uri"`

// LogoURI is an URL string that references a logo for the client.
LogoURI string `json:"logo_uri" gorethink:"logo_uri"`
LogoURI string `json:"logo_uri" gorethink:"logo_uri"`

// Contacts is a array of strings representing ways to contact people responsible
// for this client, typically email addresses.
Contacts []string `json:"contacts" gorethink:"contacts"`
Contacts []string `json:"contacts" gorethink:"contacts"`

// Public is a boolean that identifies this client as public, meaning that it
// does not have a secret. It will disable the client_credentials grant type for this client if set.
Public bool `json:"public" gorethink:"public"`
Public bool `json:"public" gorethink:"public"`
}

func (c *Client) GetID() string {
Expand Down
14 changes: 7 additions & 7 deletions client/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ const (

const (
ClientsResource = "rn:hydra:clients"
ClientResource = "rn:hydra:clients:%s"
Scope = "hydra.clients"
ClientResource = "rn:hydra:clients:%s"
Scope = "hydra.clients"
)

func (h *Handler) SetRoutes(r *httprouter.Router) {
r.GET(ClientsHandlerPath, h.List)
r.POST(ClientsHandlerPath, h.Create)
r.GET(ClientsHandlerPath + "/:id", h.Get)
r.PUT(ClientsHandlerPath + "/:id", h.Update)
r.DELETE(ClientsHandlerPath + "/:id", h.Delete)
r.GET(ClientsHandlerPath+"/:id", h.Get)
r.PUT(ClientsHandlerPath+"/:id", h.Update)
r.DELETE(ClientsHandlerPath+"/:id", h.Delete)
}

// swagger:route POST /clients oauth2 clients createOAuthClient
Expand Down Expand Up @@ -119,7 +119,7 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request, _ httprouter.Pa
}

c.Secret = secret
h.H.WriteCreated(w, r, ClientsHandlerPath + "/" + c.GetID(), &c)
h.H.WriteCreated(w, r, ClientsHandlerPath+"/"+c.GetID(), &c)
}

// swagger:route PUT /clients/{id} oauth2 clients updateOAuthClient
Expand Down Expand Up @@ -202,7 +202,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request, ps httprouter.P
return
}

h.H.WriteCreated(w, r, ClientsHandlerPath + "/" + c.GetID(), &c)
h.H.WriteCreated(w, r, ClientsHandlerPath+"/"+c.GetID(), &c)
}

// swagger:route GET /clients oauth2 clients listOAuthClients
Expand Down
82 changes: 63 additions & 19 deletions cmd/migrate_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,79 @@
package cmd

import (
"fmt"
"log"
"net/url"
"strings"
"time"

"github.com/Sirupsen/logrus"
"github.com/jmoiron/sqlx"
"github.com/ory/hydra/client"
"github.com/ory/hydra/jwk"
"github.com/ory/hydra/oauth2"
"github.com/ory/hydra/pkg"
"github.com/ory/hydra/warden/group"
ladon "github.com/ory/ladon/manager/sql"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

// sqlCmd represents the sql command
var sqlCmd = &cobra.Command{
Use: "migrate sql",
Short: "Migrate SQL schemas to the most recent version",
Long: `BEFORE RUNNING THIS COMMAND CREATE A BACK UP OF YOUR DATABASE
`,
Use: "migrate sql <database-url>",
Short: "Create and migrate SQL schemas to work with this version",
Long: `WARNING: Before running this command on an existing database, create a back up!`,
Run: func(cmd *cobra.Command, args []string) {
// TODO: Work your own magic here
fmt.Println("sql called")
},
}
var db *sqlx.DB
var logger = logrus.New()

func init() {
migrateCmd.AddCommand(sqlCmd)
u, err := url.Parse(args[0])
if err != nil {
log.Fatalf("Could not parse DATABASE_URL: %s", err)
}

if err := pkg.Retry(logger, time.Second*15, time.Minute*2, func() error {
if u.Scheme == "mysql" {
args[0] = strings.Replace(args[0], "mysql://", "", -1)
}

if db, err = sqlx.Open(u.Scheme, u); err != nil {
return errors.Errorf("Could not connect to SQL: %s", err)
} else if err := db.Ping(); err != nil {
return errors.Errorf("Could not connect to SQL: %s", err)
}

return nil
}); err != nil {
log.Fatalf("Could not connect to SQL: %s", err)
}

// Here you will define your flags and configuration settings.
if err := (&client.SQLManager{DB: db}).CreateSchemas(); err != nil {
c.GetLogger().Fatalf("Could not create client schema: %s", err)
}

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// sqlCmd.PersistentFlags().String("foo", "", "A help for foo")
if err := (&oauth2.FositeSQLStore{DB: db}).CreateSchemas(); err != nil {
c.GetLogger().Fatalf("Could not create oauth2 schema: %s", err)
}

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// sqlCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
if err := (&jwk.SQLManager{DB: db}).CreateSchemas(); err != nil {
c.GetLogger().Fatalf("Could not create jwk schema: %s", err)
}

if err := (&oauth2.FositeSQLStore{DB: db}).CreateSchemas(); err != nil {
c.GetLogger().Fatalf("Could not create oauth2 schema: %s", err)
}

if err := ladon.NewSQLManager(db, nil).CreateSchemas(); err != nil {
logrus.Fatalf("Could not create policy schema: %s", err)
}

if err := (&group.SQLManager{DB: db}).CreateSchemas(); err != nil {
logrus.Fatalf("Could not create group schema: %s", err)
}
},
}

func init() {
migrateCmd.AddCommand(sqlCmd)
}
14 changes: 7 additions & 7 deletions doc_swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ package main
type genericError struct {
// in: body
Body struct {
Code int `json:"code,omitempty"`
Code int `json:"code,omitempty"`

Status string `json:"status,omitempty"`
Status string `json:"status,omitempty"`

Request string `json:"request,omitempty"`
Request string `json:"request,omitempty"`

Reason string `json:"reason,omitempty"`
Reason string `json:"reason,omitempty"`

Details []map[string]interface{} `json:"details,omitempty"`
Details []map[string]interface{} `json:"details,omitempty"`

Message string `json:"message"`
}
Message string `json:"message"`
}
}
37 changes: 18 additions & 19 deletions jwk/doc.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package jwk


// swagger:parameters getJwkSetKey deleteJwkKey
type swaggerJwkSetKeyQuery struct {
// The kid of the desired key
Expand Down Expand Up @@ -76,14 +75,14 @@ type swaggerJSONWebKey struct {
// the public key. The "use" parameter is employed to indicate whether
// a public key is used for encrypting data or verifying the signature
// on data. Values are commonly "sig" (signature) or "enc" (encryption).
Use string `json:"use,omitempty"`
Use string `json:"use,omitempty"`

// The "kty" (key type) parameter identifies the cryptographic algorithm
// family used with the key, such as "RSA" or "EC". "kty" values should
// either be registered in the IANA "JSON Web Key Types" registry
// established by [JWA] or be a value that contains a Collision-
// Resistant Name. The "kty" value is a case-sensitive string.
Kty string `json:"kty,omitempty"`
Kty string `json:"kty,omitempty"`

// The "kid" (key ID) parameter is used to match a specific key. This
// is used, for instance, to choose among a set of keys within a JWK Set
Expand All @@ -94,16 +93,16 @@ type swaggerJSONWebKey struct {
// they have different "kty" (key type) values but are considered to be
// equivalent alternatives by the application using them.) The "kid"
// value is a case-sensitive string.
Kid string `json:"kid,omitempty"`
Kid string `json:"kid,omitempty"`

Crv string `json:"crv,omitempty"`
Crv string `json:"crv,omitempty"`

// The "alg" (algorithm) parameter identifies the algorithm intended for
// use with the key. The values used should either be registered in the
// IANA "JSON Web Signature and Encryption Algorithms" registry
// established by [JWA] or be a value that contains a Collision-
// Resistant Name.
Alg string `json:"alg,omitempty"`
Alg string `json:"alg,omitempty"`

// The "x5c" (X.509 certificate chain) parameter contains a chain of one
// or more PKIX certificates [RFC5280]. The certificate chain is
Expand All @@ -114,16 +113,16 @@ type swaggerJSONWebKey struct {
// certificate.
X5c []string `json:"x5c,omitempty"`

K []byte `json:"k,omitempty"`
X []byte `json:"x,omitempty"`
Y []byte `json:"y,omitempty"`
N []byte `json:"n,omitempty"`
E []byte `json:"e,omitempty"`

D []byte `json:"d,omitempty"`
P []byte `json:"p,omitempty"`
Q []byte `json:"q,omitempty"`
Dp []byte `json:"dp,omitempty"`
Dq []byte `json:"dq,omitempty"`
Qi []byte `json:"qi,omitempty"`
}
K []byte `json:"k,omitempty"`
X []byte `json:"x,omitempty"`
Y []byte `json:"y,omitempty"`
N []byte `json:"n,omitempty"`
E []byte `json:"e,omitempty"`

D []byte `json:"d,omitempty"`
P []byte `json:"p,omitempty"`
Q []byte `json:"q,omitempty"`
Dp []byte `json:"dp,omitempty"`
Dq []byte `json:"dq,omitempty"`
Qi []byte `json:"qi,omitempty"`
}
3 changes: 1 addition & 2 deletions jwk/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type createRequest struct {
// The kid of the key to be created
// required: true
// in: body
KeyID string `json:"kid"`
KeyID string `json:"kid"`
}

type joseWebKeySetRequest struct {
Expand Down Expand Up @@ -366,7 +366,6 @@ func (h *Handler) UpdateKey(w http.ResponseWriter, r *http.Request, ps httproute
h.H.Write(w, r, key)
}


// swagger:route DELETE /keys/{set} jwks deleteJwkSet
//
// Delete a JSON Web Key
Expand Down
Loading

0 comments on commit 91dc026

Please sign in to comment.