Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,18 @@ linters-settings:
- ^print.*$
- '^t\.Error.*$(# forbid t.Error in favor of using testify\.)?'
- '^t\.Fatal.*$(# forbid t.Fatal in favor of using testify\.)?'
staticcheck:
# SAxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
# Disable deprecation checks, note that we need to deprecate it because golangci-lint doesn't support
# setting a non-error exit code on info severity (setup below)
# https://github.com/golangci/golangci-lint/issues/1981
checks: ["all", "-SA1019"]
severity:
default-severity: error
# NOTE: this still makes the CLI exit with 1 hence the fact that we disabled the rule above as well
# https://github.com/golangci/golangci-lint/issues/1981
rules:
- linters:
- staticcheck
text: "SA1019:"
severity: info
8 changes: 5 additions & 3 deletions app/cli/cmd/attached_integration_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ func newAttachedIntegrationListCmd() *cobra.Command {
}

func attachedIntegrationListTableOutput(attachments []*action.AttachedIntegrationItem) error {
if len(attachments) == 0 {
fmt.Println("there are no integration attached")
switch n := len(attachments); {
case n == 0:
fmt.Println("there are no integrations attached")
return nil
case n > 1:
fmt.Println("Integrations attached to workflows")
}

fmt.Println("Integrations attached to workflows")
t := newTableWriter()
t.AppendHeader(table.Row{"ID", "Kind", "Config", "Attached At", "Workflow"})
for _, attachment := range attachments {
Expand Down
30 changes: 30 additions & 0 deletions app/cli/cmd/casbackend.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// Copyright 2023 The Chainloop Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"github.com/spf13/cobra"
)

func newCASBackendCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "cas-backend",
Short: "Operations on Artifact CAS backends",
}

cmd.AddCommand(newCASBackendListCmd())
return cmd
}
75 changes: 75 additions & 0 deletions app/cli/cmd/casbackend_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// Copyright 2023 The Chainloop Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"fmt"
"time"

"github.com/chainloop-dev/chainloop/app/cli/internal/action"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"
)

func newCASBackendListCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Short: "List CAS Backends from your organization",
RunE: func(cmd *cobra.Command, args []string) error {
res, err := action.NewCASBackendList(actionOpts).Run()
if err != nil {
return err
}

return encodeOutput(res, casBackendListTableOutput)
},
}

cmd.Flags().BoolVar(&full, "full", false, "show the full output")
return cmd
}

func casBackendListTableOutput(backends []*action.CASBackendItem) error {
if len(backends) == 0 {
fmt.Println("there are no cas backends associated")
return nil
}

t := newTableWriter()
header := table.Row{"ID", "Name", "Provider", "Default"}
if full {
header = append(header, "Validation Status", "Created At", "Validated At")
}

t.AppendHeader(header)
for _, b := range backends {
r := table.Row{b.ID, b.Name, b.Provider, b.Default}
if full {
r = append(r, b.ValidationStatus,
b.CreatedAt.Format(time.RFC822),
b.ValidatedAt.Format(time.RFC822),
)
}

t.AppendRow(r)
t.AppendSeparator()
}

t.Render()

return nil
}
3 changes: 2 additions & 1 deletion app/cli/cmd/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ type tabulatedData interface {
[]*action.RegisteredIntegrationItem |
[]*action.AvailableIntegrationItem |
[]*action.AttachedIntegrationItem |
[]*action.MembershipItem
[]*action.MembershipItem |
[]*action.CASBackendItem
}

var ErrOutputFormatNotImplemented = errors.New("format not implemented")
Expand Down
6 changes: 4 additions & 2 deletions app/cli/cmd/registered_integration_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ func newRegisteredIntegrationListCmd() *cobra.Command {
}

func registeredIntegrationListTableOutput(items []*action.RegisteredIntegrationItem) error {
if len(items) == 0 {
switch n := len(items); {
case n == 0:
fmt.Println("there are no third party integrations configured in your organization yet")
return nil
case n > 1:
fmt.Println("Integrations registered and configured in your organization")
}

fmt.Println("Integrations registered and configured in your organization")
t := newTableWriter()
t.AppendHeader(table.Row{"ID", "Description", "Kind", "Config", "Created At"})
for _, i := range items {
Expand Down
5 changes: 4 additions & 1 deletion app/cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ func NewRootCmd(l zerolog.Logger) *cobra.Command {
rootCmd.PersistentFlags().BoolVar(&flagDebug, "debug", false, "Enable debug/verbose logging mode")
rootCmd.PersistentFlags().StringVarP(&flagOutputFormat, "output", "o", "table", "Output format, valid options are json and table")

rootCmd.AddCommand(newWorkflowCmd(), newAuthCmd(), NewVersionCmd(), newAttestationCmd(), newArtifactCmd(), newConfigCmd(), newIntegrationCmd(), newOrganizationCmd())
rootCmd.AddCommand(newWorkflowCmd(), newAuthCmd(), NewVersionCmd(),
newAttestationCmd(), newArtifactCmd(), newConfigCmd(),
newIntegrationCmd(), newOrganizationCmd(), newCASBackendCmd(),
)

return rootCmd
}
Expand Down
88 changes: 88 additions & 0 deletions app/cli/internal/action/casbackend_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// Copyright 2023 The Chainloop Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package action

import (
"context"
"time"

pb "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1"
)

type CASBackendList struct {
cfg *ActionsOpts
}

type CASBackendItem struct {
ID string `json:"id"`
Name string `json:"name"`
Provider string `json:"provider"`
Default bool `json:"default"`
ValidationStatus ValidationStatus `json:"validationStatus"`

CreatedAt *time.Time `json:"createdAt"`
ValidatedAt *time.Time `json:"validatedAt"`
}

type ValidationStatus string

const (
Valid ValidationStatus = "valid"
Invalid ValidationStatus = "invalid"
)

func NewCASBackendList(cfg *ActionsOpts) *CASBackendList {
return &CASBackendList{cfg}
}

func (action *CASBackendList) Run() ([]*CASBackendItem, error) {
client := pb.NewCASBackendServiceClient(action.cfg.CPConnection)
resp, err := client.List(context.Background(), &pb.CASBackendServiceListRequest{})
if err != nil {
return nil, err
}

result := make([]*CASBackendItem, 0, len(resp.Result))
for _, p := range resp.Result {
result = append(result, pbCASBackendItemToAction(p))
}

return result, nil
}

func pbCASBackendItemToAction(in *pb.CASBackendItem) *CASBackendItem {
if in == nil {
return nil
}

b := &CASBackendItem{
ID: in.Id,
Name: in.Name,
Provider: in.Provider,
Default: in.Default,
CreatedAt: toTimePtr(in.CreatedAt.AsTime()),
ValidatedAt: toTimePtr(in.ValidatedAt.AsTime()),
}

switch in.GetValidationStatus() {
case pb.CASBackendItem_VALIDATION_STATUS_OK:
b.ValidationStatus = Valid
case pb.CASBackendItem_VALIDATION_STATUS_INVALID:
b.ValidationStatus = Invalid
}

return b
}
7 changes: 0 additions & 7 deletions app/cli/internal/action/config_current_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ type ConfigContextItemOCIRepo struct {
ValidationStatus ValidationStatus
}

type ValidationStatus string

const (
Valid ValidationStatus = "valid"
Invalid ValidationStatus = "invalid"
)

func (action *ConfigCurrentContext) Run() (*ConfigContextItem, error) {
client := pb.NewContextServiceClient(action.cfg.CPConnection)
resp, err := client.Current(context.Background(), &pb.ContextServiceCurrentRequest{})
Expand Down
Loading