Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,6 @@ replace certwarden-backend/pkg/storage => /pkg/storage

replace certwarden-backend/pkg/storage/sqlite3 => /pkg/storage/sqlite3

replace certwarden-backend/pkg/test_helpers => /pkg/test_helpers
replace certwarden-backend/pkg/helpers_test => /pkg/helpers_test

replace certwarden-backend/pkg/validation => /pkg/validation
25 changes: 13 additions & 12 deletions pkg/domain/acme_accounts/handlers_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ import (

// NewPayload is the payload struct for creating a new account
type NewPayload struct {
Name *string `json:"name"`
Description *string `json:"description"`
AcmeServerID *int `json:"acme_server_id"`
PrivateKeyID *int `json:"private_key_id"`
Status string `json:"-"`
Email *string `json:"email"`
AcceptedTos *bool `json:"accepted_tos"`
CreatedAt int `json:"-"`
UpdatedAt int `json:"-"`
Kid string `json:"-"`
Name *string `json:"name"`
Description *string `json:"description"`
AcmeServerID *int `json:"acme_server_id"`
PrivateKeyID *int `json:"private_key_id"`
Status string `json:"-"`
Email *string `json:"email"`
AcceptedTos *bool `json:"accepted_tos"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
Kid string `json:"-"`
}

// PostNewAccount is the handler to save a new account to storage. No ACME
Expand Down Expand Up @@ -89,8 +89,9 @@ func (service *Service) PostNewAccount(w http.ResponseWriter, r *http.Request) *

// add additional details to the payload before saving
payload.Status = "unknown"
payload.CreatedAt = int(time.Now().Unix())
payload.UpdatedAt = payload.CreatedAt
t := time.Now()
payload.CreatedAt = t
payload.UpdatedAt = t
payload.Kid = ""

// Save new account details to storage.
Expand Down
17 changes: 9 additions & 8 deletions pkg/domain/acme_servers/handlers_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (

// NewPayload is used to post a new Server
type NewPayload struct {
Name *string `json:"name"`
Description *string `json:"description"`
DirectoryURL *string `json:"directory_url"`
IsStaging *bool `json:"is_staging"`
CreatedAt int `json:"-"`
UpdatedAt int `json:"-"`
Name *string `json:"name"`
Description *string `json:"description"`
DirectoryURL *string `json:"directory_url"`
IsStaging *bool `json:"is_staging"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
}

// PostNewServer creates a new server, saves it to storage, and starts an *acme.Service
Expand Down Expand Up @@ -62,8 +62,9 @@ func (service *Service) PostNewServer(w http.ResponseWriter, r *http.Request) *o
// end validation

// add additional details to the payload before saving
payload.CreatedAt = int(time.Now().Unix())
payload.UpdatedAt = payload.CreatedAt
t := time.Now()
payload.CreatedAt = t
payload.UpdatedAt = t

// save new key to storage, which also returns the new server
newServer, err := service.storage.PostNewServer(payload)
Expand Down
14 changes: 7 additions & 7 deletions pkg/domain/acme_servers/handlers_put.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
// UpdatePayload is the struct for editing an existing Server's
// information (only certain fields are editable)
type UpdatePayload struct {
ID int `json:"-"`
Name *string `json:"name"`
Description *string `json:"description"`
DirectoryURL *string `json:"directory_url"`
IsStaging *bool `json:"is_staging"`
UpdatedAt int `json:"-"`
ID int `json:"-"`
Name *string `json:"name"`
Description *string `json:"description"`
DirectoryURL *string `json:"directory_url"`
IsStaging *bool `json:"is_staging"`
UpdatedAt time.Time `json:"-"`
}

// PutServerUpdate updates a Server that already exists in storage.
Expand Down Expand Up @@ -66,7 +66,7 @@ func (service *Service) PutServerUpdate(w http.ResponseWriter, r *http.Request)
// end validation

// add additional details to the payload before saving
payload.UpdatedAt = int(time.Now().Unix())
payload.UpdatedAt = time.Now()

// save updated key info to storage
updatedServer, err := service.storage.PutServerUpdate(payload)
Expand Down
83 changes: 38 additions & 45 deletions pkg/domain/certificates/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ type Certificate struct {
ID int
Name string
Description string
CertificateKey private_keys.Key
CertificateAccount acme_accounts.Account
Key private_keys.Key
Account acme_accounts.Account
Subject string
SubjectAltNames []string
Organization string
Expand All @@ -39,15 +39,15 @@ type Certificate struct {
// certificateSummaryResponse is a JSON response containing only
// fields desired for the summary
type certificateSummaryResponse struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
CertificateKey certificateKeySummaryResponse `json:"private_key"`
CertificateAccount certificateAccountSummaryResponse `json:"acme_account"`
Subject string `json:"subject"`
SubjectAltNames []string `json:"subject_alts"`
ApiKeyViaUrl bool `json:"api_key_via_url"`
LastAccess int64 `json:"last_access"`
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Key certificateKeySummaryResponse `json:"private_key"`
Account certificateAccountSummaryResponse `json:"acme_account"`
Subject string `json:"subject"`
SubjectAltNames []string `json:"subject_alts"`
ApiKeyViaUrl bool `json:"api_key_via_url"`
LastAccess int64 `json:"last_access"`
}

type certificateKeySummaryResponse struct {
Expand All @@ -73,18 +73,18 @@ func (cert Certificate) summaryResponse() certificateSummaryResponse {
ID: cert.ID,
Name: cert.Name,
Description: cert.Description,
CertificateKey: certificateKeySummaryResponse{
ID: cert.CertificateKey.ID,
Name: cert.CertificateKey.Name,
Algorithm: cert.CertificateKey.Algorithm,
Key: certificateKeySummaryResponse{
ID: cert.Key.ID,
Name: cert.Key.Name,
Algorithm: cert.Key.Algorithm,
},
CertificateAccount: certificateAccountSummaryResponse{
ID: cert.CertificateAccount.ID,
Name: cert.CertificateAccount.Name,
Account: certificateAccountSummaryResponse{
ID: cert.Account.ID,
Name: cert.Account.Name,
CertAccountServer: certificateAccountServerSummaryResponse{
ID: cert.CertificateAccount.AcmeServer.ID,
Name: cert.CertificateAccount.AcmeServer.Name,
IsStaging: cert.CertificateAccount.AcmeServer.IsStaging,
ID: cert.Account.AcmeServer.ID,
Name: cert.Account.AcmeServer.Name,
IsStaging: cert.Account.AcmeServer.IsStaging,
},
},
Subject: cert.Subject,
Expand All @@ -98,40 +98,33 @@ func (cert Certificate) summaryResponse() certificateSummaryResponse {
// fields that can be returned as JSON
type certificateDetailedResponse struct {
certificateSummaryResponse
Organization string `json:"organization"`
OrganizationalUnit string `json:"organizational_unit"`
Country string `json:"country"`
State string `json:"state"`
City string `json:"city"`
CSRExtraExtensions []CertExtensionJSON `json:"csr_extra_extensions"`
PreferredRootCN string `json:"preferred_root_cn"`
Profile string `json:"profile"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
ApiKey string `json:"api_key"`
ApiKeyNew string `json:"api_key_new,omitempty"`
PostProcessingCommand string `json:"post_processing_command"`
PostProcessingEnvironment []string `json:"post_processing_environment"`
PostProcessingClientAddress string `json:"post_processing_client_address"`
PostProcessingClientKeyB64 string `json:"post_processing_client_key"`
Organization string `json:"organization"`
OrganizationalUnit string `json:"organizational_unit"`
Country string `json:"country"`
State string `json:"state"`
City string `json:"city"`
CSRExtraExtensions []CertExtension `json:"csr_extra_extensions"`
PreferredRootCN string `json:"preferred_root_cn"`
Profile string `json:"profile"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
ApiKey string `json:"api_key"`
ApiKeyNew string `json:"api_key_new,omitempty"`
PostProcessingCommand string `json:"post_processing_command"`
PostProcessingEnvironment []string `json:"post_processing_environment"`
PostProcessingClientAddress string `json:"post_processing_client_address"`
PostProcessingClientKeyB64 string `json:"post_processing_client_key"`
}

func (cert Certificate) detailedResponse() certificateDetailedResponse {
// convert extensions to json output obj
extraExtensions := []CertExtensionJSON{}
for i := range cert.CSRExtraExtensions {
oneExt := cert.CSRExtraExtensions[i].toJSONObj()
extraExtensions = append(extraExtensions, oneExt)
}

return certificateDetailedResponse{
certificateSummaryResponse: cert.summaryResponse(),
Organization: cert.Organization,
OrganizationalUnit: cert.OrganizationalUnit,
Country: cert.Country,
State: cert.State,
City: cert.City,
CSRExtraExtensions: extraExtensions,
CSRExtraExtensions: cert.CSRExtraExtensions,
PreferredRootCN: cert.PreferredRootCN,
Profile: cert.Profile,
CreatedAt: cert.CreatedAt.Unix(),
Expand Down
Loading