mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-29 10:26:29 +02:00
* initial core-zero import implementation * Update /config/import openapi description and use PUT instead of POST * update import ui tests * Add 413 as a possible response for /config/import * Options/Settings type conversion tests and related bugfixes * Fixes for proto type conversion and tests * Update core-zero import client * Update core-zero import client * Update import api and environment detection * update go.mod * remove old testdata * Remove usage of deleted setting after merge * remove extra newline from --version output
41 lines
1 KiB
Go
41 lines
1 KiB
Go
package config
|
|
|
|
import (
|
|
"encoding/base64"
|
|
|
|
"github.com/pomerium/pomerium/pkg/cryptutil"
|
|
"github.com/pomerium/pomerium/pkg/grpc/crypt"
|
|
)
|
|
|
|
// A PublicKeyEncryptionKeyOptions represents options for a public key encryption key.
|
|
type PublicKeyEncryptionKeyOptions struct {
|
|
ID string `mapstructure:"id" yaml:"id"`
|
|
Data string `mapstructure:"data" yaml:"data"` // base64-encoded
|
|
}
|
|
|
|
// GetAuditKey gets the audit key from the options. If no audit key is provided it will return (nil, nil).
|
|
func (o *Options) GetAuditKey() (*cryptutil.PublicKeyEncryptionKey, error) {
|
|
if o.AuditKey == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
raw, err := base64.StdEncoding.DecodeString(o.AuditKey.Data)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return cryptutil.NewPublicKeyEncryptionKeyWithID(o.AuditKey.ID, raw)
|
|
}
|
|
|
|
func (o *PublicKeyEncryptionKeyOptions) ToProto() *crypt.PublicKeyEncryptionKey {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
decoded, err := base64.StdEncoding.DecodeString(o.Data)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return &crypt.PublicKeyEncryptionKey{
|
|
Id: o.ID,
|
|
Data: decoded,
|
|
}
|
|
}
|