From 1b60e8fdb658d4f4b1493eb19520816465a4b1d7 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 17 Oct 2017 18:03:16 -0700 Subject: [PATCH] svchost/auth: HostCredentialsFromMap function This function deals with turning a map derived from some user input (e.g. in a config file) into a HostCredentials object, if possible. This will be used as a standard way to specify credentials so we have a place to add new credentials types in future and have support for those across all of our map-based CredentialsSources. --- svchost/auth/from_map.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 svchost/auth/from_map.go diff --git a/svchost/auth/from_map.go b/svchost/auth/from_map.go new file mode 100644 index 000000000..f91006aec --- /dev/null +++ b/svchost/auth/from_map.go @@ -0,0 +1,18 @@ +package auth + +// HostCredentialsFromMap converts a map of key-value pairs from a credentials +// definition provided by the user (e.g. in a config file, or via a credentials +// helper) into a HostCredentials object if possible, or returns nil if +// no credentials could be extracted from the map. +// +// This function ignores map keys it is unfamiliar with, to allow for future +// expansion of the credentials map format for new credential types. +func HostCredentialsFromMap(m map[string]interface{}) HostCredentials { + if m == nil { + return nil + } + if token, ok := m["token"].(string); ok { + return HostCredentialsToken(token) + } + return nil +}