Merge pull request #1115 from harshavardhana/configv4-to-configv5
migrate from ConfigV4 to ConfigV5, rename Signature to API
This commit is contained in:
+3
-3
@@ -25,8 +25,8 @@ import (
|
||||
|
||||
"github.com/minio/mc/pkg/client"
|
||||
"github.com/minio/mc/pkg/client/fs"
|
||||
"github.com/minio/mc/pkg/client/s3"
|
||||
"github.com/minio/mc/pkg/client/s3v2"
|
||||
"github.com/minio/mc/pkg/client/s3v4"
|
||||
"github.com/minio/minio/pkg/probe"
|
||||
)
|
||||
|
||||
@@ -156,10 +156,10 @@ func getNewClient(urlStr string, auth hostConfig) (client.Client, *probe.Error)
|
||||
|
||||
var s3Client client.Client
|
||||
var err *probe.Error
|
||||
if auth.Signature == "v2" {
|
||||
if auth.API == "S3v2" {
|
||||
s3Client, err = s3v2.New(s3Config)
|
||||
} else {
|
||||
s3Client, err = s3.New(s3Config)
|
||||
s3Client, err = s3v4.New(s3Config)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err.Trace()
|
||||
|
||||
@@ -147,7 +147,7 @@ func listAliases() {
|
||||
fatalIf(err.Trace(configPath), "Unable to load config path")
|
||||
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV4)
|
||||
newConf := config.Data().(*configV5)
|
||||
for k, v := range newConf.Aliases {
|
||||
Prints("%s\n", AliasMessage{
|
||||
op: "list",
|
||||
@@ -173,7 +173,7 @@ func removeAlias(alias string) {
|
||||
}
|
||||
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV4)
|
||||
newConf := config.Data().(*configV5)
|
||||
if _, ok := newConf.Aliases[alias]; !ok {
|
||||
fatalIf(errDummy().Trace(), fmt.Sprintf("Alias ‘%s’ does not exist.", alias))
|
||||
}
|
||||
@@ -209,7 +209,7 @@ func addAlias(alias, url string) {
|
||||
fatalIf(errDummy().Trace(), fmt.Sprintf("Alias name ‘%s’ is invalid, valid examples are: mybucket, Area51, Grand-Nagus", alias))
|
||||
}
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV4)
|
||||
newConf := config.Data().(*configV5)
|
||||
if oldURL, ok := newConf.Aliases[alias]; ok {
|
||||
fatalIf(errDummy().Trace(), fmt.Sprintf("Alias ‘%s’ already exists for ‘%s’.", alias, oldURL))
|
||||
}
|
||||
|
||||
+16
-16
@@ -31,9 +31,9 @@ EXAMPLES:
|
||||
$ mc config {{.Name}} add s3.amazonaws.com BKIKJAA5BMMU2RHO6IBB V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12
|
||||
$ set -o history
|
||||
|
||||
2. Add host configuration for a URL, using old signature v2. For security reasons turn off bash history
|
||||
2. Add host configuration for a URL, using s3 api v2. For security reasons turn off bash history
|
||||
$ set +o history
|
||||
$ mc config {{.Name}} add s3.amazonaws.com BKIKJAA5BMMU2RHO6IBB V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12 v2
|
||||
$ mc config {{.Name}} add s3.amazonaws.com BKIKJAA5BMMU2RHO6IBB V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12 S3v2
|
||||
$ set -o history
|
||||
|
||||
3. List all hosts.
|
||||
@@ -51,7 +51,7 @@ type HostMessage struct {
|
||||
Host string `json:"host"`
|
||||
AccessKeyID string `json:"accessKeyId,omitempty"`
|
||||
SecretAccessKey string `json:"secretAccessKey,omitempty"`
|
||||
Signature string `json:"signature,omitempty"`
|
||||
API string `json:"api,omitempty"`
|
||||
}
|
||||
|
||||
// String colorized host message
|
||||
@@ -61,7 +61,7 @@ func (a HostMessage) String() string {
|
||||
if a.AccessKeyID != "" || a.SecretAccessKey != "" {
|
||||
message += console.Colorize("AccessKeyID", fmt.Sprintf("<- %s,", a.AccessKeyID))
|
||||
message += console.Colorize("SecretAccessKey", fmt.Sprintf(" %s,", a.SecretAccessKey))
|
||||
message += console.Colorize("Signature", fmt.Sprintf(" %s", a.Signature))
|
||||
message += console.Colorize("API", fmt.Sprintf(" %s", a.API))
|
||||
}
|
||||
return message
|
||||
}
|
||||
@@ -115,7 +115,7 @@ func mainConfigHost(ctx *cli.Context) {
|
||||
// set new custom coloring
|
||||
console.SetCustomTheme(map[string]*color.Color{
|
||||
"Host": color.New(color.FgCyan, color.Bold),
|
||||
"Signature": color.New(color.FgYellow, color.Bold),
|
||||
"API": color.New(color.FgYellow, color.Bold),
|
||||
"HostMessage": color.New(color.FgGreen, color.Bold),
|
||||
"AccessKeyID": color.New(color.FgBlue, color.Bold),
|
||||
"SecretAccessKey": color.New(color.FgRed, color.Bold),
|
||||
@@ -143,14 +143,14 @@ func listHosts() {
|
||||
fatalIf(err.Trace(configPath), "Unable to load config path")
|
||||
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV4)
|
||||
newConf := config.Data().(*configV5)
|
||||
for k, v := range newConf.Hosts {
|
||||
Prints("%s\n", HostMessage{
|
||||
op: "list",
|
||||
Host: k,
|
||||
AccessKeyID: v.AccessKeyID,
|
||||
SecretAccessKey: v.SecretAccessKey,
|
||||
Signature: v.Signature,
|
||||
API: v.API,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ func removeHost(hostGlob string) {
|
||||
fatalIf(err.Trace(configPath), "Unable to load config path")
|
||||
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV4)
|
||||
newConf := config.Data().(*configV5)
|
||||
if _, ok := newConf.Hosts[hostGlob]; !ok {
|
||||
fatalIf(errDummy().Trace(), fmt.Sprintf("Host glob ‘%s’ does not exist.", hostGlob))
|
||||
}
|
||||
@@ -207,15 +207,15 @@ func isValidAccessKey(accessKeyID string) bool {
|
||||
}
|
||||
|
||||
// addHost - add new host
|
||||
func addHost(hostGlob, accessKeyID, secretAccessKey, signature string) {
|
||||
func addHost(hostGlob, accessKeyID, secretAccessKey, api string) {
|
||||
if strings.TrimSpace(hostGlob) == "" {
|
||||
fatalIf(errDummy().Trace(), "Unable to proceed, empty arguments provided.")
|
||||
}
|
||||
if strings.TrimSpace(signature) == "" {
|
||||
signature = "v4"
|
||||
if strings.TrimSpace(api) == "" {
|
||||
api = "S3v4"
|
||||
}
|
||||
if strings.ToLower(signature) != "v2" && strings.ToLower(signature) != "v4" {
|
||||
fatalIf(errInvalidArgument().Trace(), "Unrecognized version name provided, supported inputs are ‘v4’, ‘v2’")
|
||||
if strings.TrimSpace(api) != "S3v2" && strings.TrimSpace(api) != "S3v4" {
|
||||
fatalIf(errInvalidArgument().Trace(), "Unrecognized version name provided, supported inputs are ‘S3v4’, ‘S3v2’")
|
||||
}
|
||||
config, err := newConfig()
|
||||
fatalIf(err.Trace(globalMCConfigVersion), "Failed to initialize ‘quick’ configuration data structure.")
|
||||
@@ -235,11 +235,11 @@ func addHost(hostGlob, accessKeyID, secretAccessKey, signature string) {
|
||||
}
|
||||
}
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV4)
|
||||
newConf := config.Data().(*configV5)
|
||||
newConf.Hosts[hostGlob] = hostConfig{
|
||||
AccessKeyID: accessKeyID,
|
||||
SecretAccessKey: secretAccessKey,
|
||||
Signature: signature,
|
||||
API: "S3v4",
|
||||
}
|
||||
newConfig, err := quick.New(newConf)
|
||||
fatalIf(err.Trace(globalMCConfigVersion), "Failed to initialize ‘quick’ configuration data structure.")
|
||||
@@ -252,6 +252,6 @@ func addHost(hostGlob, accessKeyID, secretAccessKey, signature string) {
|
||||
Host: hostGlob,
|
||||
AccessKeyID: accessKeyID,
|
||||
SecretAccessKey: secretAccessKey,
|
||||
Signature: signature,
|
||||
API: api,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func mainConfigVersion(ctx *cli.Context) {
|
||||
fatalIf(err.Trace(configPath), "Unable to load config path")
|
||||
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV4)
|
||||
newConf := config.Data().(*configV5)
|
||||
type Version struct {
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
@@ -28,12 +28,22 @@ import (
|
||||
"github.com/minio/minio/pkg/quick"
|
||||
)
|
||||
|
||||
type configV4 struct {
|
||||
type configV5 struct {
|
||||
Version string `json:"version"`
|
||||
Aliases map[string]string `json:"alias"`
|
||||
Hosts map[string]hostConfig `json:"hosts"`
|
||||
}
|
||||
|
||||
type configV4 struct {
|
||||
Version string `json:"version"`
|
||||
Aliases map[string]string `json:"alias"`
|
||||
Hosts map[string]struct {
|
||||
AccessKeyID string `json:"accessKeyId"`
|
||||
SecretAccessKey string `json:"secretAccessKey"`
|
||||
Signature string `json:"signature"`
|
||||
} `json:"hosts"`
|
||||
}
|
||||
|
||||
type configV3 struct {
|
||||
Version string `json:"version"`
|
||||
Aliases map[string]string `json:"alias"`
|
||||
@@ -127,7 +137,7 @@ func mustGetMcConfigPath() string {
|
||||
}
|
||||
|
||||
// getMcConfig - reads configuration file and returns config
|
||||
func getMcConfig() (*configV4, *probe.Error) {
|
||||
func getMcConfig() (*configV5, *probe.Error) {
|
||||
if !isMcConfigExists() {
|
||||
return nil, errInvalidArgument().Trace()
|
||||
}
|
||||
@@ -139,10 +149,10 @@ func getMcConfig() (*configV4, *probe.Error) {
|
||||
|
||||
// Cached in private global variable.
|
||||
if v := cache.Get(); v != nil { // Use previously cached config.
|
||||
return v.(quick.Config).Data().(*configV4), nil
|
||||
return v.(quick.Config).Data().(*configV5), nil
|
||||
}
|
||||
|
||||
conf := newConfigV4()
|
||||
conf := newConfigV5()
|
||||
qconf, err := quick.New(conf)
|
||||
if err != nil {
|
||||
return nil, err.Trace()
|
||||
@@ -153,11 +163,11 @@ func getMcConfig() (*configV4, *probe.Error) {
|
||||
return nil, err.Trace()
|
||||
}
|
||||
cache.Put(qconf)
|
||||
return qconf.Data().(*configV4), nil
|
||||
return qconf.Data().(*configV5), nil
|
||||
}
|
||||
|
||||
// mustGetMcConfig - reads configuration file and returns configs, exits on error
|
||||
func mustGetMcConfig() *configV4 {
|
||||
func mustGetMcConfig() *configV5 {
|
||||
config, err := getMcConfig()
|
||||
fatalIf(err.Trace(), "Unable to read mc configuration.")
|
||||
return config
|
||||
@@ -203,6 +213,8 @@ func migrateConfig() {
|
||||
migrateConfigV2ToV3()
|
||||
// Migrate config V3 to V4
|
||||
migrateConfigV3ToV4()
|
||||
// Migrate config V4 to V5
|
||||
migrateConfigV4ToV5()
|
||||
}
|
||||
|
||||
func fixConfig() {
|
||||
@@ -325,15 +337,23 @@ func migrateConfigV3ToV4() {
|
||||
if mcConfigV3.Version() == "3" {
|
||||
confV4 := new(configV4)
|
||||
confV4.Aliases = mcConfigV3.Data().(*configV3).Aliases
|
||||
confV4.Hosts = make(map[string]hostConfig)
|
||||
confV4.Hosts = make(map[string]struct {
|
||||
AccessKeyID string `json:"accessKeyId"`
|
||||
SecretAccessKey string `json:"secretAccessKey"`
|
||||
Signature string `json:"signature"`
|
||||
})
|
||||
for host, hostConf := range mcConfigV3.Data().(*configV3).Hosts {
|
||||
confV4.Hosts[host] = hostConfig{
|
||||
confV4.Hosts[host] = struct {
|
||||
AccessKeyID string `json:"accessKeyId"`
|
||||
SecretAccessKey string `json:"secretAccessKey"`
|
||||
Signature string `json:"signature"`
|
||||
}{
|
||||
AccessKeyID: hostConf.AccessKeyID,
|
||||
SecretAccessKey: hostConf.SecretAccessKey,
|
||||
Signature: "v4",
|
||||
}
|
||||
}
|
||||
confV4.Version = globalMCConfigVersion
|
||||
confV4.Version = "4"
|
||||
|
||||
mcNewConfigV4, err := quick.New(confV4)
|
||||
fatalIf(err.Trace(), "Unable to initialize quick config for config version ‘4’.")
|
||||
@@ -345,6 +365,37 @@ func migrateConfigV3ToV4() {
|
||||
}
|
||||
}
|
||||
|
||||
func migrateConfigV4ToV5() {
|
||||
if !isMcConfigExists() {
|
||||
return
|
||||
}
|
||||
mcConfigV4, err := quick.Load(mustGetMcConfigPath(), newConfigV4())
|
||||
fatalIf(err.Trace(), "Unable to load mc config V2.")
|
||||
|
||||
// update to newer version
|
||||
if mcConfigV4.Version() == "4" {
|
||||
confV5 := new(configV5)
|
||||
confV5.Aliases = mcConfigV4.Data().(*configV4).Aliases
|
||||
confV5.Hosts = make(map[string]hostConfig)
|
||||
for host, hostConf := range mcConfigV4.Data().(*configV4).Hosts {
|
||||
confV5.Hosts[host] = hostConfig{
|
||||
AccessKeyID: hostConf.AccessKeyID,
|
||||
SecretAccessKey: hostConf.SecretAccessKey,
|
||||
API: "S3v4",
|
||||
}
|
||||
}
|
||||
confV5.Version = globalMCConfigVersion
|
||||
|
||||
mcNewConfigV5, err := quick.New(confV5)
|
||||
fatalIf(err.Trace(), "Unable to initialize quick config for config version ‘5’.")
|
||||
|
||||
err = mcNewConfigV5.Save(mustGetMcConfigPath())
|
||||
fatalIf(err.Trace(), "Unable to save config version ‘5’.")
|
||||
|
||||
console.Infof("Successfully migrated %s from version ‘4’ to version ‘5’.\n", mustGetMcConfigPath())
|
||||
}
|
||||
}
|
||||
|
||||
func fixConfigV3() {
|
||||
if !isMcConfigExists() {
|
||||
return
|
||||
@@ -457,6 +508,20 @@ func newConfigV3() *configV3 {
|
||||
|
||||
func newConfigV4() *configV4 {
|
||||
conf := new(configV4)
|
||||
conf.Version = "4"
|
||||
// make sure to allocate map's otherwise Golang
|
||||
// exits silently without providing any errors
|
||||
conf.Hosts = make(map[string]struct {
|
||||
AccessKeyID string `json:"accessKeyId"`
|
||||
SecretAccessKey string `json:"secretAccessKey"`
|
||||
Signature string `json:"signature"`
|
||||
})
|
||||
conf.Aliases = make(map[string]string)
|
||||
return conf
|
||||
}
|
||||
|
||||
func newConfigV5() *configV5 {
|
||||
conf := new(configV5)
|
||||
conf.Version = globalMCConfigVersion
|
||||
// make sure to allocate map's otherwise Golang
|
||||
// exits silently without providing any errors
|
||||
@@ -466,32 +531,32 @@ func newConfigV4() *configV4 {
|
||||
localHostConfig := hostConfig{
|
||||
AccessKeyID: "",
|
||||
SecretAccessKey: "",
|
||||
Signature: "v4",
|
||||
API: "S3v4",
|
||||
}
|
||||
|
||||
s3HostConf := hostConfig{
|
||||
AccessKeyID: globalAccessKeyID,
|
||||
SecretAccessKey: globalSecretAccessKey,
|
||||
Signature: "v4",
|
||||
API: "S3v4",
|
||||
}
|
||||
|
||||
// Your example host config
|
||||
exampleHostConf := hostConfig{
|
||||
AccessKeyID: globalAccessKeyID,
|
||||
SecretAccessKey: globalSecretAccessKey,
|
||||
Signature: "v4",
|
||||
API: "S3v4",
|
||||
}
|
||||
|
||||
playHostConfig := hostConfig{
|
||||
AccessKeyID: "",
|
||||
SecretAccessKey: "",
|
||||
Signature: "v4",
|
||||
API: "S3v4",
|
||||
}
|
||||
|
||||
dlHostConfig := hostConfig{
|
||||
AccessKeyID: "",
|
||||
SecretAccessKey: "",
|
||||
Signature: "v4",
|
||||
API: "S3v4",
|
||||
}
|
||||
|
||||
conf.Hosts[globalExampleHostURL] = exampleHostConf
|
||||
@@ -513,7 +578,7 @@ func newConfigV4() *configV4 {
|
||||
|
||||
// newConfig - get new config interface
|
||||
func newConfig() (config quick.Config, err *probe.Error) {
|
||||
config, err = quick.New(newConfigV4())
|
||||
config, err = quick.New(newConfigV5())
|
||||
if err != nil {
|
||||
return nil, err.Trace()
|
||||
}
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ func (s *TestSuite) TestConfigHostContext(c *C) {
|
||||
"*my-example.com",
|
||||
"AKIKJAA5BMMU2RHO6IBB",
|
||||
"V7f1CCwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr9",
|
||||
"v2",
|
||||
"S3v2",
|
||||
})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, false)
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ var (
|
||||
|
||||
// mc configuration related constants.
|
||||
const (
|
||||
globalMCConfigVersion = "4"
|
||||
globalMCConfigVersion = "5"
|
||||
globalMCVersion = Version
|
||||
|
||||
globalMCConfigDir = ".mc/"
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ import (
|
||||
type hostConfig struct {
|
||||
AccessKeyID string `json:"accessKeyId"`
|
||||
SecretAccessKey string `json:"secretAccessKey"`
|
||||
Signature string `json:"signature"`
|
||||
API string `json:"api"`
|
||||
}
|
||||
|
||||
// getHostConfig retrieves host specific configuration such as access keys, certs.
|
||||
@@ -41,7 +41,7 @@ func getHostConfig(URL string) (hostConfig, *probe.Error) {
|
||||
hostCfg := hostConfig{
|
||||
AccessKeyID: "",
|
||||
SecretAccessKey: "",
|
||||
Signature: "",
|
||||
API: "fs",
|
||||
}
|
||||
return hostCfg, nil
|
||||
}
|
||||
|
||||
+3
-3
@@ -108,12 +108,12 @@ func (s *TestSuite) TestNewConfigV4(c *C) {
|
||||
perr = conf.Save(configFile)
|
||||
c.Assert(perr, IsNil)
|
||||
|
||||
confNew := newConfigV4()
|
||||
confNew := newConfigV5()
|
||||
config, perr := quick.New(confNew)
|
||||
c.Assert(perr, IsNil)
|
||||
perr = config.Load(configFile)
|
||||
c.Assert(perr, IsNil)
|
||||
data := config.Data().(*configV4)
|
||||
data := config.Data().(*configV5)
|
||||
|
||||
type aliases struct {
|
||||
name string
|
||||
@@ -167,7 +167,7 @@ func (s *TestSuite) TestHostConfig(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(hostcfg.AccessKeyID, Equals, globalAccessKeyID)
|
||||
c.Assert(hostcfg.SecretAccessKey, Equals, globalSecretAccessKey)
|
||||
c.Assert(hostcfg.Signature, Equals, "v4")
|
||||
c.Assert(hostcfg.API, Equals, "S3v4")
|
||||
|
||||
_, err = getHostConfig("http://test.minio.io")
|
||||
c.Assert(err, Not(IsNil))
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package s3
|
||||
package s3v4
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package s3
|
||||
package s3v4
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package s3
|
||||
package s3v4
|
||||
|
||||
// bucketHandler is an http.Handler that verifies bucket responses and validates incoming requests
|
||||
import (
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package s3
|
||||
package s3v4
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
Reference in New Issue
Block a user