Skip to content

Commit

Permalink
Add ACME account to storeconfig command
Browse files Browse the repository at this point in the history
Signed-off-by: Emile Vauge <emile@vauge.com>
  • Loading branch information
emilevauge committed Sep 30, 2016
1 parent bb29d9c commit 4ad4b8e
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 180 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
glide.lock binary
30 changes: 15 additions & 15 deletions acme/acme.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,31 @@ func (a *ACME) CreateClusterConfig(leadership *cluster.Leadership, tlsConfig *tl
a.checkOnDemandDomain = checkOnDemandDomain
tlsConfig.Certificates = append(tlsConfig.Certificates, *a.defaultCertificate)
tlsConfig.GetCertificate = a.getCertificate
listener := func(object cluster.Object) error {
account := object.(*Account)
account.Init()
if !leadership.IsLeader() {
a.client, err = a.buildACMEClient(account)
if err != nil {
log.Errorf("Error building ACME client %+v: %s", object, err.Error())
}
}
return nil
}

datastore, err := cluster.NewDataStore(
staert.KvSource{
Store: leadership.Store,
Prefix: leadership.Store.Prefix + "/acme/account",
Prefix: a.Storage,
},
leadership.Pool.Ctx(), &Account{},
func(object cluster.Object) error {
account := object.(*Account)
account.Init()
if !leadership.IsLeader() {
a.client, err = a.buildACMEClient(account)
if err != nil {
log.Errorf("Error building ACME client %+v: %s", object, err.Error())
}
}

return nil
})
listener)
if err != nil {
return err
}

a.store = datastore
a.challengeProvider = newMemoryChallengeProvider(a.store)
a.challengeProvider = &challengeProvider{store: a.store}

ticker := time.NewTicker(24 * time.Hour)
leadership.Pool.AddGoCtx(func(ctx context.Context) {
Expand Down Expand Up @@ -227,7 +227,7 @@ func (a *ACME) CreateLocalConfig(tlsConfig *tls.Config, checkOnDemandDomain func

localStore := NewLocalStore(a.Storage)
a.store = localStore
a.challengeProvider = newMemoryChallengeProvider(a.store)
a.challengeProvider = &challengeProvider{store: a.store}

var needRegister bool
var account *Account
Expand Down
6 changes: 0 additions & 6 deletions acme/challengeProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ type challengeProvider struct {
lock sync.RWMutex
}

func newMemoryChallengeProvider(store cluster.Store) *challengeProvider {
return &challengeProvider{
store: store,
}
}

func (c *challengeProvider) getCertificate(domain string) (cert *tls.Certificate, exists bool) {
log.Debugf("Challenge GetCertificate %s", domain)
if !strings.HasSuffix(domain, ".acme.invalid") {
Expand Down
3 changes: 1 addition & 2 deletions acme/localStore.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ type LocalStore struct {
// NewLocalStore create a LocalStore
func NewLocalStore(file string) *LocalStore {
return &LocalStore{
file: file,
storageLock: sync.RWMutex{},
file: file,
}
}

Expand Down
10 changes: 8 additions & 2 deletions cluster/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ type Metadata struct {
Lock string
}

func (m *Metadata) marshall() error {
// NewMetadata returns new Metadata
func NewMetadata(object Object) *Metadata {
return &Metadata{object: object}
}

// Marshall marshalls object
func (m *Metadata) Marshall() error {
var err error
m.Object, err = json.Marshal(m.object)
return err
Expand Down Expand Up @@ -227,7 +233,7 @@ func (s *datastoreTransaction) Commit(object Object) error {
return fmt.Errorf("Transaction already used. Please begin a new one.")
}
s.Datastore.meta.object = object
err := s.Datastore.meta.marshall()
err := s.Datastore.meta.Marshall()
if err != nil {
return err
}
Expand Down
155 changes: 2 additions & 153 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4ad4b8e

Please sign in to comment.