func OptionReadIAMConfig(path string) OptionRoundtripperFunc {
	return func(j *dcosRoundtripper) error {
		f, err := os.Open(path)
		if err != nil {
			return err
		}
		defer f.Close()
		fileContent, err := ioutil.ReadAll(f)
		if err != nil {
			return err
		}
		var cfg = struct {
			UID           string `json:"uid"`
			Secret        string `json:"private_key"`
			LoginEndpoint string `json:"login_endpoint"`
		}{}
		if err := json.Unmarshal(fileContent, &cfg); err != nil {
			return err
		}
		return OptionCredentials(cfg.UID, cfg.Secret, cfg.LoginEndpoint)(j)
	}
}
OptionReadIAMConfig is an option to read the IAMConfig from file system and populate uid, secret and loginEndpoint.
package transport
import (
	"crypto/rsa"
	"crypto/x509"
	"encoding/json"
	"encoding/pem"
	"errors"
	"io/ioutil"
	"os"
	"time"
)
var (
	ErrInvalidCredentials = errors.New("uid, secret and loginEndpoit cannot be empty")
	ErrInvalidExpireDuration = errors.New("token expire duration must be positive non zero value")
)
type OptionTransportFunc func(*dcosTransport) error
type OptionRoundtripperFunc func(*dcosRoundtripper) error
func errorOnEmpty(arg string) error {
	if len(arg) == 0 {
		return errors.New("Must pass non-empty string to this option")
	}
	return nil
}
func OptionCaCertificatePath(caCertificatePath string) OptionTransportFunc {
	return func(o *dcosTransport) error {
		err := errorOnEmpty(caCertificatePath)
		if err == nil {
			o.CaCertificatePath = caCertificatePath
		}
		return err
	}
}
func OptionIAMConfigPath(iamConfigPath string) OptionTransportFunc {
	return func(o *dcosTransport) error {
		err := errorOnEmpty(iamConfigPath)
		if err == nil {
			o.IAMConfigPath = iamConfigPath
		}
		return err
	}
}
func OptionTokenExpire(t time.Duration) OptionRoundtripperFunc {
	return func(j *dcosRoundtripper) error {
		if t < 1 {
			return ErrInvalidExpireDuration
		}
		j.expire = t
		return nil
	}
}
func OptionCredentials(uid, secret, loginEndpoint string) OptionRoundtripperFunc {
	return func(j *dcosRoundtripper) error {
		if uid == "" || secret == "" || loginEndpoint == "" {
			return ErrInvalidCredentials
		}
		j.uid = uid
		j.loginEndpoint = loginEndpoint
		block, _ := pem.Decode([]byte(secret))
		if block == nil {
			return ErrInvalidCredentials
		}
		key, err := x509.ParsePKCS8PrivateKey(block.Bytes)
		if err != nil {
			return ErrInvalidCredentials
		}
		if key, ok := key.(*rsa.PrivateKey); ok {
			j.secret = key
			return nil
		}
		return ErrInvalidCredentials
	}
}