Skip to content

Commit

Permalink
feat: Allow non-admin users to get install info
Browse files Browse the repository at this point in the history
This commit modifies the 'install' command to allow non-admin users to
retrieve installation information for Pipelines-as-Code. Previously, this
command was restricted to admin users only. Now, if the user does not have
rights to list all repos in the cluster, the command will attempt to list
repos in the current namespace instead. The command's help text has been
updated to reflect this change.

Signed-off-by: Chmouel Boudjnah <[email protected]>
  • Loading branch information
chmouel authored and vdemeester committed Jun 21, 2024
1 parent 4f338ba commit f80c589
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
31 changes: 18 additions & 13 deletions docs/content/docs/guide/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,19 +337,24 @@ There is no clean-up of the secret after the run.

### Installation Info

The command tkn pac info provides information about your Pipelines-as-Code
installation, including the location and version. You can also view an overview
of all Repositories CR created on the cluster and their associated URLs.

If your have your installation set-up with a [GitHub App](../../install/github_apps),
you will be able to the see details of the installed application along with
other relevant information like the URL endpoint configured for your GitHub APP.
By default, this will display information from the public GitHub API, but you
can specify a custom GitHub API URL using the `--github-api-url` argument.

It's important to note that only administrators with permission to read the
`pipelines-as-code-secret` secret and list all Repository CR on the cluster are
authorized to access this command.
The `tkn pac info` command provides information about your Pipelines-as-Code
installation, including its location and version.

By default, it displays the version of the Pipelines-as-Code controller and the
namespace where Pipelines-as-Code is installed. This information is accessible
to all users on the cluster through a special ConfigMap named
`pipelines-as-code-info`. This ConfigMap has broad read access in the namespace
where Pipelines-as-Code is installed.

If you are a cluster admin, you can also view an overview of all created
Repositories CR on the cluster, along with their associated URLs.

As an admin, if your installation is set up with a [GitHub
App](../../install/github_apps), you can see the details of the installed
application and other relevant information, such as the URL endpoint configured
for your GitHub App. By default, this will display information from the public
GitHub API, but you can specify a custom GitHub API URL using the
`--github-api-url` argument.

{{< /details >}}

Expand Down
16 changes: 12 additions & 4 deletions pkg/cmd/tknpac/info/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,18 @@ func install(ctx context.Context, run *params.Run, ios *cli.IOStreams, apiURL st
return err
}
}
var reposItems *[]v1alpha1.Repository
repos, err := run.Clients.PipelineAsCode.PipelinesascodeV1alpha1().Repositories("").List(ctx, metav1.ListOptions{})
if err != nil {
return fmt.Errorf("cannot list all repo on cluster, check your rights and that paac is installed: %w", err)
if err == nil {
reposItems = &repos.Items
} else {
// no rights to list every repos in the cluster we are probably not a cluster admin
// try listing in the current namespace in case we have rights
repos, err = run.Clients.PipelineAsCode.PipelinesascodeV1alpha1().Repositories(run.Info.Kube.Namespace).List(ctx, metav1.ListOptions{})
if err == nil {
reposItems = &repos.Items
}
}
reposItems := &repos.Items
args := struct {
Info *InstallInfo
InstallNamespace string
Expand All @@ -107,7 +114,8 @@ func installCommand(run *params.Run, ioStreams *cli.IOStreams) *cobra.Command {
var apiURL string
cmd := &cobra.Command{
Use: "install",
Short: "Provides installation info for pipelines-as-code (admin only).",
Short: "Provides installation info for pipelines-as-code.",
Long: "Provides installation info for pipelines-as-code. This command is used to get the installation info\nIf you are running as administrator and use a GtiHub app it will print information about the GitHub app. ",
RunE: func(_ *cobra.Command, _ []string) error {
ctx := context.Background()
if err := run.Clients.NewClients(ctx, &run.Info); err != nil {
Expand Down
3 changes: 0 additions & 3 deletions pkg/cmd/tknpac/info/templates/info.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,4 @@
{{- range $repo := .Repos }}
- {{ $repo.GetNamespace }} {{ $repo.Spec.URL }}
{{- end }}
{{- else }}

{{.CS.Bold "No repos CR installed on Cluster" }}
{{- end }}
2 changes: 0 additions & 2 deletions pkg/cmd/tknpac/info/testdata/TestInfo/no_repos.golden
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Pipelines as Code:
Install Version: testing
Install Namespace: pipelines-as-code

No repos CR installed on Cluster

0 comments on commit f80c589

Please sign in to comment.