Skip to content

Commit 006019f

Browse files
authored
Merge pull request #35 from mittwald/role-creating-pki
add pki role creating
2 parents a1fe696 + 62fa5bc commit 006019f

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

pki.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,80 @@ func (k *PKI) RevokeIssuer(issuerName string) (*PKIRevokeIssuerResponse, error)
295295
return response, nil
296296
}
297297

298+
type PKICreateRoleRequest struct {
299+
IssuerRef string `json:"issuer_ref"`
300+
TTL string `json:"ttl,omitempty"`
301+
MaxTTL string `json:"max_ttl,omitempty"`
302+
AllowedDomains []string `json:"allowed_domains,omitempty"`
303+
AllowBareDomain bool `json:"allow_bare_domain,omitempty"`
304+
AllowGlobDomains bool `json:"allow_glob_domains,omitempty"`
305+
AllowWildcard bool `json:"allow_wildcard_certificates,omitempty"`
306+
AllowSubdomains bool `json:"allow_subdomains,omitempty"`
307+
ServerFlag bool `json:"server_flag,omitempty"`
308+
}
309+
310+
type PKIRoleResponse struct {
311+
AllowAnyName bool `json:"allow_any_name"`
312+
AllowBareDomains bool `json:"allow_bare_domains"`
313+
AllowGlobDomains bool `json:"allow_glob_domains"`
314+
AllowIPSans bool `json:"allow_ip_sans"`
315+
AllowLocalhost bool `json:"allow_localhost"`
316+
AllowSubdomains bool `json:"allow_subdomains"`
317+
AllowTokenDisplayname bool `json:"allow_token_displayname"`
318+
AllowWildcardCertificates bool `json:"allow_wildcard_certificates"`
319+
AllowedDomains []string `json:"allowed_domains"`
320+
AllowedDomainsTemplate bool `json:"allowed_domains_template"`
321+
AllowedOtherSans []string `json:"allowed_other_sans"`
322+
AllowedSerialNumbers []string `json:"allowed_serial_numbers"`
323+
AllowedURISans []string `json:"allowed_uri_sans"`
324+
AllowedURISansTemplate bool `json:"allowed_uri_sans_template"`
325+
AllowedUserIDs []string `json:"allowed_user_ids"`
326+
EnforceHostnames bool `json:"enforce_hostnames"`
327+
GenerateLease bool `json:"generate_lease"`
328+
IssuerRef string `json:"issuer_ref"`
329+
KeyUsage []string `json:"key_usage"`
330+
MaxTTL string `json:"max_ttl"`
331+
NoStore bool `json:"no_store"`
332+
NotAfter string `json:"not_after"`
333+
NotBeforeDuration string `json:"not_before_duration"`
334+
ServerFlag bool `json:"server_flag"`
335+
TTL string `json:"ttl"`
336+
UseCSRCommonName bool `json:"use_csr_common_name"`
337+
UseCSRSans bool `json:"use_csr_sans"`
338+
}
339+
340+
func (k *PKI) CreateOrUpdateRole(roleName string, pkiopts PKICreateRoleRequest) (*PKIRoleResponse, error) {
341+
response := &PKIRoleResponse{}
342+
err := k.client.Write(
343+
[]string{
344+
"v1",
345+
k.MountPoint,
346+
"roles",
347+
roleName,
348+
}, pkiopts, response, nil,
349+
)
350+
if err != nil {
351+
return nil, err
352+
}
353+
return response, nil
354+
}
355+
356+
func (k *PKI) ReadRole(roleName string) (*PKIRoleResponse, error) {
357+
response := &PKIRoleResponse{}
358+
err := k.client.Read(
359+
[]string{
360+
"v1",
361+
k.MountPoint,
362+
"roles",
363+
roleName,
364+
}, response, nil,
365+
)
366+
if err != nil {
367+
return nil, err
368+
}
369+
return response, nil
370+
}
371+
298372
func (k *PKI) mapError(err error) error {
299373
resErr := &api.ResponseError{}
300374
if errors.As(err, &resErr) {

0 commit comments

Comments
 (0)