-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for rotating credentials.
- Loading branch information
Showing
4 changed files
with
191 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package local | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"time" | ||
|
||
v1 "github.com/conductorone/baton-sdk/pb/c1/connectorapi/baton/v1" | ||
"github.com/conductorone/baton-sdk/pkg/provisioner" | ||
"github.com/conductorone/baton-sdk/pkg/tasks" | ||
"github.com/conductorone/baton-sdk/pkg/types" | ||
) | ||
|
||
type localCredentialRotator struct { | ||
dbPath string | ||
o sync.Once | ||
|
||
resourceId string | ||
resourceType string | ||
} | ||
|
||
func (m *localCredentialRotator) Next(ctx context.Context) (*v1.Task, time.Duration, error) { | ||
var task *v1.Task | ||
m.o.Do(func() { | ||
task = &v1.Task{ | ||
TaskType: &v1.Task_CreateAccount{}, | ||
} | ||
}) | ||
return task, 0, nil | ||
} | ||
|
||
func (m *localCredentialRotator) Process(ctx context.Context, task *v1.Task, cc types.ConnectorClient) error { | ||
accountManager := provisioner.NewCredentialRotator(cc, m.dbPath, m.resourceId, m.resourceType) | ||
|
||
err := accountManager.Run(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = accountManager.Close(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// NewGranter returns a task manager that queues a sync task. | ||
func NewCredentialRotator(ctx context.Context, dbPath string, resourceId string, resourceType string) tasks.Manager { | ||
return &localCredentialRotator{ | ||
dbPath: dbPath, | ||
resourceId: resourceId, | ||
resourceType: resourceType, | ||
} | ||
} |