-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
- Loading branch information
Frank Jogeleit
committed
May 10, 2024
1 parent
169a068
commit 4dd1d7d
Showing
11 changed files
with
285 additions
and
225 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package formatting | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func ResourceString(res *corev1.ObjectReference) string { | ||
var resource string | ||
if res.Namespace == "" { | ||
resource = fmt.Sprintf("%s/%s: %s", res.APIVersion, res.Kind, res.Name) | ||
} else { | ||
resource = fmt.Sprintf("%s/%s: %s/%s", res.APIVersion, res.Kind, res.Namespace, res.Name) | ||
} | ||
|
||
return strings.Trim(resource, "/") | ||
} |
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,54 @@ | ||
package teams | ||
|
||
import ( | ||
"github.com/atc0005/go-teams-notify/v2/adaptivecard" | ||
"github.com/kyverno/policy-reporter/pkg/helper" | ||
) | ||
|
||
func newFactSet() adaptivecard.Element { | ||
factSet := adaptivecard.Element{ | ||
Type: adaptivecard.TypeElementFactSet, | ||
} | ||
|
||
return factSet | ||
} | ||
|
||
func newFactSetPointer() *adaptivecard.Element { | ||
factSet := newFactSet() | ||
|
||
return &factSet | ||
} | ||
|
||
func newSubTitle(title string) adaptivecard.Element { | ||
text := adaptivecard.NewTextBlock(title, true) | ||
text.Weight = adaptivecard.WeightBolder | ||
text.IsSubtle = true | ||
|
||
return text | ||
} | ||
|
||
func MapToColumnSet(list map[string]string) adaptivecard.Element { | ||
i := 0 | ||
|
||
first := adaptivecard.NewColumn() | ||
first.Items = append(first.Items, newFactSetPointer()) | ||
|
||
second := adaptivecard.NewColumn() | ||
second.Items = append(second.Items, newFactSetPointer()) | ||
|
||
propBlock := adaptivecard.NewColumnSet() | ||
propBlock.Columns = []adaptivecard.Column{first, second} | ||
|
||
for property, value := range list { | ||
index := i % 2 | ||
|
||
propBlock.Columns[index].Items[0].Facts = append(propBlock.Columns[index].Items[0].Facts, adaptivecard.Fact{ | ||
Title: helper.Title(property), | ||
Value: value, | ||
}) | ||
|
||
i++ | ||
} | ||
|
||
return propBlock | ||
} |
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,29 @@ | ||
package teams | ||
|
||
import ( | ||
"net/http" | ||
|
||
teams "github.com/atc0005/go-teams-notify/v2" | ||
"github.com/atc0005/go-teams-notify/v2/adaptivecard" | ||
) | ||
|
||
type APIClient interface { | ||
PostMessage(*adaptivecard.Message) error | ||
} | ||
|
||
type apiClient struct { | ||
webhook string | ||
client *teams.TeamsClient | ||
} | ||
|
||
func (c *apiClient) PostMessage(message *adaptivecard.Message) error { | ||
return c.client.Send(c.webhook, message) | ||
} | ||
|
||
func NewAPIClient(webhook string, client *http.Client) APIClient { | ||
msTeams := teams.NewTeamsClient() | ||
msTeams.SetHTTPClient(client) | ||
msTeams.SetUserAgent("Policy-Reporter") | ||
|
||
return &apiClient{webhook: webhook, client: msTeams} | ||
} |
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,16 @@ | ||
package teams_test | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/kyverno/policy-reporter/pkg/target/teams" | ||
) | ||
|
||
func TestNewAPI(t *testing.T) { | ||
h := &http.Client{} | ||
|
||
assert.NotNil(t, teams.NewAPIClient("http://webhook:8080", h)) | ||
} |
Oops, something went wrong.