@@ -6,6 +6,8 @@ package harness
6
6
7
7
import (
8
8
"context"
9
+ "fmt"
10
+ "strings"
9
11
10
12
"github.com/drone/go-scm/scm"
11
13
)
@@ -15,9 +17,19 @@ type userService struct {
15
17
}
16
18
17
19
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
21
33
}
22
34
23
35
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,
36
48
// native data structures
37
49
//
38
50
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"`
47
87
}
48
88
49
89
//
50
90
// native data structure conversion
51
91
//
52
92
53
- func convertUser (src * user ) * scm.User {
93
+ func convertHarnessUser (src * harnessUser ) * scm.User {
54
94
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 ,
59
99
}
60
100
}
0 commit comments