This repository has been archived by the owner on Mar 6, 2024. It is now read-only.
forked from s7techlab/hlf-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 2
/
core.go
62 lines (49 loc) · 1.81 KB
/
core.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package ca
import (
"context"
"crypto/x509"
"crypto/x509/pkix"
"net/url"
)
type Core interface {
// Getting information about CA
CAInfo(ctx context.Context) (*ResponseCAInfo, error)
// Common operations over certificates
Register(ctx context.Context, req RegistrationRequest) (string, error)
Enroll(ctx context.Context, name, secret string, req *x509.CertificateRequest, opts ...EnrollOpt) (*x509.Certificate, interface{}, error)
Revoke(ctx context.Context, req RevocationRequest) (*pkix.CertificateList, error)
// Operations over identities
IdentityList(ctx context.Context) ([]Identity, error)
IdentityGet(ctx context.Context, enrollId string) (*Identity, error)
// Operations over certificates
CertificateList(ctx context.Context, opts ...CertificateListOpt) ([]*x509.Certificate, error)
// Operations over affiliations
// AffiliationList lists all affiliations and identities of identity affiliation
AffiliationList(ctx context.Context, rootAffiliation ...string) ([]Identity, []Affiliation, error)
AffiliationCreate(ctx context.Context, name string, opts ...AffiliationOpt) error
AffiliationDelete(ctx context.Context, name string, opts ...AffiliationOpt) ([]Identity, []Affiliation, error)
}
type EnrollOpts struct {
PrivateKey interface{}
}
type EnrollOpt func(opts *EnrollOpts) error
func WithEnrollPrivateKey(privateKey interface{}) EnrollOpt {
return func(opts *EnrollOpts) error {
opts.PrivateKey = privateKey
return nil
}
}
type CertificateListOpt func(values *url.Values) error
func WithEnrollId(enrollId string) CertificateListOpt {
return func(values *url.Values) error {
values.Add(`id`, enrollId)
return nil
}
}
type AffiliationOpt func(values *url.Values) error
func WithForce() AffiliationOpt {
return func(values *url.Values) error {
values.Set(`force`, `true`)
return nil
}
}