Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 1 addition & 3 deletions auth/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,9 @@ func PurgeCredentials() error {
}

func IsColumnarPrivateRegistry(u *url.URL) bool {
return u.Host == DefaultOauthURI
return u.Host == defaultOauthURI
}

const licenseURI = "https://heimdall.columnar.tech/trial_license"

var (
ErrNoTrialLicense = errors.New("no trial license found")
ErrTrialExpired = errors.New("trial license has expired")
Expand Down
20 changes: 17 additions & 3 deletions auth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,28 @@ import (
"fmt"
"net/http"
"net/url"
"os"
"strconv"
"strings"
)

const (
DefaultOauthURI = "dbc-cdn-private.columnar.tech"
DefaultOauthClientID = "eSKuasirO0gUnGuNURPagErV3TSSFhEK"
var (
defaultOauthURI = "dbc-cdn-private.columnar.tech"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can we make these defaultOauthURI values the actual URI and then we don't have to concatenate a string later on like this?

mustParseURL("https://" + auth.DefaultOauthURI())},

Maybe there's a reason you had it separated out?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the IsColumnarPrivateRegistry function compares against url.URL.Host which doesn't contain the scheme. We also compare the host elsewhere which doesn't include the scheme, so it made more sense for the DefaultOauthURI to only be the host and not include the scheme so that I wouldn't have to reconstruct (or deconstruct) to perform the comparisons elsewhere with parsed URL objects.

Did we want setting DBC_USE_STAGING to also have dbc use the staging index for search/info/install? It doesn't appear to be from this PR. Happy to mark that as a follow-ons. At least auth works here.

It does force dbc to use the dbc-cdn-private-staging url for search/info/install of the private drivers. This doesn't implement adding the /staging/ prefix to the urls for the public registry, you're correct there. I think that's up for discussion I guess. Since we aren't dealing with auth stuff through there (i.e. we don't need to point at other URLs) we can use the built-in cloudfront cdn staging configs if we ever need to change the actual deployment configs I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, makes sense. No need for a change here. I think later down the line we could think about how this env var interacts with our REGISTRY_URL override (or whatever it's called).

defaultOauthClientID = "eSKuasirO0gUnGuNURPagErV3TSSFhEK"
licenseURI = "https://heimdall.columnar.tech/trial_license"
)

func init() {
if isStaging, _ := strconv.ParseBool(os.Getenv("DBC_USE_STAGING")); isStaging {
defaultOauthURI = "dbc-cdn-private-staging.columnar.tech"
defaultOauthClientID = "XZaxtg7XjYSTLNzgrLbYNrPOZzRiRpvW"
licenseURI = "https://dbc-cf-api-staging.columnar.workers.dev/trial_license"
}
}

func DefaultOauthURI() string { return defaultOauthURI }
func DefaultOauthClientID() string { return defaultOauthClientID }

type OpenIDConfig struct {
Issuer Uri `json:"issuer"`
AuthorizationEndpoint Uri `json:"authorization_endpoint"`
Expand Down
8 changes: 4 additions & 4 deletions cmd/dbc/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ func (l LoginCmd) GetModelCustom(baseModel baseModel) tea.Model {
}

if l.RegistryURL == "" {
l.RegistryURL = auth.DefaultOauthURI
l.RegistryURL = auth.DefaultOauthURI()
}

if l.RegistryURL == auth.DefaultOauthURI {
if l.RegistryURL == auth.DefaultOauthURI() {
if l.ClientID == "" {
l.ClientID = auth.DefaultOauthClientID
l.ClientID = auth.DefaultOauthClientID()
}
}

Expand Down Expand Up @@ -237,7 +237,7 @@ type LogoutCmd struct {

func (l LogoutCmd) GetModelCustom(baseModel baseModel) tea.Model {
if l.RegistryURL == "" {
l.RegistryURL = auth.DefaultOauthURI
l.RegistryURL = auth.DefaultOauthURI()
}

return logoutModel{
Expand Down
8 changes: 4 additions & 4 deletions cmd/dbc/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func (suite *SubcommandTestSuite) TestLoginCmdDefaults() {

loginM, ok := m.(loginModel)
suite.Require().True(ok, "expected loginModel")
suite.Equal(auth.DefaultOauthURI, loginM.inputURI)
suite.Equal(auth.DefaultOauthClientID, loginM.oauthClientID)
suite.Equal(auth.DefaultOauthURI(), loginM.inputURI)
suite.Equal(auth.DefaultOauthClientID(), loginM.oauthClientID)
suite.Equal("", loginM.apiKey)
}

Expand Down Expand Up @@ -66,7 +66,7 @@ func (suite *SubcommandTestSuite) TestLoginCmdWithClientID() {

loginM, ok := m.(loginModel)
suite.Require().True(ok, "expected loginModel")
suite.Equal(auth.DefaultOauthURI, loginM.inputURI)
suite.Equal(auth.DefaultOauthURI(), loginM.inputURI)
suite.Equal("custom-client-id", loginM.oauthClientID)
}

Expand Down Expand Up @@ -180,7 +180,7 @@ func (suite *SubcommandTestSuite) TestLogoutCmdDefaults() {

logoutM, ok := m.(logoutModel)
suite.Require().True(ok, "expected logoutModel")
suite.Equal(auth.DefaultOauthURI, logoutM.inputURI)
suite.Equal(auth.DefaultOauthURI(), logoutM.inputURI)
}

func (suite *SubcommandTestSuite) TestLogoutCmdWithRegistryURL() {
Expand Down
2 changes: 1 addition & 1 deletion drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func mustParseURL(u string) *url.URL {
var (
registries = []Registry{
{BaseURL: mustParseURL("https://dbc-cdn.columnar.tech")},
{BaseURL: mustParseURL("https://dbc-cdn-private.columnar.tech")},
{BaseURL: mustParseURL("https://" + auth.DefaultOauthURI())},
}
Version = "unknown"
mid string
Expand Down
Loading