From 8777e97b72eb30eb8609bafa86e6612f7b9635c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphae=CC=88l=20Enrici?= Date: Sun, 17 Dec 2017 18:26:09 +0100 Subject: [PATCH] fixes #2249: sanitize tenant and tenantid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If tenant or tenantid are passed as env variables, we systematically use Sprint to make sure they are string and not integer as it would make mapstructure fail. Signed-off-by: Raphaël Enrici --- registry/storage/driver/swift/swift.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/registry/storage/driver/swift/swift.go b/registry/storage/driver/swift/swift.go index 11a33264..60ebea4a 100644 --- a/registry/storage/driver/swift/swift.go +++ b/registry/storage/driver/swift/swift.go @@ -142,6 +142,19 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { InsecureSkipVerify: false, } + // Sanitize some entries before trying to decode parameters with mapstructure + // TenantID and Tenant when integers only and passed as ENV variables + // are considered as integer and not string. The parser fails in this + // case. + _, ok := parameters["tenant"] + if ok { + parameters["tenant"] = fmt.Sprint(parameters["tenant"]) + } + _, ok = parameters["tenantid"] + if ok { + parameters["tenantid"] = fmt.Sprint(parameters["tenantid"]) + } + if err := mapstructure.Decode(parameters, ¶ms); err != nil { return nil, err }