storage: add connector object to backend storage.
This commit is contained in:
@@ -20,6 +20,7 @@ const (
|
||||
kindKeys = "SigningKey"
|
||||
kindPassword = "Password"
|
||||
kindOfflineSessions = "OfflineSessions"
|
||||
kindConnector = "Connector"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -30,6 +31,7 @@ const (
|
||||
resourceKeys = "signingkeies" // Kubernetes attempts to pluralize.
|
||||
resourcePassword = "passwords"
|
||||
resourceOfflineSessions = "offlinesessionses" // Again attempts to pluralize.
|
||||
resourceConnector = "connectors"
|
||||
)
|
||||
|
||||
// Config values for the Kubernetes storage type.
|
||||
@@ -173,6 +175,10 @@ func (cli *client) CreateOfflineSessions(o storage.OfflineSessions) error {
|
||||
return cli.post(resourceOfflineSessions, cli.fromStorageOfflineSessions(o))
|
||||
}
|
||||
|
||||
func (cli *client) CreateConnector(c storage.Connector) error {
|
||||
return cli.post(resourceConnector, cli.fromStorageConnector(c))
|
||||
}
|
||||
|
||||
func (cli *client) GetAuthRequest(id string) (storage.AuthRequest, error) {
|
||||
var req AuthRequest
|
||||
if err := cli.get(resourceAuthRequest, id, &req); err != nil {
|
||||
@@ -271,6 +277,14 @@ func (cli *client) getOfflineSessions(userID string, connID string) (o OfflineSe
|
||||
return o, nil
|
||||
}
|
||||
|
||||
func (cli *client) GetConnector(id string) (storage.Connector, error) {
|
||||
var c Connector
|
||||
if err := cli.get(resourceConnector, id, &c); err != nil {
|
||||
return storage.Connector{}, err
|
||||
}
|
||||
return toStorageConnector(c), nil
|
||||
}
|
||||
|
||||
func (cli *client) ListClients() ([]storage.Client, error) {
|
||||
return nil, errors.New("not implemented")
|
||||
}
|
||||
@@ -298,6 +312,20 @@ func (cli *client) ListPasswords() (passwords []storage.Password, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (cli *client) ListConnectors() (connectors []storage.Connector, err error) {
|
||||
var connectorList ConnectorList
|
||||
if err = cli.list(resourceConnector, &connectorList); err != nil {
|
||||
return connectors, fmt.Errorf("failed to list connectors: %v", err)
|
||||
}
|
||||
|
||||
connectors = make([]storage.Connector, len(connectorList.Connectors))
|
||||
for i, connector := range connectorList.Connectors {
|
||||
connectors[i] = toStorageConnector(connector)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (cli *client) DeleteAuthRequest(id string) error {
|
||||
return cli.delete(resourceAuthRequest, id)
|
||||
}
|
||||
@@ -337,6 +365,10 @@ func (cli *client) DeleteOfflineSessions(userID string, connID string) error {
|
||||
return cli.delete(resourceOfflineSessions, o.ObjectMeta.Name)
|
||||
}
|
||||
|
||||
func (cli *client) DeleteConnector(id string) error {
|
||||
return cli.delete(resourceConnector, id)
|
||||
}
|
||||
|
||||
func (cli *client) UpdateRefreshToken(id string, updater func(old storage.RefreshToken) (storage.RefreshToken, error)) error {
|
||||
r, err := cli.getRefreshToken(id)
|
||||
if err != nil {
|
||||
@@ -446,6 +478,23 @@ func (cli *client) UpdateAuthRequest(id string, updater func(a storage.AuthReque
|
||||
return cli.put(resourceAuthRequest, id, newReq)
|
||||
}
|
||||
|
||||
func (cli *client) UpdateConnector(id string, updater func(a storage.Connector) (storage.Connector, error)) error {
|
||||
var c Connector
|
||||
err := cli.get(resourceConnector, id, &c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
updated, err := updater(toStorageConnector(c))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
newConn := cli.fromStorageConnector(updated)
|
||||
newConn.ObjectMeta = c.ObjectMeta
|
||||
return cli.put(resourceConnector, id, newConn)
|
||||
}
|
||||
|
||||
func (cli *client) GarbageCollect(now time.Time) (result storage.GCResult, err error) {
|
||||
var authRequests AuthRequestList
|
||||
if err := cli.list(resourceAuthRequest, &authRequests); err != nil {
|
||||
|
@@ -74,6 +74,14 @@ var thirdPartyResources = []k8sapi.ThirdPartyResource{
|
||||
Description: "User sessions with an active refresh token.",
|
||||
Versions: []k8sapi.APIVersion{{Name: "v1"}},
|
||||
},
|
||||
{
|
||||
ObjectMeta: k8sapi.ObjectMeta{
|
||||
Name: "connector.oidc.coreos.com",
|
||||
},
|
||||
TypeMeta: tprMeta,
|
||||
Description: "Connectors available for login",
|
||||
Versions: []k8sapi.APIVersion{{Name: "v1"}},
|
||||
},
|
||||
}
|
||||
|
||||
// There will only ever be a single keys resource. Maintain this by setting a
|
||||
@@ -513,3 +521,52 @@ func toStorageOfflineSessions(o OfflineSessions) storage.OfflineSessions {
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// Connector is a mirrored struct from storage with JSON struct tags and Kubernetes
|
||||
// type metadata.
|
||||
type Connector struct {
|
||||
k8sapi.TypeMeta `json:",inline"`
|
||||
k8sapi.ObjectMeta `json:"metadata,omitempty"`
|
||||
|
||||
ID string `json:"id,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
ResourceVersion string `json:"resourceVersion,omitempty"`
|
||||
// Config holds connector specific configuration information
|
||||
Config []byte `json:"config,omitempty"`
|
||||
}
|
||||
|
||||
func (cli *client) fromStorageConnector(c storage.Connector) Connector {
|
||||
return Connector{
|
||||
TypeMeta: k8sapi.TypeMeta{
|
||||
Kind: kindConnector,
|
||||
APIVersion: cli.apiVersion,
|
||||
},
|
||||
ObjectMeta: k8sapi.ObjectMeta{
|
||||
Name: c.ID,
|
||||
Namespace: cli.namespace,
|
||||
},
|
||||
ID: c.ID,
|
||||
Type: c.Type,
|
||||
Name: c.Name,
|
||||
ResourceVersion: c.ResourceVersion,
|
||||
Config: c.Config,
|
||||
}
|
||||
}
|
||||
|
||||
func toStorageConnector(c Connector) storage.Connector {
|
||||
return storage.Connector{
|
||||
ID: c.ID,
|
||||
Type: c.Type,
|
||||
Name: c.Name,
|
||||
ResourceVersion: c.ResourceVersion,
|
||||
Config: c.Config,
|
||||
}
|
||||
}
|
||||
|
||||
// ConnectorList is a list of Connectors.
|
||||
type ConnectorList struct {
|
||||
k8sapi.TypeMeta `json:",inline"`
|
||||
k8sapi.ListMeta `json:"metadata,omitempty"`
|
||||
Connectors []Connector `json:"items"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user