diff --git a/cmd/baton-jenkins/config.go b/cmd/baton-jenkins/config.go index f9ed8fd..29c4db2 100644 --- a/cmd/baton-jenkins/config.go +++ b/cmd/baton-jenkins/config.go @@ -22,6 +22,10 @@ func validateConfig(ctx context.Context, cfg *config) error { return fmt.Errorf("jenkins-baseurl must be provided") } + if cfg.JenkinsUsername == "" { + return fmt.Errorf("jenkins-username must be provided") + } + if cfg.JenkinsToken == "" { if cfg.JenkinsUsername == "" || cfg.JenkinsPassword == "" { return fmt.Errorf("either bitbucketdc-token or (bitbucketdc-username/bitbucketdc-password) must be provided") diff --git a/cmd/baton-jenkins/main.go b/cmd/baton-jenkins/main.go index 345e036..3e15a5e 100644 --- a/cmd/baton-jenkins/main.go +++ b/cmd/baton-jenkins/main.go @@ -40,7 +40,7 @@ func getConnector(ctx context.Context, cfg *config) (types.ConnectorServer, erro l := ctxzap.Extract(ctx) jenkinsClient := client.NewClient() if cfg.JenkinsToken != "" { - jenkinsClient.WithBearerToken(cfg.JenkinsToken) + jenkinsClient.WithUser(cfg.JenkinsUsername).WithBearerToken(cfg.JenkinsToken) } if cfg.JenkinsUsername != "" && cfg.JenkinsPassword != "" { diff --git a/pkg/client/client.go b/pkg/client/client.go index 15a48e4..e714ddd 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -93,13 +93,13 @@ func WithSetBasicAuthHeader(username, password string) uhttp.RequestOption { return uhttp.WithHeader("Authorization", "Basic "+basicAuth(username, password)) } -func WithSetBearerAuthHeader(token string) uhttp.RequestOption { - return uhttp.WithHeader("Authorization", "Bearer "+token) +func WithSetTokenAuthHeader(username, token string) uhttp.RequestOption { + return uhttp.WithHeader("Authorization", "Basic "+basicAuth(username, token)) } func WithAuthorization(username, password, token string) uhttp.RequestOption { if token != "" { - return WithSetBearerAuthHeader(token) + return WithSetTokenAuthHeader(username, token) } return WithSetBasicAuthHeader(username, password) diff --git a/pkg/client/internal_integration_test.go b/pkg/client/internal_integration_test.go index a191c17..d903c9a 100644 --- a/pkg/client/internal_integration_test.go +++ b/pkg/client/internal_integration_test.go @@ -14,11 +14,12 @@ var ( ctx = context.Background() userName, _ = os.LookupEnv("BATON_JENKINS_USERNAME") password, _ = os.LookupEnv("BATON_JENKINS_PASSWORD") + token, _ = os.LookupEnv("BATON_JENKINS_TOKEN") baseUrl = "http://localhost:8080" ) func TestJenkinsClient_GetNodes(t *testing.T) { - if userName == "" && password == "" { + if userName == "" && password == "" && token == "" { t.Skip() } @@ -29,7 +30,7 @@ func TestJenkinsClient_GetNodes(t *testing.T) { } func TestJenkinsClient_GetJobs(t *testing.T) { - if userName == "" && password == "" { + if userName == "" && password == "" && token == "" { t.Skip() } @@ -49,7 +50,7 @@ func getJenkinsClientForTesting() *JenkinsClient { auth: &auth{ user: userName, password: password, - bearerToken: "", + bearerToken: token, }, httpClient: getClientForTesting(ctx), baseUrl: baseUrl, @@ -57,7 +58,7 @@ func getJenkinsClientForTesting() *JenkinsClient { } func TestJenkinsClient_GetViews(t *testing.T) { - if userName == "" && password == "" { + if userName == "" && password == "" && token == "" { t.Skip() } @@ -68,7 +69,7 @@ func TestJenkinsClient_GetViews(t *testing.T) { } func TestJenkinsClient_GetUsers(t *testing.T) { - if userName == "" && password == "" { + if userName == "" && password == "" && token == "" { t.Skip() } @@ -79,7 +80,7 @@ func TestJenkinsClient_GetUsers(t *testing.T) { } func TestJenkinsClient_GetRoles(t *testing.T) { - if userName == "" && password == "" { + if userName == "" && password == "" && token == "" { t.Skip() } @@ -101,7 +102,7 @@ func TestJenkinsClient_GetGroups(t *testing.T) { } func TestJenkinsClient_GetAllRoles(t *testing.T) { - if userName == "" && password == "" { + if userName == "" && password == "" && token == "" { t.Skip() } diff --git a/pkg/connector/connector.go b/pkg/connector/connector.go index 12104f7..1606766 100644 --- a/pkg/connector/connector.go +++ b/pkg/connector/connector.go @@ -35,8 +35,8 @@ func (d *Connector) Asset(ctx context.Context, asset *v2.AssetRef) (string, io.R // Metadata returns metadata about the connector. func (d *Connector) Metadata(ctx context.Context) (*v2.ConnectorMetadata, error) { return &v2.ConnectorMetadata{ - DisplayName: "My Baton Connector", - Description: "The template implementation of a baton connector", + DisplayName: "Jenkins Connector", + Description: "Connector syncing users, roles, groups, nodes and jobs from Jenkins.", }, nil }