Files
virtual-kubelet/providers/azure/acsCredential.go
Brian Goff 1bfffa975e Make tracing interface to coalesce logging/tracing (#519)
* Define and use an interface for logging.

This allows alternative implementations to use whatever logging package
they want.

Currently the interface just mimicks what logrus already implements,
with minor modifications to not rely on logrus itself. I think the
interface is pretty solid in terms of logging implementations being able
to do what they need to.

* Make tracing interface to coalesce logging/tracing

Allows us to share data between the tracer and the logger so we can
simplify log/trace handling wher we generally want data to go both
places.
2019-02-22 11:36:03 -08:00

44 lines
1.2 KiB
Go

package azure
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"github.com/virtual-kubelet/virtual-kubelet/log"
)
// AcsCredential represents the credential file for ACS
type AcsCredential struct {
Cloud string `json:"cloud"`
TenantID string `json:"tenantId"`
SubscriptionID string `json:"subscriptionId"`
ClientID string `json:"aadClientId"`
ClientSecret string `json:"aadClientSecret"`
ResourceGroup string `json:"resourceGroup"`
Region string `json:"location"`
VNetName string `json:"vnetName"`
VNetResourceGroup string `json:"vnetResourceGroup"`
}
// NewAcsCredential returns an AcsCredential struct from file path
func NewAcsCredential(p string) (*AcsCredential, error) {
logger := log.G(context.TODO()).WithField("method", "NewAcsCredential").WithField("file", p)
logger.Debug("Reading ACS credential file")
b, err := ioutil.ReadFile(p)
if err != nil {
return nil, fmt.Errorf("Reading ACS credential file %q failed: %v", p, err)
}
// Unmarshal the authentication file.
var cred AcsCredential
if err := json.Unmarshal(b, &cred); err != nil {
return nil, err
}
logger.Debug("Load ACS credential file successfully")
return &cred, nil
}