mirrored from https://skia.googlesource.com/buildbot
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add swarming_token app to retrieve a token and write to a file
Retrieves the service account token from metadata and writes to the location expected by Swarming. Should be run as a cron job. Also add go_build_all_platforms.sh to compile an app for every platform we support, and go_build_and_upload_all_platforms.sh to do the same and upload to the skia-public-binaries bucket. Bug: skia:5410 Change-Id: Id0ac5bd84ecdf1f66a95eb1864a28d16d5c200dc Reviewed-on: https://skia-review.googlesource.com/99886 Reviewed-by: Kevin Lubick <kjlubick@google.com> Reviewed-by: Ben Wagner <benjaminwagner@google.com> Commit-Queue: Eric Boren <borenet@google.com>
- Loading branch information
Showing
18 changed files
with
198 additions
and
74 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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,57 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"io" | ||
"runtime" | ||
|
||
"go.skia.org/infra/go/common" | ||
"go.skia.org/infra/go/metadata" | ||
"go.skia.org/infra/go/skiaversion" | ||
"go.skia.org/infra/go/sklog" | ||
"go.skia.org/infra/go/util" | ||
) | ||
|
||
/* | ||
Obtain an OAuth token from metadata and write it to the expected location. | ||
Run this program every 4 minutes to ensure that the token is always valid. | ||
*/ | ||
|
||
const ( | ||
TOKEN_DEST = "/var/lib/swarming/oauth_bot_token.json" | ||
TOKEN_DEST_WIN = "C:\\swarming\\oauth_bot_token.json" | ||
) | ||
|
||
func main() { | ||
common.Init() | ||
skiaversion.MustLogVersion() | ||
|
||
// Obtain the token. | ||
tok, err := metadata.GetToken() | ||
if err != nil { | ||
sklog.Fatal(err) | ||
} | ||
|
||
// Swarming expects tokens in a slightly different format. | ||
token := struct { | ||
Token string `json:"token"` | ||
TokenType string `json:"token_type"` | ||
Expiry int64 `json:"expiry"` | ||
}{ | ||
Token: tok.AccessToken, | ||
TokenType: tok.TokenType, | ||
Expiry: tok.Expiry.Unix(), | ||
} | ||
|
||
// Write the token to the expected location. | ||
dest := TOKEN_DEST | ||
if runtime.GOOS == "windows" { | ||
dest = TOKEN_DEST_WIN | ||
} | ||
if err := util.WithWriteFile(dest, func(w io.Writer) error { | ||
return json.NewEncoder(w).Encode(token) | ||
}); err != nil { | ||
sklog.Fatal(err) | ||
} | ||
} |
This file contains 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 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.