certificates/authority/mgmt/config.go

49 lines
1.2 KiB
Go
Raw Normal View History

2021-05-03 12:48:20 -07:00
package mgmt
const (
2021-05-05 23:02:42 -07: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 12:48:20 -07:00
DefaultAuthorityID = "00000000-0000-0000-0000-000000000000"
)
2021-05-24 13:38:24 -07:00
/*
2021-05-05 23:02:42 -07:00
func CreateAuthority(ctx context.Context, db DB, options ...AuthorityOption) (*AuthConfig, error) {
ac := NewDefaultAuthConfig()
2021-05-03 12:48:20 -07:00
2021-05-05 23:02:42 -07:00
for _, o := range options {
if err := o(ac); err != nil {
2021-05-03 12:48:20 -07:00
return nil, err
}
}
2021-05-05 23:02:42 -07:00
if err := db.CreateAuthConfig(ctx, ac); err != nil {
return nil, errors.Wrap(err, "error creating authConfig")
2021-05-03 12:48:20 -07:00
}
2021-05-05 23:02:42 -07:00
// Generate default JWK provisioner.
2021-05-03 12:48:20 -07:00
2021-05-05 23:02:42 -07:00
provOpts := []ProvisionerOption{WithPassword("pass")}
prov, err := CreateProvisioner(ctx, db, "JWK", "changeme", provOpts...)
2021-05-03 12:48:20 -07:00
if err != nil {
2021-05-05 23:02:42 -07:00
// TODO should we try to clean up?
return nil, WrapErrorISE(err, "error creating first provisioner")
2021-05-03 12:48:20 -07:00
}
2021-05-17 21:07:25 -07:00
adm := &Admin{
ProvisionerID: prov.ID,
Subject: "Change Me",
Type: AdminTypeSuper,
}
if err := db.CreateAdmin(ctx, adm); err != nil {
2021-05-05 23:02:42 -07:00
// TODO should we try to clean up?
2021-05-17 21:07:25 -07:00
return nil, WrapErrorISE(err, "error creating first admin")
2021-05-03 12:48:20 -07:00
}
2021-05-05 23:02:42 -07:00
ac.Provisioners = []*Provisioner{prov}
2021-05-17 21:07:25 -07:00
ac.Admins = []*Admin{adm}
2021-05-05 23:02:42 -07:00
return ac, nil
2021-05-03 12:48:20 -07:00
}
2021-05-24 13:38:24 -07:00
*/