-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modified to use Git with PAT #4534
Conversation
26f8907
to
634ff91
Compare
Local behavior testing has not yet been completed... |
+1 for this feature |
89e8a20
to
eb372f7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your PR!
Left comments. PTAL 👀
Also, please review the test data and make the test pass 👍
pkg/config/piped.go
Outdated
@@ -176,6 +179,7 @@ func (s *PipedSpec) Mask() { | |||
s.PipedKeyData = maskString | |||
} | |||
s.Git.Mask() | |||
s.Git.PersonalAccessToken.Mask() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, it would be better to move this line to s.Git.Mask()
.
pkg/config/piped.go
Outdated
if g.ShouldConfigureSSHConfig() && g.PersonalAccessToken.ShouldConfigureSSHConfig() { | ||
return errors.New("cannot configure both sshKeyData or sshKeyFile and personalAccessToken") | ||
} | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please try not to use ShouldConfigureSSHConfig
? This function is supposed to be used in a different context. Validate configs here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kentakozuka
Sorry... I forgot to fix name when I copied.
How about "ShouldConfigurePATConfig" because the function is checking to use PAT or not?
pkg/config/piped.go
Outdated
UserToken string `json:"userToken,omitempty"` | ||
} | ||
|
||
func (p PipedGitPersonalAccessToken) ShouldConfigureSSHConfig() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (p PipedGitPersonalAccessToken) ShouldConfigureSSHConfig() bool { | |
func (p PipedGitPersonalAccessToken) Validate() bool { |
44bfbae
to
fc0e001
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some nits.
pkg/config/piped_test.go
Outdated
@@ -1289,3 +1306,46 @@ func TestFindPlatformProvidersByLabel(t *testing.T) { | |||
}) | |||
} | |||
} | |||
|
|||
func TestPipeGitValidate(t *testing.T) { | |||
testcases := []struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testcases := []struct { | |
t.Parallel() | |
testcases := []struct { |
pkg/config/piped_test.go
Outdated
for _, tc := range testcases { | ||
t.Run(tc.git.SSHKeyData, func(t *testing.T) { | ||
err := tc.git.Validate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for _, tc := range testcases { | |
t.Run(tc.git.SSHKeyData, func(t *testing.T) { | |
err := tc.git.Validate() | |
for _, tc := range testcases { | |
tt := tt | |
t.Run(tc.git.SSHKeyData, func(t *testing.T) { | |
t.Parallel() | |
err := tc.git.Validate() |
pkg/config/piped_test.go
Outdated
func TestPipeGitValidate(t *testing.T) { | ||
testcases := []struct { | ||
git PipedGit | ||
expectedError error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expectedError error | |
err error |
pkg/config/piped_test.go
Outdated
if tc.expectedError != nil { | ||
assert.Equal(t, tc.expectedError, err) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if tc.expectedError != nil { | |
assert.Equal(t, tc.expectedError, err) | |
} else { | |
require.NoError(t, err) | |
} | |
}) | |
assert.Equal(t, tc.err, err) | |
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Can you run make test/go
to make sure all tests pass?
Also, docs needs to be updated.
pkg/config/piped.go
Outdated
@@ -345,6 +351,13 @@ func (g PipedGit) LoadSSHKey() ([]byte, error) { | |||
return nil, errors.New("either sshKeyFile or sshKeyData must be set") | |||
} | |||
|
|||
func (g *PipedGit) Validate() error { | |||
if g.ShouldConfigureSSHConfig() && g.PersonalAccessToken.ShouldConfigurePATConfig() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ShouldConfigureSSHConfig()
is not exactly for validation purpose(called here). Can you validate ssh and pat config without using ShouldConfigureXXX()
?
aa88e0e
to
3d4abae
Compare
Sorry for the delay. |
Sorry, I just checked at hand and the test was down, so please hold on a moment for a review. |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #4534 +/- ##
==========================================
+ Coverage 29.98% 29.99% +0.01%
==========================================
Files 220 220
Lines 25808 25909 +101
==========================================
+ Hits 7739 7772 +33
- Misses 17422 17487 +65
- Partials 647 650 +3
☔ View full report in Codecov by Sentry. |
I had a lint error in Github Actions, so I tried again in my local enviroment, but it appears that some of these are outside the scope of this PR, how should I handle this?
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Left some comments.
CI is passing, so ignore the lint error on local for now.
(I also ran make lint/go
on local and got a bunch of errors. We should fix them in another PR 😉 )
pkg/config/piped.go
Outdated
func (p PipedGitPersonalAccessToken) Validate() bool { | ||
return p.UserName != "" && p.UserToken != "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this function return error for consistency?
ref: https://github.com/pipe-cd/pipecd/blob/master/pkg/config/piped.go#L103
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
pkg/config/piped.go
Outdated
func (g *PipedGit) Validate() error { | ||
if g.ShouldConfigureSSHConfig() && g.PersonalAccessToken.Validate() { | ||
return errors.New("cannot configure both sshKeyData or sshKeyFile and personalAccessToken") | ||
} | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a unit test for this function?
I don't feel this is not enough. What about a case in which one of ShouldConfigureSSHConfig
and PersonalAccessToken.Validate
returns false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected missing test case!
## GitPersonalAccessToken | ||
| Field | Type | Description | Required | | ||
|-|-|-|-| | ||
| userName | string | The user name for git used while cloning above Git repository. | No | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| userName | string | The user name for git used while cloning above Git repository. | No | | |
| userName | string | The user name for git used while cloning above Git repository. | Yes | |
| Field | Type | Description | Required | | ||
|-|-|-|-| | ||
| userName | string | The user name for git used while cloning above Git repository. | No | | ||
| userToken | string | The generated personal access token used while cloning above Git repository. | No | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| userToken | string | The generated personal access token used while cloning above Git repository. | No | | |
| userToken | string | The generated personal access token used while cloning above Git repository. | Yes | |
7f6a679
to
01ad346
Compare
01ad346
to
78cfc03
Compare
What this PR does / why we need it: Modified to use Personal Access Token since currently only SSH can control the Git repository.
Which issue(s) this PR fixes:
Fixes #4106
Does this PR introduce a user-facing change?: Yes