Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
28daffa
commit ef6ae9e
Showing
9 changed files
with
141 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package aci | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestLogAnalyticsFileParsingSuccess(t *testing.T) { | ||
diagnostics, err := NewContainerGroupDiagnosticsFromFile("../../../../loganalytics.json") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if diagnostics == nil || diagnostics.LogAnalytics == nil { | ||
t.Fatalf("Unexpected nil diagnostics. Log Analytics file not parsed correctly") | ||
} | ||
|
||
if diagnostics.LogAnalytics.WorkspaceID == "" || diagnostics.LogAnalytics.WorkspaceKey == "" { | ||
t.Fatalf("Unexpected empty analytics authentication credentials. Log Analytics file not parsed correctly") | ||
} | ||
} | ||
|
||
func TestLogAnalyticsFileParsingFailure(t *testing.T) { | ||
tempFile, err := ioutil.TempFile("", "") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
_, err = NewContainerGroupDiagnosticsFromFile(tempFile.Name()) | ||
|
||
// Cleaup | ||
tempFile.Close() | ||
os.Remove(tempFile.Name()) | ||
|
||
if err == nil { | ||
t.Fatalf("Expected parsing an empty Log Analytics auth file to fail, but there were no errors") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters