Skip to content

Commit

Permalink
Feedback (#59)
Browse files Browse the repository at this point in the history
feat: Add slack client, feedback resolver and a lot of boilerplate
  • Loading branch information
rbjornstad authored Aug 15, 2024
1 parent facdb6a commit 966c425
Show file tree
Hide file tree
Showing 20 changed files with 668 additions and 11 deletions.
16 changes: 14 additions & 2 deletions charts/Feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@ values:
template: |
{{ .Env.nais_api_db_password | quote }}
slack.token:
displayName: Slack token
description: Token for the Slack API
config:
type: string
secret: true

slack.feedbackChannel:
displayName: Slack feedback channel
description: The Slack channel to post feedback to
config:
type: string

usersync.serviceAccount:
displayName: Service account for user sync
description: The service account used to sync users from GSuite
Expand All @@ -165,12 +178,11 @@ values:
description: Enable Unleash feature flag
config:
type: bool
default: false

unleash.namespace:
displayName: Unleash namespace
description: Namespace for Unleash
config:
type: string
computed:
template: '"{{ .Management.bifrost_unleash_namespace}}"'
template: '"{{ .Management.bifrost_unleash_namespace}}"'
4 changes: 3 additions & 1 deletion charts/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ stringData:
DEPENDENCYTRACK_PASSWORD: "{{ .Values.dependencytrack.password }}"
OAUTH_CLIENT_SECRET: "{{ .Values.oauth.clientSecret }}"
STATIC_SERVICE_ACCOUNTS: {{ .Values.staticServiceAccounts | quote }}
DATABASE_URL: "postgres://{{ .Values.database.user }}:{{ .Values.database.password }}@127.0.0.1:5432/{{ .Values.database.name }}?sslmode=disable"
DATABASE_URL: "postgres://{{ .Values.database.user }}:{{ .Values.database.password }}@127.0.0.1:5432/{{ .Values.database.name }}?sslmode=disable"
SLACK_FEEDBACK_CHANNEL: {{ .Values.slack.feedbackChannel | quote }}
SLACK_API_TOKEN: {{ .Values.slack.token }}
4 changes: 4 additions & 0 deletions charts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ oauth: # mapped in fasit
clientID: ""
clientSecret: ""

slack:
feedbackChannel: "console-user-feedback"
token: "" # Config in fasit

staticServiceAccounts: "" # mapped in fasit

usersync:
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
github.com/rs/cors v1.11.0
github.com/sethvargo/go-envconfig v1.0.3
github.com/sirupsen/logrus v1.9.3
github.com/slack-go/slack v0.13.1
github.com/sourcegraph/conc v0.3.0
github.com/sqlc-dev/sqlc v1.26.0
github.com/stretchr/testify v1.9.0
Expand Down Expand Up @@ -63,6 +64,7 @@ require (
k8s.io/klog/v2 v2.130.1
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0
sigs.k8s.io/yaml v1.4.0

)

require (
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqw
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/go-test/deep v1.0.4 h1:u2CU3YKy9I2pmu9pX0eq50wCgjfGIt539SqR7FbHiho=
github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
Expand Down Expand Up @@ -214,6 +216,7 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
Expand All @@ -235,6 +238,7 @@ github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfF
github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0=
github.com/googleapis/gax-go/v2 v2.12.5 h1:8gw9KZK8TiVKB6q3zHY3SBzLnrGp6HQjyfYBYGmXdxA=
github.com/googleapis/gax-go/v2 v2.12.5/go.mod h1:BUDKcWo+RaKq5SC9vVYL0wLADa3VcfswbOMMRmB9H3E=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
Expand Down Expand Up @@ -455,6 +459,8 @@ github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU=
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/slack-go/slack v0.13.1 h1:6UkM3U1OnbhPsYeb1IMkQ6HSNOSikWluwOncJt4Tz/o=
github.com/slack-go/slack v0.13.1/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw=
github.com/sosodev/duration v1.3.1 h1:qtHBDMQ6lvMQsL15g4aopM4HEfOaYuhWBw3NPTtlqq4=
github.com/sosodev/duration v1.3.1/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
Expand All @@ -478,6 +484,7 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/nais/api/internal/bigquery"
"github.com/nais/api/internal/kafka"
"github.com/nais/api/internal/opensearch"
"github.com/nais/api/internal/slack"

"github.com/nais/api/internal/unleash"

Expand Down Expand Up @@ -196,6 +197,7 @@ func run(ctx context.Context, cfg *Config, log logrus.FieldLogger) error {
dependencyTrackClient,
resourceUsageClient,
db,
cfg.Tenant,
cfg.TenantDomain,
usersyncTrigger,
auditLogger,
Expand All @@ -210,6 +212,7 @@ func run(ctx context.Context, cfg *Config, log logrus.FieldLogger) error {
kafka.NewClient(k8sClient.Informers(), log, db),
unleashMgr,
audit.NewAuditor(db),
slack.New(cfg.Slack.Token, cfg.Slack.FeedbackChannel),
)

graphHandler, err := graph.NewHandler(gengql.Config{
Expand Down
6 changes: 6 additions & 0 deletions internal/cmd/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ type oAuthConfig struct {
RedirectURL string `env:"OAUTH_REDIRECT_URL"`
}

type slackConfig struct {
Token string `env:"SLACK_TOKEN"`
FeedbackChannel string `env:"SLACK_FEEDBACK_CHANNEL"`
}

type unleashConfig struct {
// Enabled When set to true, the Unleash feature flag service will be enabled.
Enabled bool `env:"UNLEASH_ENABLED"`
Expand Down Expand Up @@ -200,6 +205,7 @@ type Config struct {
Hookd hookdConfig
OAuth oAuthConfig
Unleash unleashConfig
Slack slackConfig
}

// NewConfig creates a new configuration instance from environment variables
Expand Down
3 changes: 3 additions & 0 deletions internal/graph/deployinfo.resolvers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/nais/api/internal/graph"
"github.com/nais/api/internal/graph/model"
"github.com/nais/api/internal/graph/scalar"
"github.com/nais/api/internal/slack/fake"
"github.com/nais/api/internal/thirdparty/hookd"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand Down Expand Up @@ -94,6 +95,7 @@ func Test_deployInfoResolver_History(t *testing.T) {
nil,
nil,
nil,
"example",
"example.com",
nil,
nil,
Expand All @@ -108,6 +110,7 @@ func Test_deployInfoResolver_History(t *testing.T) {
nil,
nil,
nil,
fake.NewFakeSlackClient(),
).
DeployInfo().
History(ctx, deployInfo, nil, nil)
Expand Down
36 changes: 36 additions & 0 deletions internal/graph/feedback.resolvers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package graph

import (
"context"

"github.com/nais/api/internal/graph/model"
"k8s.io/utils/ptr"
)

func (r *mutationResolver) CreateFeedback(ctx context.Context, input model.CreateFeedbackInput) (*model.CreateFeedbackResult, error) {
if len(input.Details) == 0 {
return &model.CreateFeedbackResult{
Created: false,
Error: ptr.To("Feedback details are required"),
}, nil
}
if len(input.Details) > 3000 {
return &model.CreateFeedbackResult{
Created: false,
Error: ptr.To("Feedback details must be no more than 3000 characters"),
}, nil
}

messageOptions := r.slackClient.GetFeedbackMessageOptions(ctx, r.tenant, input)
if _, _, err := r.slackClient.PostFeedbackMessage(messageOptions); err != nil {
return &model.CreateFeedbackResult{
Created: false,
Error: ptr.To(err.Error()),
}, err
}

return &model.CreateFeedbackResult{
Created: true,
Error: nil,
}, nil
}
Loading

0 comments on commit 966c425

Please sign in to comment.