-
Notifications
You must be signed in to change notification settings - Fork 9
add caib image token command for internal registry builds
#177
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
bennyz
merged 1 commit into
centos-automotive-suite:main
from
bennyz:worktree-image-token-cmd
Mar 23, 2026
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // Package tokencmd provides the image registry token request handler. | ||
| package tokencmd | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| common "github.com/centos-automotive-suite/automotive-dev-operator/cmd/caib/common" | ||
| buildapitypes "github.com/centos-automotive-suite/automotive-dev-operator/internal/buildapi" | ||
| buildapiclient "github.com/centos-automotive-suite/automotive-dev-operator/internal/buildapi/client" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // Options wires token handler dependencies. | ||
| type Options struct { | ||
| ServerURL *string | ||
| AuthToken *string | ||
| InsecureSkipTLS *bool | ||
|
|
||
| HandleError func(error) | ||
| } | ||
|
|
||
| // Handler implements the token command run function. | ||
| type Handler struct { | ||
| opts Options | ||
| } | ||
|
|
||
| // NewHandler creates a token handler. | ||
| func NewHandler(opts Options) *Handler { | ||
| return &Handler{opts: opts} | ||
| } | ||
|
|
||
| func (h *Handler) handleError(err error) { | ||
| if h.opts.HandleError != nil { | ||
| h.opts.HandleError(err) | ||
| return | ||
| } | ||
| panic(err) | ||
| } | ||
|
|
||
| // RunToken handles `caib image token`. | ||
| func (h *Handler) RunToken(_ *cobra.Command, args []string) { | ||
| ctx := context.Background() | ||
| buildName := args[0] | ||
|
|
||
| if h.opts.ServerURL == nil || strings.TrimSpace(*h.opts.ServerURL) == "" { | ||
| h.handleError(fmt.Errorf("server URL required (use --server, CAIB_SERVER, run 'caib login <server-url>' or 'jmp login <endpoint>')")) | ||
| return | ||
| } | ||
| if h.opts.InsecureSkipTLS == nil { | ||
| h.handleError(fmt.Errorf("internal error: --insecure option is not configured")) | ||
| return | ||
| } | ||
|
|
||
| serverURL := strings.TrimSpace(*h.opts.ServerURL) | ||
| insecureSkipTLS := *h.opts.InsecureSkipTLS | ||
|
|
||
| var tok *buildapitypes.TokenResponse | ||
| err := common.ExecuteWithReauth(serverURL, h.opts.AuthToken, insecureSkipTLS, func(api *buildapiclient.Client) error { | ||
| var tokenErr error | ||
| tok, tokenErr = api.CreateBuildToken(ctx, buildName) | ||
| return tokenErr | ||
| }) | ||
| if err != nil { | ||
| h.handleError(fmt.Errorf("error requesting token for build %s: %w", buildName, err)) | ||
| return | ||
| } | ||
|
|
||
| fmt.Printf("Registry: %s\n", tok.Registry) | ||
| fmt.Printf("Image: %s\n", tok.Image) | ||
| fmt.Printf("Username: %s\n", tok.Username) | ||
| fmt.Printf("Token: %s\n", tok.Token) | ||
| fmt.Printf("Expires: %s\n", tok.ExpiresAt) | ||
| fmt.Println() | ||
| fmt.Println("To authenticate:") | ||
| fmt.Printf(" echo '%s' | podman login %s --username %s --password-stdin\n", tok.Token, tok.Registry, tok.Username) | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.