-
Notifications
You must be signed in to change notification settings - Fork 39
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 #6 from coreos-inc/credstore
Create the credential store registration mechanism and wire it in
- Loading branch information
Showing
8 changed files
with
159 additions
and
78 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
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,22 @@ | ||
// Copyright 2016 CoreOS, Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package credential | ||
|
||
type Credential struct { | ||
ID string | ||
Secret string | ||
Service string | ||
Region string | ||
} |
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 @@ | ||
// Copyright 2016 CoreOS, Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package singlekey | ||
|
||
import ( | ||
"fmt" | ||
|
||
"gopkg.in/yaml.v2" | ||
|
||
"github.com/coreos-inc/hmacproxy/config" | ||
"github.com/coreos-inc/hmacproxy/credential" | ||
) | ||
|
||
type SingleAccessKey struct { | ||
credential.Credential | ||
} | ||
|
||
func (s SingleAccessKey) LoadCredential(keyID, serviceName, regionName string) (*credential.Credential, error) { | ||
if keyID != s.ID || serviceName != s.Service || regionName != s.Region { | ||
return nil, fmt.Errorf("Unknown key with key id: %s", keyID) | ||
} | ||
return &s.Credential, nil | ||
} | ||
|
||
func constructor(cfg *config.CredentialSourceConfig) (credential.CredentialStore, error) { | ||
reserialized, err := yaml.Marshal(cfg.Options) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to marshall configuration: %v", cfg.Options) | ||
} | ||
var parsed SingleAccessKey | ||
err = yaml.Unmarshal(reserialized, &parsed) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to parse configuration: %v", reserialized) | ||
} | ||
return parsed, nil | ||
} | ||
|
||
func init() { | ||
credential.RegisterCredentialStoreFacory("SingleCredential", constructor) | ||
} |
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,59 @@ | ||
// Copyright 2016 CoreOS, Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package credential | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/coreos-inc/hmacproxy/config" | ||
) | ||
|
||
type CredentialStoreConstructor func(*config.CredentialSourceConfig) (CredentialStore, error) | ||
|
||
var storeFactories = make(map[string]CredentialStoreConstructor) | ||
|
||
// RegisterNotifier makes a Fetcher available by the provided name. | ||
// If Register is called twice with the same name or if driver is nil, | ||
// it panics. | ||
func RegisterCredentialStoreFacory(name string, csf func(*config.CredentialSourceConfig) (CredentialStore, error)) { | ||
if name == "" { | ||
panic("credentials: could not register a CredentialStore with an empty name") | ||
} | ||
|
||
if csf == nil { | ||
panic("credentials: could not register a nil CredentialStore") | ||
} | ||
|
||
if _, dup := storeFactories[name]; dup { | ||
panic("credentials: RegisterCredentialStore called twice for " + name) | ||
} | ||
|
||
storeFactories[name] = csf | ||
} | ||
|
||
func CreateCredentialStore(cfg *config.CredentialSourceConfig) (cs CredentialStore, err error) { | ||
constructor, found := storeFactories[cfg.Type] | ||
if !found { | ||
err = fmt.Errorf("credentials: Unable to find credential store constructor for %s", cfg.Type) | ||
return | ||
} | ||
|
||
cs, err = constructor(cfg) | ||
return | ||
} | ||
|
||
type CredentialStore interface { | ||
LoadCredential(keyID, serviceName, regionName string) (*Credential, error) | ||
} |
This file was deleted.
Oops, something went wrong.
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