-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
bb0358e
commit 7cc134a
Showing
12 changed files
with
142 additions
and
104 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
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
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,67 @@ | ||
// +build !oss | ||
|
||
/* | ||
* Copyright 2021 Dgraph Labs, Inc. All rights reserved. | ||
* | ||
* Licensed under the Dgraph Community License (the "License"); you | ||
* may not use this file except in compliance with the License. You | ||
* may obtain a copy of the License at | ||
* | ||
* https://github.com/dgraph-io/dgraph/blob/master/licenses/DCL.txt | ||
*/ | ||
|
||
package ee | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
|
||
"github.com/dgraph-io/ristretto/z" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// GetKeys returns the ACL and encryption keys as configured by the user | ||
// through the --acl, --encryption, and --vault flags. On OSS builds, | ||
// this function always returns an error. | ||
func GetKeys(config *viper.Viper) (*Keys, error) { | ||
keys := &Keys{} | ||
var err error | ||
|
||
aclSuperFlag := z.NewSuperFlag(config.GetString("acl")).MergeAndCheckDefault(AclDefaults) | ||
encSuperFlag := z.NewSuperFlag(config.GetString("encryption")).MergeAndCheckDefault(EncDefaults) | ||
|
||
// Get AclKey and EncKey from vault / acl / encryption SuperFlags | ||
keys.AclKey, keys.EncKey = vaultGetKeys(config) | ||
aclKeyFile := aclSuperFlag.GetPath(flagAclSecretFile) | ||
if aclKeyFile != "" { | ||
if keys.AclKey != nil { | ||
return nil, fmt.Errorf("flags: ACL secret key set in both vault and acl flags") | ||
} | ||
if keys.AclKey, err = ioutil.ReadFile(aclKeyFile); err != nil { | ||
return nil, fmt.Errorf("error reading ACL secret key from file: %s: %s", aclKeyFile, err) | ||
} | ||
} | ||
if l := len(keys.AclKey); keys.AclKey != nil && l < 32 { | ||
return nil, fmt.Errorf( | ||
"ACL secret key must have length of at least 32 bytes, got %d bytes instead", l) | ||
} | ||
encKeyFile := encSuperFlag.GetPath(flagEncKeyFile) | ||
if encKeyFile != "" { | ||
if keys.EncKey != nil { | ||
return nil, fmt.Errorf("flags: Encryption key set in both vault and encryption flags") | ||
} | ||
if keys.EncKey, err = ioutil.ReadFile(encKeyFile); err != nil { | ||
return nil, fmt.Errorf("error reading encryption key from file: %s: %s", encKeyFile, err) | ||
} | ||
} | ||
if l := len(keys.EncKey); keys.EncKey != nil && l != 16 && l != 32 && l != 64 { | ||
return nil, fmt.Errorf( | ||
"encryption key must have length of 16, 32, or 64 bytes, got %d bytes instead", l) | ||
} | ||
|
||
// Get remaining keys | ||
keys.AclAccessTtl = aclSuperFlag.GetDuration(flagAclAccessTtl) | ||
keys.AclRefreshTtl = aclSuperFlag.GetDuration(flagAclRefreshTtl) | ||
|
||
return keys, nil | ||
} |
Oops, something went wrong.