Files
probo/pkg/cmd/risk/update/update.go
Cursor Agent e5c7cf9b9c Rename Inherent to Initial in risk module UI
Several risk views already used "Initial" while others still showed
"Inherent". Align user-facing labels across the console, shared UI
components, CLI help, n8n fields, generated documents, and MCP
descriptions. API and database field names are unchanged.

Signed-off-by: Cursor Agent <cursoragent@cursor.com>

Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
2026-07-20 12:06:46 +02:00

187 lines
5.0 KiB
Go

// Copyright (c) 2026 Probo Inc <hello@probo.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
package update
import (
"encoding/json"
"fmt"
"github.com/spf13/cobra"
"go.probo.inc/probo/pkg/cli/api"
"go.probo.inc/probo/pkg/cmd/cmdutil"
)
const updateMutation = `
mutation($input: UpdateRiskInput!) {
updateRisk(input: $input) {
risk {
id
name
category
treatment
inherentRiskScore
residualRiskScore
}
}
}
`
type updateResponse struct {
UpdateRisk struct {
Risk struct {
ID string `json:"id"`
Name string `json:"name"`
Category string `json:"category"`
Treatment string `json:"treatment"`
InherentRiskScore int `json:"inherentRiskScore"`
ResidualRiskScore int `json:"residualRiskScore"`
} `json:"risk"`
} `json:"updateRisk"`
}
func NewCmdUpdate(f *cmdutil.Factory) *cobra.Command {
var (
flagName string
flagCategory string
flagTreatment string
flagInherentLikelihood int
flagInherentImpact int
flagResidualLikelihood int
flagResidualImpact int
flagDescription string
flagNote string
flagOwner string
)
cmd := &cobra.Command{
Use: "update <id>",
Short: "Update a risk",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := f.Config()
if err != nil {
return err
}
host, hc, err := cfg.DefaultHost()
if err != nil {
return err
}
client := api.NewClient(
host,
hc.Token,
"/api/console/v1/graphql",
cfg.HTTPTimeoutDuration(),
cmdutil.TokenRefreshOption(cfg, host, hc),
)
input := map[string]any{
"id": args[0],
}
if cmd.Flags().Changed("name") {
input["name"] = flagName
}
if cmd.Flags().Changed("category") {
input["category"] = flagCategory
}
if cmd.Flags().Changed("treatment") {
input["treatment"] = flagTreatment
}
if cmd.Flags().Changed("inherent-likelihood") {
input["inherentLikelihood"] = flagInherentLikelihood
}
if cmd.Flags().Changed("inherent-impact") {
input["inherentImpact"] = flagInherentImpact
}
if cmd.Flags().Changed("residual-likelihood") {
input["residualLikelihood"] = flagResidualLikelihood
}
if cmd.Flags().Changed("residual-impact") {
input["residualImpact"] = flagResidualImpact
}
if cmd.Flags().Changed("description") {
input["description"] = flagDescription
}
if cmd.Flags().Changed("note") {
input["note"] = flagNote
}
if cmd.Flags().Changed("owner") {
if flagOwner == "" {
input["ownerId"] = nil
} else {
input["ownerId"] = flagOwner
}
}
if len(input) == 1 {
return fmt.Errorf("at least one field must be specified for update")
}
data, err := client.Do(
updateMutation,
map[string]any{"input": input},
)
if err != nil {
return err
}
var resp updateResponse
if err := json.Unmarshal(data, &resp); err != nil {
return fmt.Errorf("cannot parse response: %w", err)
}
r := resp.UpdateRisk.Risk
_, _ = fmt.Fprintf(
f.IOStreams.Out,
"Updated risk %s (%s)\n",
r.ID,
r.Name,
)
return nil
},
}
cmd.Flags().StringVar(&flagName, "name", "", "Risk name")
cmd.Flags().StringVar(&flagCategory, "category", "", "Risk category")
cmd.Flags().StringVar(&flagTreatment, "treatment", "", "Risk treatment: MITIGATED, ACCEPTED, AVOIDED, TRANSFERRED")
cmd.Flags().IntVar(&flagInherentLikelihood, "inherent-likelihood", 0, "Initial likelihood 1-5")
cmd.Flags().IntVar(&flagInherentImpact, "inherent-impact", 0, "Initial impact 1-5")
cmd.Flags().IntVar(&flagResidualLikelihood, "residual-likelihood", 0, "Residual likelihood 1-5")
cmd.Flags().IntVar(&flagResidualImpact, "residual-impact", 0, "Residual impact 1-5")
cmd.Flags().StringVar(&flagDescription, "description", "", "Risk description")
cmd.Flags().StringVar(&flagNote, "note", "", "Risk note")
cmd.Flags().StringVar(&flagOwner, "owner", "", "Owner profile ID")
return cmd
}