1
0
mirror of https://github.com/minio/mc.git synced 2025-11-13 12:22:45 +03:00
Files
mc/hostconfig.go
Anand Babu (AB) Periasamy fddcb821fa URL related bug fixes and cleanup
2015-08-30 02:14:24 -07:00

57 lines
1.5 KiB
Go

/*
* Minio Client (C) 2015 Minio, 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 main
import (
"path/filepath"
"github.com/minio/mc/pkg/client"
"github.com/minio/minio/pkg/probe"
)
type hostConfig struct {
AccessKeyID string `json:"access-key-id"`
SecretAccessKey string `json:"secret-access-key"`
}
// getHostConfig retrieves host specific configuration such as access keys, certs.
func getHostConfig(URL string) (hostConfig, *probe.Error) {
config, err := getMcConfig()
if err != nil {
return hostConfig{}, err.Trace()
}
url := client.NewURL(URL)
// No host matching or keys needed for filesystem requests
if url.Type == client.Filesystem {
hostCfg := hostConfig{
AccessKeyID: "",
SecretAccessKey: "",
}
return hostCfg, nil
}
for globURL, hostCfg := range config.Hosts {
match, err := filepath.Match(globURL, url.Host)
if err != nil {
return hostConfig{}, errInvalidGlobURL(globURL, URL).Trace()
}
if match {
return hostCfg, nil
}
}
return hostConfig{}, errNoMatchingHost(URL).Trace()
}