dex/schema/workerschema/mapper.go

59 lines
1.2 KiB
Go
Raw Normal View History

2015-08-18 05:57:27 +05:30
package workerschema
import (
"errors"
"net/url"
2016-04-16 05:53:27 +05:30
"github.com/coreos/dex/client"
2015-08-18 05:57:27 +05:30
"github.com/coreos/go-oidc/oidc"
)
2016-04-16 05:53:27 +05:30
func MapSchemaClientToClient(sc Client) (client.Client, error) {
ci := client.Client{
2015-08-18 05:57:27 +05:30
Credentials: oidc.ClientCredentials{
ID: sc.Id,
},
Metadata: oidc.ClientMetadata{
RedirectURIs: make([]url.URL, len(sc.RedirectURIs)),
2015-08-18 05:57:27 +05:30
},
}
for i, ru := range sc.RedirectURIs {
if ru == "" {
2016-04-16 05:53:27 +05:30
return client.Client{}, errors.New("redirect URL empty")
2015-08-18 05:57:27 +05:30
}
u, err := url.Parse(ru)
if err != nil {
2016-04-16 05:53:27 +05:30
return client.Client{}, errors.New("redirect URL invalid")
2015-08-18 05:57:27 +05:30
}
ci.Metadata.RedirectURIs[i] = *u
2015-08-18 05:57:27 +05:30
}
return ci, nil
}
2016-04-16 05:53:27 +05:30
func MapClientToSchemaClient(c client.Client) Client {
2015-08-18 05:57:27 +05:30
cl := Client{
Id: c.Credentials.ID,
RedirectURIs: make([]string, len(c.Metadata.RedirectURIs)),
2015-08-18 05:57:27 +05:30
}
for i, u := range c.Metadata.RedirectURIs {
2015-08-18 05:57:27 +05:30
cl.RedirectURIs[i] = u.String()
}
return cl
}
2016-04-16 05:53:27 +05:30
func MapClientToSchemaClientWithSecret(c client.Client) ClientWithSecret {
2015-08-18 05:57:27 +05:30
cl := ClientWithSecret{
Id: c.Credentials.ID,
Secret: c.Credentials.Secret,
RedirectURIs: make([]string, len(c.Metadata.RedirectURIs)),
2015-08-18 05:57:27 +05:30
}
for i, u := range c.Metadata.RedirectURIs {
2015-08-18 05:57:27 +05:30
cl.RedirectURIs[i] = u.String()
}
return cl
}