Skip to content

Commit 1ddface

Browse files
author
TP Honey
authored
Merge pull request #250 from tphoney/harness_user
(feat) harness, add finduser
2 parents 288a76a + f8f38df commit 1ddface

File tree

4 files changed

+115
-34
lines changed

4 files changed

+115
-34
lines changed

scm/driver/harness/testdata/user.json

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,47 @@
11
{
2-
"admin": true,
3-
"blocked": true,
4-
"created": 0,
5-
"display_name": "1",
6-
"email": "2",
7-
"uid": "3",
8-
"updated": 0
2+
"status": "SUCCESS",
3+
"data": {
4+
"uuid": "0Nnoezs6RGa_fOWvG_Ta4w",
5+
"name": "thomas.honey",
6+
"email": "[email protected]",
7+
"token": null,
8+
"defaultAccountId": "px7xd_BFRCi-pfWPYXVjvw",
9+
"intent": null,
10+
"accounts": [
11+
{
12+
"uuid": "px7xd_BFRCi-pfWPYXVjvw",
13+
"accountName": "harness-dev",
14+
"companyName": "harness-dev",
15+
"defaultExperience": "NG",
16+
"createdFromNG": false,
17+
"nextGenEnabled": true
18+
},
19+
{
20+
"uuid": "Ws0xvw71Sm2YmpSC7A8z4g",
21+
"accountName": "OPA-Governance",
22+
"companyName": "Feature-Flag",
23+
"defaultExperience": "NG",
24+
"createdFromNG": false,
25+
"nextGenEnabled": true
26+
}
27+
],
28+
"admin": false,
29+
"twoFactorAuthenticationEnabled": false,
30+
"emailVerified": true,
31+
"locked": false,
32+
"disabled": false,
33+
"signupAction": null,
34+
"edition": null,
35+
"billingFrequency": null,
36+
"utmInfo": {
37+
"utmSource": null,
38+
"utmContent": null,
39+
"utmMedium": null,
40+
"utmTerm": null,
41+
"utmCampaign": null
42+
},
43+
"externallyManaged": false
44+
},
45+
"metaData": null,
46+
"correlationId": "c4014fdb-10a1-4dc4-ace0-6fad93544993"
947
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"ID": "3",
3-
"Login": "2",
4-
"Name": "1",
5-
"Email": "2",
2+
"ID": "0Nnoezs6RGa_fOWvG_Ta4w",
3+
"Login": "[email protected]",
4+
"Name": "thomas.honey",
5+
"Email": "[email protected]",
66
"Avatar": ""
77
}

scm/driver/harness/user.go

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package harness
66

77
import (
88
"context"
9+
"fmt"
10+
"strings"
911

1012
"github.com/drone/go-scm/scm"
1113
)
@@ -15,9 +17,19 @@ type userService struct {
1517
}
1618

1719
func (s *userService) Find(ctx context.Context) (*scm.User, *scm.Response, error) {
18-
out := new(user)
19-
res, err := s.client.do(ctx, "GET", "api/v1/user", nil, out)
20-
return convertUser(out), res, err
20+
out := new(harnessUser)
21+
// the following is for the corporate version of Harness code
22+
tempUserService := *s
23+
// get the basepath
24+
basePath := tempUserService.client.BaseURL.Path
25+
// use the NG user endpoint
26+
basePath = strings.Replace(basePath, "code", "ng", 1)
27+
// set the new basepath
28+
tempUserService.client.BaseURL.Path = basePath
29+
// set the path
30+
path := fmt.Sprintf("api/user/currentUser")
31+
res, err := s.client.do(ctx, "GET", path, nil, out)
32+
return convertHarnessUser(out), res, err
2133
}
2234

2335
func (s *userService) FindLogin(ctx context.Context, login string) (*scm.User, *scm.Response, error) {
@@ -36,25 +48,53 @@ func (s *userService) ListEmail(context.Context, scm.ListOptions) ([]*scm.Email,
3648
// native data structures
3749
//
3850

39-
type user struct {
40-
Admin bool `json:"admin"`
41-
Blocked bool `json:"blocked"`
42-
Created int `json:"created"`
43-
DisplayName string `json:"display_name"`
44-
Email string `json:"email"`
45-
UID string `json:"uid"`
46-
Updated int `json:"updated"`
51+
type harnessUser struct {
52+
Status string `json:"status"`
53+
Data struct {
54+
UUID string `json:"uuid"`
55+
Name string `json:"name"`
56+
Email string `json:"email"`
57+
Token interface{} `json:"token"`
58+
Defaultaccountid string `json:"defaultAccountId"`
59+
Intent interface{} `json:"intent"`
60+
Accounts []struct {
61+
UUID string `json:"uuid"`
62+
Accountname string `json:"accountName"`
63+
Companyname string `json:"companyName"`
64+
Defaultexperience string `json:"defaultExperience"`
65+
Createdfromng bool `json:"createdFromNG"`
66+
Nextgenenabled bool `json:"nextGenEnabled"`
67+
} `json:"accounts"`
68+
Admin bool `json:"admin"`
69+
Twofactorauthenticationenabled bool `json:"twoFactorAuthenticationEnabled"`
70+
Emailverified bool `json:"emailVerified"`
71+
Locked bool `json:"locked"`
72+
Disabled bool `json:"disabled"`
73+
Signupaction interface{} `json:"signupAction"`
74+
Edition interface{} `json:"edition"`
75+
Billingfrequency interface{} `json:"billingFrequency"`
76+
Utminfo struct {
77+
Utmsource interface{} `json:"utmSource"`
78+
Utmcontent interface{} `json:"utmContent"`
79+
Utmmedium interface{} `json:"utmMedium"`
80+
Utmterm interface{} `json:"utmTerm"`
81+
Utmcampaign interface{} `json:"utmCampaign"`
82+
} `json:"utmInfo"`
83+
Externallymanaged bool `json:"externallyManaged"`
84+
} `json:"data"`
85+
Metadata interface{} `json:"metaData"`
86+
Correlationid string `json:"correlationId"`
4787
}
4888

4989
//
5090
// native data structure conversion
5191
//
5292

53-
func convertUser(src *user) *scm.User {
93+
func convertHarnessUser(src *harnessUser) *scm.User {
5494
return &scm.User{
55-
Login: src.Email,
56-
Email: src.Email,
57-
Name: src.DisplayName,
58-
ID: src.UID,
95+
Login: src.Data.Email,
96+
Email: src.Data.Email,
97+
Name: src.Data.Name,
98+
ID: src.Data.UUID,
5999
}
60100
}

scm/driver/harness/user_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"encoding/json"
1010
"io/ioutil"
1111
"net/http"
12+
"strings"
1213
"testing"
1314

1415
"github.com/drone/go-scm/scm"
@@ -18,15 +19,17 @@ import (
1819
)
1920

2021
func TestUsersFind(t *testing.T) {
22+
if harnessPAT == "" {
23+
defer gock.Off()
2124

22-
defer gock.Off()
23-
24-
gock.New(gockOrigin).
25-
Get("/gateway/code/api/v1/user").
26-
Reply(200).
27-
Type("application/json").
28-
File("testdata/user.json")
25+
harnessUserOrigin := strings.Replace(gockOrigin, "code", "ng", 1)
2926

27+
gock.New(harnessUserOrigin).
28+
Get("/gateway/ng/api/user/currentUser").
29+
Reply(200).
30+
Type("application/json").
31+
File("testdata/user.json")
32+
}
3033
client, _ := New(gockOrigin, harnessOrg, harnessAccount, harnessProject)
3134
client.Client = &http.Client{
3235
Transport: &transport.Custom{

0 commit comments

Comments
 (0)