Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't initialize youtube resolver if youtube-api-key is empty #556

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Dev: Add some `pkg/utils/url.go` tests. (#525)
- Dev: Make `IsSubdomainOf` variadic, making it easier for users of it to support multiple top level domains. (#526)
- Dev: Use logger for skipping url message instead of fmt. (#554)
- Dev: Improve YoutTube resolver initialization logging. (#556)

## 2.0.2

Expand Down
8 changes: 7 additions & 1 deletion internal/resolvers/youtube/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,15 @@ func NewYouTubeVideoResolvers(ctx context.Context, cfg config.APIConfig, pool db
func Initialize(ctx context.Context, cfg config.APIConfig, pool db.Pool, resolvers *[]resolver.Resolver) {
log := logger.FromContext(ctx)

if cfg.YoutubeApiKey == "" {
log.Warnw("[Config] youtube-api-key missing, won't do special responses for YouTube")
return

}

youtubeClient, err := youtubeAPI.NewService(ctx, option.WithAPIKey(cfg.YoutubeApiKey))
if err != nil {
log.Warnw("[Config] youtube-api-key missing or otherwise misconfigured, won't do special responses for YouTube",
log.Warnw("[Config] Failed to create youtube client, won't do special responses for YouTube",
"error", err,
)
return
Expand Down
6 changes: 6 additions & 0 deletions internal/resolvers/youtube/initialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package youtube

import (
"context"
"os"
"testing"

"github.com/Chatterino/api/internal/logger"
Expand All @@ -18,6 +19,11 @@ func TestInitialize(t *testing.T) {
pool, err := pgxmock.NewPool()
c.Assert(err, qt.IsNil)

// google.golang.org/api/youtube/v3 automatically
// uses this environment variable to initialize clients
err = os.Unsetenv("GOOGLE_APPLICATION_CREDENTIALS")
pajlada marked this conversation as resolved.
Show resolved Hide resolved
c.Assert(err, qt.IsNil)

c.Run("No YouTube API key", func(c *qt.C) {
cfg := config.APIConfig{
YoutubeApiKey: "",
Expand Down
Loading