2021-05-03 19:48:20 +00:00
|
|
|
package mgmt
|
|
|
|
|
|
|
|
const (
|
2021-05-06 06:02:42 +00:00
|
|
|
// DefaultAuthorityID is the default AuthorityID. This will be the ID
|
|
|
|
// of the first Authority created, as well as the default AuthorityID
|
|
|
|
// if one is not specified in the configuration.
|
2021-05-03 19:48:20 +00:00
|
|
|
DefaultAuthorityID = "00000000-0000-0000-0000-000000000000"
|
|
|
|
)
|
|
|
|
|
2021-05-24 20:38:24 +00:00
|
|
|
/*
|
2021-05-06 06:02:42 +00:00
|
|
|
func CreateAuthority(ctx context.Context, db DB, options ...AuthorityOption) (*AuthConfig, error) {
|
|
|
|
ac := NewDefaultAuthConfig()
|
2021-05-03 19:48:20 +00:00
|
|
|
|
2021-05-06 06:02:42 +00:00
|
|
|
for _, o := range options {
|
|
|
|
if err := o(ac); err != nil {
|
2021-05-03 19:48:20 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-06 06:02:42 +00:00
|
|
|
if err := db.CreateAuthConfig(ctx, ac); err != nil {
|
|
|
|
return nil, errors.Wrap(err, "error creating authConfig")
|
2021-05-03 19:48:20 +00:00
|
|
|
}
|
|
|
|
|
2021-05-06 06:02:42 +00:00
|
|
|
// Generate default JWK provisioner.
|
2021-05-03 19:48:20 +00:00
|
|
|
|
2021-05-06 06:02:42 +00:00
|
|
|
provOpts := []ProvisionerOption{WithPassword("pass")}
|
|
|
|
prov, err := CreateProvisioner(ctx, db, "JWK", "changeme", provOpts...)
|
2021-05-03 19:48:20 +00:00
|
|
|
if err != nil {
|
2021-05-06 06:02:42 +00:00
|
|
|
// TODO should we try to clean up?
|
|
|
|
return nil, WrapErrorISE(err, "error creating first provisioner")
|
2021-05-03 19:48:20 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 04:07:25 +00:00
|
|
|
adm := &Admin{
|
|
|
|
ProvisionerID: prov.ID,
|
|
|
|
Subject: "Change Me",
|
|
|
|
Type: AdminTypeSuper,
|
|
|
|
}
|
|
|
|
if err := db.CreateAdmin(ctx, adm); err != nil {
|
2021-05-06 06:02:42 +00:00
|
|
|
// TODO should we try to clean up?
|
2021-05-18 04:07:25 +00:00
|
|
|
return nil, WrapErrorISE(err, "error creating first admin")
|
2021-05-03 19:48:20 +00:00
|
|
|
}
|
|
|
|
|
2021-05-06 06:02:42 +00:00
|
|
|
ac.Provisioners = []*Provisioner{prov}
|
2021-05-18 04:07:25 +00:00
|
|
|
ac.Admins = []*Admin{adm}
|
2021-05-06 06:02:42 +00:00
|
|
|
|
|
|
|
return ac, nil
|
2021-05-03 19:48:20 +00:00
|
|
|
}
|
2021-05-24 20:38:24 +00:00
|
|
|
*/
|