Skip to content

Commit

Permalink
Merge branch 'main' of github.com:sourcegraph/sourcegraph into operat…
Browse files Browse the repository at this point in the history
…iondocs-to-notion
  • Loading branch information
bobheadxi committed May 2, 2024
2 parents 9ee89ce + bbba66f commit 2ae19de
Show file tree
Hide file tree
Showing 33 changed files with 324 additions and 384 deletions.
2 changes: 2 additions & 0 deletions client/web-sveltekit/src/lib/repo/LastCommit.gql
Expand Up @@ -7,6 +7,8 @@ fragment LastCommitFragment on GitCommit {
date
person {
...Avatar_Person
displayName
name
}
}
}
2 changes: 1 addition & 1 deletion client/web-sveltekit/src/lib/repo/LastCommit.svelte
Expand Up @@ -18,7 +18,7 @@
<Avatar avatar={user} />
</div>
<div class="display-name">
<span class="label">{user.name}</span>
<span class="label">{user.displayName || user.name}</span>
</div>
<div class="commit-message">
<a href={canonicalURL}>
Expand Down
Expand Up @@ -21,7 +21,8 @@

<style lang="scss">
.progress-message {
font-size: var(--font-size-base);
font-size: var(--font-size-small);
color: var(--text-title);
&.error-text {
color: var(--danger);
Expand Down
Expand Up @@ -65,13 +65,18 @@
align-items: center;
gap: 0.75rem;
padding: 0.375rem 0.75rem;
border-radius: var(--border-radius);
&:hover {
background-color: var(--color-bg-2);
}
.messages {
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: flex-start;
row-gap: 0.125rem;
row-gap: 0.25rem;
}
span {
Expand Down
Expand Up @@ -58,6 +58,7 @@
column-gap: 0.5rem;
color: var(--text-muted);
white-space: nowrap;
font-size: var(--font-size-tiny);
.info-badge {
background-color: var(--primary-2);
Expand Down
Expand Up @@ -32,11 +32,13 @@
{/if}
</h3>
<div class="content">
{#if $readme.value}
<Readme file={$readme.value} />
{:else if !$readme.pending}
{data.resolvedRevision.repo.description}
{/if}
<div class="inner">
{#if $readme.value}
<Readme file={$readme.value} />
{:else if !$readme.pending}
{data.resolvedRevision.repo.description}
{/if}
</div>
</div>

<style lang="scss">
Expand Down Expand Up @@ -68,8 +70,15 @@
}
.content {
padding: 1rem;
overflow: auto;
flex: 1;
// We use an "inner" element to limit the width of the content while
// keeping the scrollbar on the outer element, at the edge of the
// viewport.
.inner {
max-width: var(--viewport-xl);
padding: 1rem;
}
}
</style>
3 changes: 2 additions & 1 deletion client/web-sveltekit/src/routes/svelte-overrides.scss
Expand Up @@ -12,8 +12,9 @@ h6 {
}

body {
--font-size-small: 0.875rem;
--font-size-base: 0.9375rem;
--font-size-small: 0.875rem;
--font-size-tiny: 0.8125rem;
--code-font-size: 13px;
--border-radius: 4px;

Expand Down
3 changes: 1 addition & 2 deletions cmd/frontend/graphqlbackend/external_account.go
Expand Up @@ -2,7 +2,6 @@ package graphqlbackend

import (
"context"
"fmt"

"github.com/graph-gophers/graphql-go"
"github.com/graph-gophers/graphql-go/relay"
Expand Down Expand Up @@ -63,7 +62,7 @@ func (r *externalAccountResolver) CodySubscription(ctx context.Context) (*CodySu
return nil, errors.New("this feature is only available on sourcegraph.com")
}

if r.account.ServiceType != "openidconnect" || r.account.ServiceID != fmt.Sprintf("https://%s", ssc.GetSAMSHostName()) {
if r.account.ServiceType != "openidconnect" || r.account.ServiceID != ssc.GetSAMSServiceID() {
return nil, nil
}

Expand Down
19 changes: 11 additions & 8 deletions cmd/frontend/internal/app/ui/router.go
Expand Up @@ -80,6 +80,13 @@ var aboutRedirects = map[string]string{
"help/terms": "terms",
}

type staticPageInfo struct {
// Specify either path OR pathPrefix.
path, pathPrefix string
name, title string
index bool
}

// Router returns the router that serves pages for our web app.
func Router() *mux.Router {
return uirouter.Router
Expand Down Expand Up @@ -111,13 +118,8 @@ func InitRouter(db database.DB) {
ghAppRouter := r.PathPrefix("/githubapp/").Subrouter()
githubapp.SetupGitHubAppRoutes(ghAppRouter, db)

// Basic pages with static titles
for _, p := range []struct {
// Specify either path OR pathPrefix.
path, pathPrefix string
name, title string
index bool
}{
// Basic pages with static titles.
staticPages := []staticPageInfo{
// with index:
{pathPrefix: "/insights", name: "insights", title: "Insights", index: true},
{pathPrefix: "/search-jobs", name: "search-jobs", title: "Search Jobs", index: true},
Expand Down Expand Up @@ -160,7 +162,8 @@ func InitRouter(db database.DB) {
{path: "/survey", name: "survey", title: "Survey", index: false},
{path: "/survey/{score}", name: "survey-score", title: "Survey", index: false},
{path: "/welcome", name: "welcome", title: "Welcome", index: false},
} {
}
for _, p := range staticPages {
var handler http.Handler
if p.index {
handler = brandedIndex(p.title)
Expand Down
8 changes: 1 addition & 7 deletions cmd/frontend/internal/cody/subscription.go
Expand Up @@ -2,7 +2,6 @@ package cody

import (
"context"
"fmt"
"sync"
"time"

Expand Down Expand Up @@ -88,14 +87,10 @@ func consolidateSubscriptionDetails(ctx context.Context, user types.User, subscr
// will return ("", nil). After we migrate all dotcom user accounts to SAMS, that
// should no longer be possible.
func getSAMSAccountIDsForUser(ctx context.Context, db database.DB, dotcomUserID int32) ([]string, error) {
// NOTE: We hard-code this to look for the SAMS-prod environment, meaning there isn't a way
// to test dotcom pulling subscription data from a local SAMS/SSC instance. To support that
// we'd need to make the SAMSHostname configurable. (Or somehow identify which OIDC provider
// is SAMS.)
oidcAccounts, err := db.UserExternalAccounts().List(ctx, database.ExternalAccountsListOptions{
UserID: dotcomUserID,
ServiceType: "openidconnect",
ServiceID: fmt.Sprintf("https://%s", ssc.GetSAMSHostName()),
ServiceID: ssc.GetSAMSServiceID(),
})
if err != nil {
return []string{}, errors.Wrap(err, "listing external accounts")
Expand Down Expand Up @@ -137,7 +132,6 @@ func SubscriptionForUser(ctx context.Context, db database.DB, user types.User) (
// While developing the SSC backend, we only fetch subscription data for users based on a flag.
var subscription *ssc.Subscription
if samsAccountID != "" {

subscription, err = sscClient.FetchSubscriptionBySAMSAccountID(ctx, samsAccountID)
if err != nil {
return nil, errors.Wrap(err, "fetching subscription from SSC")
Expand Down
3 changes: 1 addition & 2 deletions cmd/frontend/internal/cody/subscription_test.go
Expand Up @@ -2,7 +2,6 @@ package cody

import (
"context"
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -130,7 +129,7 @@ func TestGetSubscriptionForUser(t *testing.T) {
accounts = append(accounts, &extsvc.Account{AccountSpec: extsvc.AccountSpec{
AccountID: MockSSCValue.SAMSAccountID,
ServiceType: "openidconnect",
ServiceID: fmt.Sprintf("https://%s/", ssc.GetSAMSHostName()),
ServiceID: ssc.GetSAMSServiceID(),
}})
}

Expand Down
Expand Up @@ -2,7 +2,6 @@ package productsubscription_test

import (
"context"
"fmt"
"math"
"testing"
"time"
Expand Down Expand Up @@ -313,7 +312,7 @@ func TestCodyGatewayCompletionsRateLimit(t *testing.T) {
AccountSpec: extsvc.AccountSpec{
AccountID: "123",
ServiceType: "openidconnect",
ServiceID: fmt.Sprintf("https://%s", ssc.GetSAMSHostName()),
ServiceID: ssc.GetSAMSServiceID(),
},
})
require.NoError(t, err)
Expand All @@ -328,7 +327,7 @@ func TestCodyGatewayCompletionsRateLimit(t *testing.T) {
AccountSpec: extsvc.AccountSpec{
AccountID: "456",
ServiceType: "openidconnect",
ServiceID: fmt.Sprintf("https://%s", ssc.GetSAMSHostName()),
ServiceID: ssc.GetSAMSServiceID(),
},
})
require.NoError(t, err)
Expand All @@ -343,7 +342,7 @@ func TestCodyGatewayCompletionsRateLimit(t *testing.T) {
AccountSpec: extsvc.AccountSpec{
AccountID: "789",
ServiceType: "openidconnect",
ServiceID: fmt.Sprintf("https://%s", ssc.GetSAMSHostName()),
ServiceID: ssc.GetSAMSServiceID(),
},
})
require.NoError(t, err)
Expand All @@ -358,7 +357,7 @@ func TestCodyGatewayCompletionsRateLimit(t *testing.T) {
AccountSpec: extsvc.AccountSpec{
AccountID: "abc",
ServiceType: "openidconnect",
ServiceID: fmt.Sprintf("https://%s", ssc.GetSAMSHostName()),
ServiceID: ssc.GetSAMSServiceID(),
},
})
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/frontend/internal/httpapi/ssc.go
Expand Up @@ -27,7 +27,7 @@ func newSSCRefreshCodyRateLimitHandler(logger log.Logger, db database.DB) http.H
oidcAccounts, err := db.UserExternalAccounts().List(ctx, database.ExternalAccountsListOptions{
AccountID: samsAccountID,
ServiceType: "openidconnect",
ServiceID: fmt.Sprintf("https://%s", ssc.GetSAMSHostName()),
ServiceID: ssc.GetSAMSServiceID(),
LimitOffset: &database.LimitOffset{
Limit: 1,
},
Expand Down
58 changes: 45 additions & 13 deletions cmd/frontend/internal/ssc/ssc.go
Expand Up @@ -113,13 +113,52 @@ func (c *client) FetchSubscriptionBySAMSAccountID(ctx context.Context, samsAccou
}
}

func GetSAMSHostName() string {
sgconf := conf.Get().SiteConfig()
// getSSCBaseURL returns the base URL for the SSC backend's REST API for
// service-to-service requests.
func getSSCBaseURL() string {
config := conf.Get()

// Prefer the newer "dotcom.codyProConfig.sscBackendOrigin" config setting if available.
// This allows for local development (not hard-coding the https scheme).
if dotcomConfig := config.Dotcom; dotcomConfig != nil {
if codyProConfig := dotcomConfig.CodyProConfig; codyProConfig != nil {
return fmt.Sprintf("%s/cody/api", codyProConfig.SscBackendOrigin)
}
}

// Fall back to original logic, using the "ssc.apiBaseUrl" setting.
// (To be removed when the codyProConfig changes are in production.)
siteConfig := config.SiteConfig()
baseURL := siteConfig.SscApiBaseUrl
if baseURL == "" {
baseURL = "https://accounts.sourcegraph.com/cody/api"
}

return baseURL
}

// GetSAMSServiceID returns the ServiceID of the currently registered SAMS identity provider.
// This is found in the site configuration, and must match the auth.providers configuration
// exactly.
func GetSAMSServiceID() string {
config := conf.Get()

// Prefer the newer "dotcom.codyProConfig.samsBackendOrigin" config setting if available.
// This allows for local development (not hard-coding the https scheme).
if dotcomConfig := config.Dotcom; dotcomConfig != nil {
if codyProConfig := dotcomConfig.CodyProConfig; codyProConfig != nil {
return codyProConfig.SamsBackendOrigin
}
}

// Fallback to the original logic, using the "ssc.samsHostName" setting.
// (To be removed when the codyProConfig changes are in production.)
sgconf := config.SiteConfig()
if sgconf.SscSamsHostName == "" {
// If unset, default to the production hostname.
return "accounts.sourcegraph.com"
return "https://accounts.sourcegraph.com"
}
return sgconf.SscSamsHostName
return fmt.Sprintf("https://%s", sgconf.SscSamsHostName)
}

// NewClient returns a new SSC API client. It is important to avoid creating new
Expand All @@ -130,8 +169,6 @@ func GetSAMSHostName() string {
// If no SAMS authorization provider is configured, this function will not panic,
// but instead will return an error on every call.
func NewClient() (Client, error) {
sgconf := conf.Get().SiteConfig()

// Fetch the SAMS configuration data.
var samsConfig *clientcredentials.Config
for _, provider := range conf.Get().AuthProviders {
Expand All @@ -140,7 +177,7 @@ func NewClient() (Client, error) {
continue
}

if strings.Contains(oidcInfo.Issuer, GetSAMSHostName()) {
if oidcInfo.Issuer == GetSAMSServiceID() {
samsConfig = &clientcredentials.Config{
ClientID: oidcInfo.ClientID,
ClientSecret: oidcInfo.ClientSecret,
Expand All @@ -155,17 +192,12 @@ func NewClient() (Client, error) {
return &client{}, errors.New("no SAMS authorization provider configured")
}

baseURL := sgconf.SscApiBaseUrl
if baseURL == "" {
baseURL = "https://accounts.sourcegraph.com/cody/api"
}

// We want this tokenSource to be long lived, so we benefit from reusing existing
// SAMS tokens if repeated requests are made within the token's lifetime. (Under
// the hood it returns an oauth2.ReuseTokenSource.)
tokenSource := samsConfig.TokenSource(context.Background())
return &client{
baseURL: baseURL,
baseURL: getSSCBaseURL(),
samsTokenSource: tokenSource,
}, nil
}
14 changes: 0 additions & 14 deletions cmd/gitserver/BUILD.bazel
Expand Up @@ -27,19 +27,6 @@ pkg_tar(
srcs = [":gitserver"],
)

pkg_tar(
name = "tar_p4_fusion_wrappers",
srcs = [
"p4-fusion-wrapper-detect-kill.sh",
"process-stats-watcher.sh",
],
remap_paths = {
"/p4-fusion-wrapper-detect-kill.sh": "/usr/local/bin/p4-fusion",
"/process-stats-watcher.sh": "/usr/local/bin/process-stats-watcher.sh",
},
visibility = ["//visibility:public"],
)

oci_image(
name = "image",
base = ":base_image",
Expand All @@ -50,7 +37,6 @@ oci_image(
],
tars = [
":tar_gitserver",
":tar_p4_fusion_wrappers",
],
user = "sourcegraph",
workdir = "/",
Expand Down

0 comments on commit 2ae19de

Please sign in to comment.