-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Writable deploy keys (closes #671) #3225
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
Conversation
models/ssh_key.go
Outdated
@@ -600,6 +600,9 @@ type DeployKey struct { | |||
Fingerprint string | |||
Content string `xorm:"-"` | |||
|
|||
Mode AccessMode |
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.
Why is access mode needed, why not just use ReadOnly?
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.
Also as table is changed it needs migration to Sync2 that type
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.
It's a little tricky...
DeployKey
seems to be just a proxy table, with some cached property (like Name
and Fingerprint
) of PublicKey
. Using the same reasoning, I thought that it will be better to have a Mode
column (like Name
and Fingerprint
).
Another way to do this will be to have retrieved the Mode
from PublicKey
(similar to how Content
is retrieved), but this means an extra query for each access (most probably in AfterLoad
function, since xorm doesn't that for you...maybe go-xorm/xorm#41 will solve it).
ReadOnly
is just a property so I don't have to compare Mode
with AccessRead
, more like HasRecentActivity
.
@@ -31,7 +31,7 @@ | |||
{{.Fingerprint}} | |||
</div> | |||
<div class="activity meta"> | |||
<i>{{$.i18n.Tr "settings.add_on"}} <span>{{.CreatedUnix.FormatShort}}</span> — <i class="octicon octicon-info"></i> {{if .HasUsed}}{{$.i18n.Tr "settings.last_used"}} <span {{if .HasRecentActivity}}class="green"{{end}}>{{.UpdatedUnix.FormatShort}}</span>{{else}}{{$.i18n.Tr "settings.no_activity"}}{{end}}</i> | |||
<i>{{$.i18n.Tr "settings.add_on"}} <span>{{.CreatedUnix.FormatShort}}</span> — <i class="octicon octicon-info"></i> {{if .HasUsed}}{{$.i18n.Tr "settings.last_used"}} <span {{if .HasRecentActivity}}class="green"{{end}}>{{.UpdatedUnix.FormatShort}}</span>{{else}}{{$.i18n.Tr "settings.no_activity"}}{{end}} - <span>Read{{if not .ReadOnly}} / Write {{end}}</i> |
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.
text in templates should use i18n locales
@@ -37,3 +39,54 @@ func TestDeleteDeployKeyNoLogin(t *testing.T) { | |||
req := NewRequest(t, "DELETE", "/api/v1/repos/user2/repo1/keys/1") | |||
MakeRequest(t, req, http.StatusUnauthorized) | |||
} | |||
|
|||
func TestCreateReadOnlyDeployKey(t *testing.T) { |
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 very much for adding tests!
However, our suite of integration tests is becoming quite unwieldy. Would you consider instead writing equivalent unit tests for the DeployKeysPost
handler? See routers/repo/issue_label_test.go for some examples.
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.
I wrote the unit tests, but I don't know if it's ok to dump the integration tests.
Those are testing the API and the unit tests the interface.
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.
Okay, let's leave the integration tests. Eventually, it might make sense to convert our API integration tests to unit tests, but that's for another day. Thanks for adding unit tests!
95c1675
to
a1f29cd
Compare
@lafriks @ethantkoenig Thanks for code review! |
models/migrations/v54.go
Outdated
return fmt.Errorf("Sync2: %v", err) | ||
} | ||
|
||
_, err := x.Cols("mode").Update(&DeployKey{ |
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.
Is this really needed as NOT NULL DEFAULT when adding column should automatically add default value?
options/locale/locale_en-US.ini
Outdated
settings.no_deploy_keys = You haven't added any deploy keys. | ||
settings.title = Title | ||
settings.deploy_key_content = Content | ||
settings.is_writable = Allow write access | ||
settings.is_writable_info = Can this key be used to <strong>push</strong> to this repository? Deploy keys always have pull access. |
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.
Duplicate of lines 991-992?
models/ssh_key.go
Outdated
@@ -600,6 +600,9 @@ type DeployKey struct { | |||
Fingerprint string | |||
Content string `xorm:"-"` | |||
|
|||
Mode AccessMode `xorm:"NOT NULL DEFAULT 1"` | |||
ReadOnly bool `xorm:"-"` |
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.
nit: could we add a ReadOnly()
method instead of adding a field?
integrations/api_keys_test.go
Outdated
ID: newDeployKey.ID, | ||
Name: rawKeyBody.Title, | ||
Content: rawKeyBody.Key, | ||
ReadOnly: true, |
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.
The ReadOnly
field is not stored in the DB, so this condition has no effect. You should instead check the Mode
field (which is in the DB). Likewise for the unit test.
fa1a1a1
to
dd22f0f
Compare
CI failed |
bb97518
to
0f6ae7c
Compare
@vtemian To fix tests please add |
3081099
to
4771472
Compare
Thanks @lafriks |
Codecov Report
@@ Coverage Diff @@
## master #3225 +/- ##
==========================================
+ Coverage 34.67% 35.08% +0.41%
==========================================
Files 278 279 +1
Lines 40506 40522 +16
==========================================
+ Hits 14044 14217 +173
+ Misses 24394 24203 -191
- Partials 2068 2102 +34
Continue to review full report at Codecov.
|
LGTM |
@vtemian you need to rename migration to v55 as other migration was merged already. As soon as you do that this PR can be merged |
5d232ac
to
691820b
Compare
@vtemian please force push to get tests pass, seems to be random failure not related to this PR |
691820b
to
440cd76
Compare
@vtemian you have renamed existing v54.go that comes from master not yours |
3b0686c
to
c5f6b56
Compare
c5f6b56
to
b3e094e
Compare
@lafriks It should be good now. Thanks! |
Add support for read/write deploy key (as github has).
It introduces a new option for write access and an info note that will show the user key's access mode (read/write).


Those options are supported by the API as well.