forked from kubernetes-retired/etcdadm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubernetes-retired#147 from justinsb/more_certs
Make PKI library richer, including in-memory keypairs
- Loading branch information
Showing
4 changed files
with
161 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ go_library( | |
srcs = [ | ||
"certs.go", | ||
"fs.go", | ||
"inmem.go", | ||
"store.go", | ||
"utils.go", | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package pki | ||
|
||
import "sync" | ||
|
||
type InMemoryMutableKeypair struct { | ||
Keypair *Keypair | ||
} | ||
|
||
var _ MutableKeypair = &InMemoryMutableKeypair{} | ||
|
||
func (s *InMemoryMutableKeypair) MutateKeypair(mutator func(keypair *Keypair) error) (*Keypair, error) { | ||
keypair := &Keypair{} | ||
|
||
if s.Keypair != nil { | ||
*keypair = *s.Keypair | ||
} | ||
|
||
if err := mutator(keypair); err != nil { | ||
return nil, err | ||
} | ||
|
||
if s.Keypair == nil { | ||
s.Keypair = &Keypair{} | ||
} | ||
*s.Keypair = *keypair | ||
return keypair, nil | ||
} | ||
|
||
type InMemoryStore struct { | ||
mutex sync.Mutex | ||
data map[string]*InMemoryMutableKeypair | ||
} | ||
|
||
var _ Store = &InMemoryStore{} | ||
|
||
func NewInMemoryStore() *InMemoryStore { | ||
return &InMemoryStore{ | ||
data: make(map[string]*InMemoryMutableKeypair), | ||
} | ||
} | ||
|
||
func (s *InMemoryStore) Keypair(name string) MutableKeypair { | ||
s.mutex.Lock() | ||
defer s.mutex.Unlock() | ||
|
||
k := s.data[name] | ||
if k == nil { | ||
k = &InMemoryMutableKeypair{} | ||
s.data[name] = k | ||
} | ||
return k | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters