-
-
Notifications
You must be signed in to change notification settings - Fork 27
Runneradmin flow + broker message listener #205
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1c4e8b4
wip
ChristopherHX 0b166aa
Merge branch 'main' of https://github.com/ChristopherHX/github-act-ru…
ChristopherHX 100ddba
Reworkv2 register
ChristopherHX 1ea7dda
add code for broker message listener
ChristopherHX 1881e1a
fixup
ChristopherHX 2ee2417
fixup
ChristopherHX 1a102aa
fix set missing status
ChristopherHX 0895bc6
fix bug of deleting messages
ChristopherHX 8945530
Merge branch 'main' of https://github.com/ChristopherHX/github-act-ru…
ChristopherHX 9ddb0e9
fix lint
ChristopherHX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package protocol | ||
|
|
||
| type Runner struct { | ||
| Name string `json:"name"` | ||
| Id int64 `json:"id"` | ||
| Authorization struct { | ||
| AuthorizationURL string `json:"authorization_url"` | ||
| ServerURL string `json:"server_url"` | ||
| ClientId string `json:"client_id"` | ||
| } `json:"authorization"` | ||
| } | ||
|
|
||
| type RunnerGroup struct { | ||
| Id int32 `json:"id,omitempty"` | ||
| Name string `json:"name,omitempty"` | ||
| IsDefault bool `json:"default,omitempty"` | ||
| IsHosted bool `json:"is_hosted,omitempty"` | ||
| } | ||
|
|
||
| type RunnerGroupList struct { | ||
| RunnerGroups []RunnerGroup `json:"runner_groups"` | ||
| Count int `json:"total_count"` | ||
| } | ||
|
|
||
| type ListRunnersResponse struct { | ||
| TotalCount int `json:"total_count"` | ||
| Runners []Runner `json:"runners"` | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import ( | |
| "crypto/cipher" | ||
| "crypto/rand" | ||
| "crypto/rsa" | ||
| "net/url" | ||
| "strings" | ||
|
|
||
| // nolint:gosec | ||
|
|
@@ -27,7 +28,7 @@ type TaskAgentMessage struct { | |
| Body string | ||
| } | ||
|
|
||
| func (message *TaskAgentMessage) Decrypt(block cipher.Block) ([]byte, error) { | ||
| func (message *TaskAgentMessage) Decrypt(session *AgentMessageConnection) ([]byte, error) { | ||
| if message.IV == "" { | ||
| return []byte(message.Body), nil | ||
| } | ||
|
|
@@ -39,9 +40,17 @@ func (message *TaskAgentMessage) Decrypt(block cipher.Block) ([]byte, error) { | |
| if err != nil { | ||
| return nil, err | ||
| } | ||
| cbcdec := cipher.NewCBCDecrypter(block, iv) | ||
| if session.Block == nil { | ||
| // Parse Key | ||
| var err error | ||
| session.Block, err = session.TaskAgentSession.GetSessionKey(session.VssConnection.Key) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
| cbcdec := cipher.NewCBCDecrypter(session.Block, iv) | ||
| cbcdec.CryptBlocks(src, src) | ||
| maxlen := block.BlockSize() | ||
| maxlen := session.Block.BlockSize() | ||
| validlen := len(src) | ||
| if int(src[len(src)-1]) <= maxlen { // <= is needed if the message ends within a block boundary and maxlen=16 then we get 16 times char 16 appended, one whole extra block | ||
| ok := true | ||
|
|
@@ -71,7 +80,7 @@ func (message *TaskAgentMessage) FetchBrokerIfNeeded(xctx context.Context, sessi | |
| if strings.EqualFold(message.MessageType, "BrokerMigration") { | ||
| vssConnection := session.VssConnection | ||
| rjrr := &BrokerMigration{} | ||
| raw, err := message.Decrypt(session.Block) | ||
| raw, err := message.Decrypt(session) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -112,11 +121,12 @@ type TaskAgentSessionKey struct { | |
| } | ||
|
|
||
| type TaskAgentSession struct { | ||
| SessionID string `json:",omitempty"` | ||
| EncryptionKey TaskAgentSessionKey | ||
| OwnerName string | ||
| Agent TaskAgent | ||
| UseFipsEncryption bool | ||
| SessionID string `json:",omitempty"` | ||
| EncryptionKey TaskAgentSessionKey | ||
| OwnerName string | ||
| Agent TaskAgent | ||
| UseFipsEncryption bool | ||
| BrokerMigrationMessage *BrokerMigration `json:",omitempty"` | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed today again as unused code, planning revert |
||
| } | ||
|
|
||
| func (session *TaskAgentSession) GetSessionKey(key *rsa.PrivateKey) (cipher.Block, error) { | ||
|
|
@@ -145,30 +155,50 @@ type AgentMessageConnection struct { | |
| TaskAgentSession *TaskAgentSession | ||
| Block cipher.Block | ||
| Status string | ||
| ServerV2URL string | ||
| } | ||
|
|
||
| func (session *AgentMessageConnection) Delete(ctx context.Context) error { | ||
| if session.ServerV2URL != "" { | ||
| return session.VssConnection.RequestWithContext2(ctx, "DELETE", session.ServerV2URL+"/session", "", nil, nil) | ||
| } | ||
| return session.VssConnection.RequestWithContext(ctx, "134e239e-2df3-4794-a6f6-24f1f19ec8dc", "5.1-preview", "DELETE", map[string]string{ | ||
| "poolId": fmt.Sprint(session.VssConnection.PoolID), | ||
| "sessionId": session.TaskAgentSession.SessionID, | ||
| }, map[string]string{}, session.TaskAgentSession, nil) | ||
| } | ||
|
|
||
| func (session *AgentMessageConnection) GetNextMessage(ctx context.Context) (*TaskAgentMessage, error) { | ||
| func (session *AgentMessageConnection) GetSingleMessage(ctx context.Context) (*TaskAgentMessage, error) { | ||
| message := &TaskAgentMessage{} | ||
| for { | ||
| select { | ||
| case <-ctx.Done(): | ||
| return nil, context.Canceled | ||
| default: | ||
| } | ||
| err := session.VssConnection.RequestWithContext(ctx, "c3a054f6-7a8a-49c0-944e-3a8e5d7adfd7", "5.1-preview", "GET", map[string]string{ | ||
| var err error | ||
| if session.ServerV2URL != "" { | ||
| query := url.Values{} | ||
| query.Set("sessionId", session.TaskAgentSession.SessionID) | ||
| query.Set("runnerVersion", "3.0.0") | ||
| query.Set("status", session.Status) | ||
| query.Set("disableUpdate", fmt.Sprint(session.TaskAgentSession.Agent.DisableUpdate)) | ||
| err = session.VssConnection.RequestWithContext2(ctx, "GET", session.ServerV2URL+"/message?"+query.Encode(), "", nil, message) | ||
| } else { | ||
| err = session.VssConnection.RequestWithContext(ctx, "c3a054f6-7a8a-49c0-944e-3a8e5d7adfd7", "5.1-preview", "GET", map[string]string{ | ||
| "poolId": fmt.Sprint(session.VssConnection.PoolID), | ||
| }, map[string]string{ | ||
| "sessionId": session.TaskAgentSession.SessionID, | ||
| "runnerVersion": "3.0.0", | ||
| "status": session.Status, | ||
| }, nil, message) | ||
| // TODO lastMessageId= | ||
| } | ||
| return message, err | ||
| } | ||
|
|
||
| func (session *AgentMessageConnection) GetNextMessage(ctx context.Context) (*TaskAgentMessage, error) { | ||
| for { | ||
| select { | ||
| case <-ctx.Done(): | ||
| return nil, context.Canceled | ||
| default: | ||
| } | ||
| message, err := session.GetSingleMessage(ctx) | ||
| if err == nil { | ||
| err = session.DeleteMessage(ctx, message) | ||
| err = errors.Join(err, message.FetchBrokerIfNeeded(ctx, session)) | ||
|
|
@@ -191,6 +221,10 @@ func (session *AgentMessageConnection) GetNextMessage(ctx context.Context) (*Tas | |
| } | ||
|
|
||
| func (session *AgentMessageConnection) DeleteMessage(ctx context.Context, message *TaskAgentMessage) error { | ||
| if session.ServerV2URL != "" { | ||
| // V2 no support for deleting messages | ||
| return nil | ||
| } | ||
| return session.VssConnection.RequestWithContext(ctx, "c3a054f6-7a8a-49c0-944e-3a8e5d7adfd7", "5.1-preview", "DELETE", map[string]string{ | ||
| "poolId": fmt.Sprint(session.VssConnection.PoolID), | ||
| "messageId": fmt.Sprint(message.MessageID), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
remove this