refactor: remove unused context
This commit is contained in:
@@ -117,7 +117,7 @@ func newConnector(ctx context.Context, source *Source) (Connector, error) {
|
|||||||
switch cred := source.conn.GetCredential().(type) {
|
switch cred := source.conn.GetCredential().(type) {
|
||||||
case *sourcespb.GitHub_GithubApp:
|
case *sourcespb.GitHub_GithubApp:
|
||||||
log.RedactGlobally(cred.GithubApp.GetPrivateKey())
|
log.RedactGlobally(cred.GithubApp.GetPrivateKey())
|
||||||
return NewAppConnector(ctx, apiEndpoint, cred.GithubApp, source.conn.GetScanAllInstallations())
|
return NewAppConnector(apiEndpoint, cred.GithubApp, source.conn.GetScanAllInstallations())
|
||||||
case *sourcespb.GitHub_BasicAuth:
|
case *sourcespb.GitHub_BasicAuth:
|
||||||
log.RedactGlobally(cred.BasicAuth.GetPassword())
|
log.RedactGlobally(cred.BasicAuth.GetPassword())
|
||||||
return NewBasicAuthConnector(ctx, apiEndpoint, source.conn.GetClonePath(), cred.BasicAuth)
|
return NewBasicAuthConnector(ctx, apiEndpoint, source.conn.GetClonePath(), cred.BasicAuth)
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ var _ Connector = (*appConnector)(nil)
|
|||||||
|
|
||||||
const githubHTTPTimeoutSeconds = 60
|
const githubHTTPTimeoutSeconds = 60
|
||||||
|
|
||||||
func NewAppConnector(ctx context.Context, apiEndpoint string, app *credentialspb.GitHubApp, scanAllInstallations bool) (Connector, error) {
|
func NewAppConnector(apiEndpoint string, app *credentialspb.GitHubApp, scanAllInstallations bool) (Connector, error) {
|
||||||
var installationID int64
|
var installationID int64
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@@ -130,10 +130,10 @@ func (c *appConnector) APIClientForRepo(repoURL string) (*github.Client, error)
|
|||||||
|
|
||||||
func (c *appConnector) GraphQLClientForRepo(ctx context.Context, repoURL string) (*githubv4.Client, error) {
|
func (c *appConnector) GraphQLClientForRepo(ctx context.Context, repoURL string) (*githubv4.Client, error) {
|
||||||
installID, _ := c.installationIDForRepo(repoURL)
|
installID, _ := c.installationIDForRepo(repoURL)
|
||||||
return c.graphqlClientForInstallation(ctx, installID)
|
return c.graphqlClientForInstallation(installID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *appConnector) graphqlClientForInstallation(ctx context.Context, installID int64) (*githubv4.Client, error) {
|
func (c *appConnector) graphqlClientForInstallation(installID int64) (*githubv4.Client, error) {
|
||||||
clients, err := c.clientsForInstallation(installID)
|
clients, err := c.clientsForInstallation(installID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -238,7 +238,7 @@ func (c *appConnector) setRepoInstallationForWiki(repoURL string, installationID
|
|||||||
// installation, lazily creating it if needed. See APIClient for why this
|
// installation, lazily creating it if needed. See APIClient for why this
|
||||||
// cannot simply return nil when no default installation is configured.
|
// cannot simply return nil when no default installation is configured.
|
||||||
func (c *appConnector) GraphQLClient() *githubv4.Client {
|
func (c *appConnector) GraphQLClient() *githubv4.Client {
|
||||||
client, err := c.graphqlClientForInstallation(context.Background(), c.installationID)
|
client, err := c.graphqlClientForInstallation(c.installationID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ func TestNewAppConnectorDefaultAPIClientUsesConfiguredInstallation(t *testing.T)
|
|||||||
}))
|
}))
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
|
||||||
connector, err := NewAppConnector(trContext.Background(), server.URL, &credentialspb.GitHubApp{
|
connector, err := NewAppConnector(server.URL, &credentialspb.GitHubApp{
|
||||||
PrivateKey: string(privKey),
|
PrivateKey: string(privKey),
|
||||||
InstallationId: "4242",
|
InstallationId: "4242",
|
||||||
AppId: "12345",
|
AppId: "12345",
|
||||||
@@ -184,7 +184,7 @@ func TestNewAppConnectorInstallationIDOptionalWithScanAllInstallations(t *testin
|
|||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
|
||||||
// scanAllInstallations=true with no installationId configured should succeed.
|
// scanAllInstallations=true with no installationId configured should succeed.
|
||||||
connector, err := NewAppConnector(trContext.Background(), server.URL, &credentialspb.GitHubApp{
|
connector, err := NewAppConnector(server.URL, &credentialspb.GitHubApp{
|
||||||
PrivateKey: string(privKey),
|
PrivateKey: string(privKey),
|
||||||
AppId: "12345",
|
AppId: "12345",
|
||||||
}, true)
|
}, true)
|
||||||
@@ -192,7 +192,7 @@ func TestNewAppConnectorInstallationIDOptionalWithScanAllInstallations(t *testin
|
|||||||
require.NotNil(t, connector)
|
require.NotNil(t, connector)
|
||||||
|
|
||||||
// Without scanAllInstallations, installationId is still required.
|
// Without scanAllInstallations, installationId is still required.
|
||||||
_, err = NewAppConnector(trContext.Background(), server.URL, &credentialspb.GitHubApp{
|
_, err = NewAppConnector(server.URL, &credentialspb.GitHubApp{
|
||||||
PrivateKey: string(privKey),
|
PrivateKey: string(privKey),
|
||||||
AppId: "12345",
|
AppId: "12345",
|
||||||
}, false)
|
}, false)
|
||||||
@@ -215,7 +215,7 @@ func TestAPIClientAndGraphQLClientNonNilWithoutDefaultInstallation(t *testing.T)
|
|||||||
}))
|
}))
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
|
||||||
connector, err := NewAppConnector(trContext.Background(), server.URL, &credentialspb.GitHubApp{
|
connector, err := NewAppConnector(server.URL, &credentialspb.GitHubApp{
|
||||||
PrivateKey: string(privKey),
|
PrivateKey: string(privKey),
|
||||||
AppId: "12345",
|
AppId: "12345",
|
||||||
}, true)
|
}, true)
|
||||||
|
|||||||
@@ -375,15 +375,11 @@ func TestAppConnector_EnterpriseBaseURL(t *testing.T) {
|
|||||||
privateKey := createPrivateKey()
|
privateKey := createPrivateKey()
|
||||||
enterpriseEndpoint := "https://api.example.ghe.com"
|
enterpriseEndpoint := "https://api.example.ghe.com"
|
||||||
|
|
||||||
connector, err := NewAppConnector(
|
connector, err := NewAppConnector(enterpriseEndpoint, &credentialspb.GitHubApp{
|
||||||
context.Background(),
|
PrivateKey: privateKey,
|
||||||
enterpriseEndpoint,
|
InstallationId: "1337",
|
||||||
&credentialspb.GitHubApp{
|
AppId: "4141",
|
||||||
PrivateKey: privateKey,
|
}, false)
|
||||||
InstallationId: "1337",
|
|
||||||
AppId: "4141",
|
|
||||||
},
|
|
||||||
false)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
appConn, ok := connector.(*appConnector)
|
appConn, ok := connector.(*appConnector)
|
||||||
|
|||||||
Reference in New Issue
Block a user