MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / NewRootCmd

Function NewRootCmd

app/cli/cmd/root.go:95–304  ·  view source on GitHub ↗
(l zerolog.Logger)

Source from the content-addressed store, hash-verified

93}
94
95func NewRootCmd(l zerolog.Logger) *cobra.Command {
96 rootCmd := &cobra.Command{
97 Use: appName,
98 Short: "Chainloop Command Line Interface",
99 SilenceErrors: true,
100 SilenceUsage: true,
101 PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
102 var err error
103 logger, err = initLogger(l)
104 if err != nil {
105 return err
106 }
107
108 logger.Debug().Str("path", viper.ConfigFileUsed()).Msg("using config file")
109
110 // Commands annotated with skipActionOptsInit don't need ActionOpts initialization
111 // These are local-only commands that don't interact with the control plane
112 if cmd.Annotations[skipActionOptsInit] == trueString {
113 return nil
114 }
115
116 if apiInsecure() {
117 logger.Warn().Msg("API contacted in insecure mode")
118 }
119
120 authToken, isUserToken, err := loadAuthToken(cmd)
121 if err != nil {
122 return err
123 }
124
125 // If the auth token is not set and the command supports federated auth, we try to discover the runner and use the federated token for the runner if available
126 if authToken == "" && cmdSupportsFederatedAuth(cmd) {
127 r := crafter.DiscoverRunner(authToken, logger)
128 if r.IsAuthenticated() && r.FederatedToken() != "" {
129 logger.Debug().Str("runner", r.ID().String()).Msg("using federated auth token")
130 authToken = r.FederatedToken()
131 // reset isUserToken to false because we are using a federated token and we don't want to ask for confirmation
132 isUserToken = false
133 }
134 }
135
136 var opts = []grpcconn.Option{
137 grpcconn.WithInsecure(apiInsecure()),
138 grpcconn.WithCLIVersion(fullVersion()),
139 }
140
141 if maxRecv := apiMaxRecvMsgSize(); maxRecv > 0 {
142 opts = append(opts, grpcconn.WithMaxRecvMsgSize(maxRecv))
143 }
144
145 if caValue := viper.GetString(confOptions.controlplaneCA.viperKey); caValue != "" {
146 // Check if the value is a file path, if it is we read the content and encode it to base64, if not we assume it's the content already
147 if _, err := os.Stat(caValue); err == nil {
148 opts = append(opts, grpcconn.WithCAFile(caValue))
149 } else {
150 opts = append(opts, grpcconn.WithCAContent(caValue))
151 }
152 }

Callers 2

mainFunction · 0.92
mainFunction · 0.92

Calls 15

DiscoverRunnerFunction · 0.92
WithInsecureFunction · 0.92
WithCLIVersionFunction · 0.92
WithMaxRecvMsgSizeFunction · 0.92
WithCAFileFunction · 0.92
WithCAContentFunction · 0.92
NewFunction · 0.92
NewConfigCurrentContextFunction · 0.92
WithOrgNameFunction · 0.92
RegisterDiscoverBuiltinFunction · 0.92
ParseFunction · 0.92
NewManagerFunction · 0.92

Tested by

no test coverage detected