Plumb through log analytics values (#274)
* plumb through log analytics values * add option to specify a log analytics file as well * use secret for log analytics
This commit is contained in:
committed by
Robbie Zhang
parent
28daffa96f
commit
ef6ae9ecf4
39
providers/azure/client/aci/analytics.go
Normal file
39
providers/azure/client/aci/analytics.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package aci
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func NewContainerGroupDiagnostics(logAnalyticsID, logAnalyticsKey string) (*ContainerGroupDiagnostics, error) {
|
||||
|
||||
if logAnalyticsID == "" || logAnalyticsKey == "" {
|
||||
return nil, errors.New("Log Analytics configuration requires both the workspace ID and Key")
|
||||
}
|
||||
|
||||
return &ContainerGroupDiagnostics{
|
||||
LogAnalytics: &LogAnalyticsWorkspace{
|
||||
WorkspaceID: logAnalyticsID,
|
||||
WorkspaceKey: logAnalyticsKey,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewContainerGroupDiagnosticsFromFile(filepath string) (*ContainerGroupDiagnostics, error) {
|
||||
|
||||
analyticsdata, err := ioutil.ReadFile(filepath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Reading Log Analytics Auth file %q failed: %v", filepath, err)
|
||||
}
|
||||
// Unmarshal the log analytics file.
|
||||
var law LogAnalyticsWorkspace
|
||||
if err := json.Unmarshal(analyticsdata, &law); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ContainerGroupDiagnostics{
|
||||
LogAnalytics: &law,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user