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{
|
2016-01-13 06:46:28 +05:30
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-01-13 06:46:28 +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,
|
2016-01-13 06:46:28 +05:30
|
|
|
RedirectURIs: make([]string, len(c.Metadata.RedirectURIs)),
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
2016-01-13 06:46:28 +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,
|
2016-01-13 06:46:28 +05:30
|
|
|
RedirectURIs: make([]string, len(c.Metadata.RedirectURIs)),
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
2016-01-13 06:46:28 +05:30
|
|
|
for i, u := range c.Metadata.RedirectURIs {
|
2015-08-18 05:57:27 +05:30
|
|
|
cl.RedirectURIs[i] = u.String()
|
|
|
|
}
|
|
|
|
return cl
|
|
|
|
}
|