diff --git a/.golangci.yml b/.golangci.yml index 6e0e9bda..991c601f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -15,4 +15,9 @@ linters: - staticcheck - typecheck - unparam - - unused \ No newline at end of file + - unused + - lll + +linters-settings: + lll: + line-length: 120 \ No newline at end of file diff --git a/client/foundries.go b/client/foundries.go index c2b60497..69c6b101 100644 --- a/client/foundries.go +++ b/client/foundries.go @@ -1201,7 +1201,8 @@ func (a *Api) TufMetadataGet(factory string, metadata string, tag string, prod b return a.Get(url) } -func (a *Api) TufTargetMetadataRefresh(factory string, target string, tag string, expiresIn int, prod bool) (map[string]tuf.Signed, error) { +func (a *Api) TufTargetMetadataRefresh(factory string, target string, tag string, + expiresIn int, prod bool) (map[string]tuf.Signed, error) { url := a.serverUrl + "/ota/factories/" + factory + "/targets/" + target + "/meta/" type targetMeta struct { Tag string `json:"tag"` @@ -1350,7 +1351,8 @@ func (a *Api) TargetDeleteTargets(factory string, target_names []string) (string return parseJobServResponse(resp, err, "UpdateTargets") } -func (a *Api) TargetImageCreate(factory, targetName, appShortlist, ciScriptsRepo, ciScriptsRef string) (string, string, error) { +func (a *Api) TargetImageCreate(factory, targetName, appShortlist, + ciScriptsRepo, ciScriptsRef string) (string, string, error) { url := a.serverUrl + "/ota/factories/" + factory + "/targets/" + targetName + "/images/" url += "?script_repo=" + ciScriptsRepo + "&script_repo_ref=" + ciScriptsRef if len(appShortlist) > 0 { @@ -1389,7 +1391,8 @@ func (a *Api) TargetComposeApp(factory string, targetName string, app string) (* } func (a *Api) TargetDeltasCreate(factory string, toVer int, fromVers []int, hwId string) (string, string, error) { - url := a.serverUrl + "/ota/factories/" + factory + "/targets/" + strconv.Itoa(toVer) + "/static-deltas/" + url := a.serverUrl + "/ota/factories/" + factory + + "/targets/" + strconv.Itoa(toVer) + "/static-deltas/" type payload struct { FromVersions []int `json:"from_versions"` HwId string `json:"hw_id"` @@ -1459,7 +1462,8 @@ func (a *Api) TargetTestResults(factory string, target int, testId string) (*Tar } func (a *Api) TargetTestArtifact(factory string, target int, testId string, artifact string) (*[]byte, error) { - url := a.serverUrl + "/ota/factories/" + factory + "/targets/" + strconv.Itoa(target) + "/testing/" + testId + "/" + artifact + url := a.serverUrl + "/ota/factories/" + factory + "/targets/" + strconv.Itoa(target) + + "/testing/" + testId + "/" + artifact logrus.Debugf("TargetTests with url: %s", url) return a.Get(url) } @@ -1686,7 +1690,8 @@ func (a *Api) FactoryCreateWave(factory string, wave *WaveCreate) error { } func (a *Api) FactoryListWaves(factory string, limit uint64, page int) (*WaveList, error) { - url := a.serverUrl + "/ota/factories/" + factory + "/waves/?limit=" + strconv.FormatUint(limit, 10) + "&page=" + strconv.Itoa(page) + url := a.serverUrl + "/ota/factories/" + factory + + "/waves/?limit=" + strconv.FormatUint(limit, 10) + "&page=" + strconv.Itoa(page) logrus.Debugf("Listing factory waves %s", url) body, err := a.Get(url) diff --git a/client/foundries_el2g.go b/client/foundries_el2g.go index 6e080040..5b2e69c6 100644 --- a/client/foundries_el2g.go +++ b/client/foundries_el2g.go @@ -148,7 +148,8 @@ type El2gProduct struct { } func (a *Api) El2gProductInfo(factory, deviceId string) (El2gProduct, error) { - url := a.serverUrl + "/ota/factories/" + factory + "/el2g-proxy/devices/" + deviceId + "/product" + url := a.serverUrl + "/ota/factories/" + + factory + "/el2g-proxy/devices/" + deviceId + "/product" body, err := a.Get(url) var prod El2gProduct @@ -211,7 +212,8 @@ type El2gSecureObjectProvisioning struct { } func (a *Api) El2gSecureObjectProvisionings(factory, deviceId string) ([]El2gSecureObjectProvisioning, error) { - url := a.serverUrl + "/ota/factories/" + factory + "/el2g-proxy/rtp/devices/" + deviceId + "/secure-object-provisionings" + url := a.serverUrl + "/ota/factories/" + factory + "/el2g-proxy/rtp/devices/" + deviceId + + "/secure-object-provisionings" body, err := a.Get(url) if err != nil { return nil, err diff --git a/client/foundries_sboms.go b/client/foundries_sboms.go index 40ecee0e..7740a449 100644 --- a/client/foundries_sboms.go +++ b/client/foundries_sboms.go @@ -47,7 +47,8 @@ func (p SpdxPackage) License() string { } else if p.LicenseConcluded == "NOASSERTION" { return p.LicenseDeclared } - return fmt.Sprintf("ERROR: Unknown license configuration for package: %s - Concluded(%s) Declared(%s)", p.Name, p.LicenseConcluded, p.LicenseDeclared) + return fmt.Sprintf("ERROR: Unknown license configuration for package: %s - Concluded(%s) Declared(%s)", + p.Name, p.LicenseConcluded, p.LicenseDeclared) } func (a *Api) SbomDownload(factory, targetName, path, contentType string) ([]byte, error) { diff --git a/subcommands/config/rotate_certs.go b/subcommands/config/rotate_certs.go index 3d388910..3155763c 100644 --- a/subcommands/config/rotate_certs.go +++ b/subcommands/config/rotate_certs.go @@ -27,7 +27,8 @@ This command will only work for devices running LmP version 90 and later.`, rotateCmd.Flags().StringP("reason", "r", "", "The reason for changing the cert") rotateCmd.Flags().StringP("hsm-pkey-ids", "", "01,07", "Available PKCS11 slot IDs for the private key") rotateCmd.Flags().StringP("hsm-cert-ids", "", "03,09", "Available PKCS11 slot IDs for the client certificate") - rotateCmd.Flags().StringP("server-name", "", "", "EST server name when not using the Foundries managed server. e.g. est.example.com") + rotateCmd.Flags().StringP("server-name", "", "", + "EST server name when not using the Foundries managed server. e.g. est.example.com") rotateCmd.Flags().BoolP("dryrun", "", false, "Show what the fioconfig entry will be and exit") _ = cmd.MarkFlagRequired("reason") _ = cmd.MarkFlagRequired("group") diff --git a/subcommands/config/set.go b/subcommands/config/set.go index 7fa4611a..e66c712f 100644 --- a/subcommands/config/set.go +++ b/subcommands/config/set.go @@ -61,7 +61,8 @@ create a device group wide configuration instead.`, setCmd.Flags().StringP("group", "g", "", "Device group to use") setCmd.Flags().StringP("reason", "m", "", "Add a message to store as the \"reason\" for this change") setCmd.Flags().BoolP("raw", "", false, "Use raw configuration file") - setCmd.Flags().BoolP("create", "", false, "Replace the whole config with these values. Default is to merge these values in with the existing config values") + setCmd.Flags().BoolP("create", "", false, + "Replace the whole config with these values. Default is to merge these values in with the existing config values") } func doConfigSet(cmd *cobra.Command, args []string) { diff --git a/subcommands/devices/config_rotate_certs.go b/subcommands/devices/config_rotate_certs.go index 4d6aa9d6..9b1af17a 100644 --- a/subcommands/devices/config_rotate_certs.go +++ b/subcommands/devices/config_rotate_certs.go @@ -22,12 +22,16 @@ a certificate rotation using the EST server configured with "fioctl keys est". This command will only work for devices running LmP version 90 and later.`, } - cmd.Flags().StringP("est-resource", "e", "/.well-known/est", "The path the to EST resource on your server") + cmd.Flags().StringP("est-resource", "e", "/.well-known/est", + "The path the to EST resource on your server") cmd.Flags().IntP("est-port", "p", 8443, "The EST server port") cmd.Flags().StringP("reason", "r", "", "The reason for changing the cert") - cmd.Flags().StringP("hsm-pkey-ids", "", "01,07", "Available PKCS11 slot IDs for the private key") - cmd.Flags().StringP("hsm-cert-ids", "", "03,09", "Available PKCS11 slot IDs for the client certificate") - cmd.Flags().StringP("server-name", "", "", "EST server name when not using the Foundries managed server. e.g. est.example.com") + cmd.Flags().StringP("hsm-pkey-ids", "", "01,07", + "Available PKCS11 slot IDs for the private key") + cmd.Flags().StringP("hsm-cert-ids", "", "03,09", + "Available PKCS11 slot IDs for the client certificate") + cmd.Flags().StringP("server-name", "", "", + "EST server name when not using the Foundries managed server. e.g. est.example.com") cmd.Flags().BoolP("dryrun", "", false, "Show what the fioconfig entry will be and exit") configCmd.AddCommand(cmd) _ = cmd.MarkFlagRequired("reason") diff --git a/subcommands/devices/config_set.go b/subcommands/devices/config_set.go index a4a87687..1f467f07 100644 --- a/subcommands/devices/config_set.go +++ b/subcommands/devices/config_set.go @@ -69,7 +69,8 @@ device's configuration and apply it. The maximum size of a config is 1Mb.`, configCmd.AddCommand(setConfigCmd) setConfigCmd.Flags().StringP("reason", "m", "", "Add a message to store as the \"reason\" for this change") setConfigCmd.Flags().BoolP("raw", "", false, "Use raw configuration file") - setConfigCmd.Flags().BoolP("create", "", false, "Replace the whole config with these values. Default is to merge these values in with the existing config values") + setConfigCmd.Flags().BoolP("create", "", false, "Replace the whole config with these values. "+ + "Default is to merge these values in with the existing config values") } func loadEciesPub(pubkey string) *ecies.PublicKey { diff --git a/subcommands/devices/list.go b/subcommands/devices/list.go index 0ccf4ed0..00887e04 100644 --- a/subcommands/devices/list.go +++ b/subcommands/devices/list.go @@ -99,8 +99,10 @@ func addPaginationFlags(cmd *cobra.Command) { limitsStr += strconv.Itoa(limit) } - cmd.Flags().IntVarP(&showPage, "page", "p", 1, "Page of devices to display when pagination is needed") - cmd.Flags().IntVarP(&paginationLimit, "limit", "n", 500, "Number of devices to paginate by. Allowed values: "+limitsStr) + cmd.Flags().IntVarP(&showPage, "page", "p", 1, + "Page of devices to display when pagination is needed") + cmd.Flags().IntVarP(&paginationLimit, "limit", "n", 500, + "Number of devices to paginate by. Allowed values: "+limitsStr) } func addSortFlag(cmd *cobra.Command, flag, short, help string) { @@ -134,18 +136,24 @@ func init() { } sort.Strings(allCols) listCmd := &cobra.Command{ - Use: "list [pattern]", - Short: "List devices registered to factories. Optionally include filepath style patterns to limit to device names. eg device-*", - Run: doList, - Args: cobra.MaximumNArgs(1), - Long: "Available columns for display:\n\n * " + strings.Join(allCols, "\n * "), + Use: "list [pattern]", + Short: "List devices registered to factories. Optionally include filepath style patterns to limit to device " + + "names. eg device-*", + Run: doList, + Args: cobra.MaximumNArgs(1), + Long: "Available columns for display:\n\n * " + strings.Join(allCols, "\n * "), } cmd.AddCommand(listCmd) - listCmd.Flags().BoolVarP(&deviceMine, "just-mine", "", false, "Only include devices owned by you") - listCmd.Flags().StringVarP(&deviceByTag, "by-tag", "", "", "Only list devices configured with the given tag") - listCmd.Flags().StringVarP(&deviceByTarget, "by-target", "", "", "Only list devices updated to the given target name") - listCmd.Flags().StringVarP(&deviceByGroup, "by-group", "g", "", "Only list devices belonging to this group (factory is mandatory)") - listCmd.Flags().IntVarP(&deviceInactiveHours, "offline-threshold", "", 4, "List the device as 'OFFLINE' if not seen in the last X hours") + listCmd.Flags().BoolVarP(&deviceMine, "just-mine", "", false, + "Only include devices owned by you") + listCmd.Flags().StringVarP(&deviceByTag, "by-tag", "", "", + "Only list devices configured with the given tag") + listCmd.Flags().StringVarP(&deviceByTarget, "by-target", "", "", + "Only list devices updated to the given target name") + listCmd.Flags().StringVarP(&deviceByGroup, "by-group", "g", "", + "Only list devices belonging to this group (factory is mandatory)") + listCmd.Flags().IntVarP(&deviceInactiveHours, "offline-threshold", "", 4, + "List the device as 'OFFLINE' if not seen in the last X hours") listCmd.Flags().StringVarP(&deviceUuid, "uuid", "", "", "Find device with the given UUID") listCmd.Flags().StringSliceVarP(&showColumns, "columns", "", defCols, "Specify which columns to display") addPaginationFlags(listCmd) diff --git a/subcommands/docker/cmd.go b/subcommands/docker/cmd.go index dc99d2cc..1856ffc6 100644 --- a/subcommands/docker/cmd.go +++ b/subcommands/docker/cmd.go @@ -127,7 +127,8 @@ func doDockerCreds(cmd *cobra.Command, args []string) { func RunCredsHelper() int { if subcommands.Config.ClientCredentials.ClientSecret == "" { - msg := "ERROR: Your fioctl configuration does not appear to include oauth2 credentials. Please run `fioctl login` to configure and then try again.\n" + msg := "ERROR: Your fioctl configuration does not appear to include oauth2 credentials. " + + "Please run `fioctl login` to configure and then try again.\n" os.Stderr.WriteString(msg) os.Exit(1) } diff --git a/subcommands/git/cmd.go b/subcommands/git/cmd.go index 7046e257..4102f8c6 100644 --- a/subcommands/git/cmd.go +++ b/subcommands/git/cmd.go @@ -43,7 +43,8 @@ NOTE: The credentials will need the "source:read-update" scope to work with Git` subcommands.DieNotNil(err, "Git not found on system") }, } - cmd.Flags().StringVarP(&helperPath, "creds-path", "", helperPath, "Path to install credential helper. This needs to be writable and in $PATH") + cmd.Flags().StringVarP(&helperPath, "creds-path", "", helperPath, "Path to install credential "+ + "helper. This needs to be writable and in $PATH") if len(helperPath) == 0 { _ = cmd.MarkFlagRequired("creds-path") } @@ -84,12 +85,16 @@ func doGitCreds(cmd *cobra.Command, args []string) { u, err := user.Lookup(sudoer) subcommands.DieNotNil(err) execCommand = "su" - gitUsernameCommandArgs = []string{u.Username, "-c", "git config --global credential.https://source.foundries.io.username fio-oauth2"} - gitHelperCommandArgs = []string{u.Username, "-c", "git config --global credential.https://source.foundries.io.helper " + helperName} + gitUsernameCommandArgs = []string{u.Username, "-c", "git config --global " + + "credential.https://source.foundries.io.username fio-oauth2"} + gitHelperCommandArgs = []string{u.Username, "-c", "git config --global " + + "credential.https://source.foundries.io.helper " + helperName} } else { execCommand = "git" - gitUsernameCommandArgs = []string{"config", "--global", "credential.https://source.foundries.io.username", "fio-oauth2"} - gitHelperCommandArgs = []string{"config", "--global", "credential.https://source.foundries.io.helper", helperName} + gitUsernameCommandArgs = []string{"config", "--global", + "credential.https://source.foundries.io.username", "fio-oauth2"} + gitHelperCommandArgs = []string{"config", "--global", + "credential.https://source.foundries.io.helper", helperName} } c := exec.Command(execCommand, gitUsernameCommandArgs...) out, err := c.CombinedOutput() @@ -110,7 +115,9 @@ func doGitCreds(cmd *cobra.Command, args []string) { func RunCredsHelper() int { if subcommands.Config.ClientCredentials.ClientSecret == "" { - msg := "ERROR: Your fioctl configuration does not appear to include oauth2 credentials. Please run `fioctl login` to configure and then try again.\n" + msg := "ERROR: Your fioctl configuration " + + "does not appear to include oauth2 credentials. " + + "Please run `fioctl login` to configure and then try again.\n" os.Stderr.WriteString(msg) os.Exit(1) } diff --git a/subcommands/keys/ca_create.go b/subcommands/keys/ca_create.go index 06a4183a..81148bf5 100644 --- a/subcommands/keys/ca_create.go +++ b/subcommands/keys/ca_create.go @@ -56,11 +56,14 @@ keypair. This is optional.`, } caCmd.AddCommand(cmd) - cmd.Flags().BoolVarP(&createOnlineCA, "online-ca", "", true, "Create an online CA owned by Foundries that works with lmp-device-register") - cmd.Flags().BoolVarP(&createLocalCA, "local-ca", "", true, "Create a local CA that you can use for signing your own device certificates") + cmd.Flags().BoolVarP(&createOnlineCA, "online-ca", "", true, + "Create an online CA owned by Foundries that works with lmp-device-register") + cmd.Flags().BoolVarP(&createLocalCA, "local-ca", "", true, + "Create a local CA that you can use for signing your own device certificates") cmd.Flags().StringVarP(&hsmModule, "hsm-module", "", "", "Create key on an PKCS#11 compatible HSM using this module") cmd.Flags().StringVarP(&hsmPin, "hsm-pin", "", "", "The PKCS#11 PIN to set up on the HSM, if using one") - cmd.Flags().StringVarP(&hsmTokenLabel, "hsm-token-label", "", "device-gateway-root", "The label of the HSM token created for this") + cmd.Flags().StringVarP(&hsmTokenLabel, "hsm-token-label", "", "device-gateway-root", + "The label of the HSM token created for this") } func writeFile(filename, contents string, mode os.FileMode) { diff --git a/subcommands/keys/tuf_rotate_all_keys.go b/subcommands/keys/tuf_rotate_all_keys.go index 12cb17a6..c307d8b3 100644 --- a/subcommands/keys/tuf_rotate_all_keys.go +++ b/subcommands/keys/tuf_rotate_all_keys.go @@ -34,11 +34,14 @@ Migrate an old factory to use Ed25519 key type for all TUF signing keys (online rotate.Flags().StringP("keys", "k", "", "Path to used to sign TUF root.") _ = rotate.MarkFlagRequired("keys") _ = rotate.MarkFlagFilename("keys") - rotate.Flags().StringP("targets-keys", "K", "", "Path to used to sign prod & wave TUF targets.") + rotate.Flags().StringP("targets-keys", "K", "", + "Path to used to sign prod & wave TUF targets.") _ = rotate.MarkFlagFilename("targets-keys") - rotate.Flags().BoolP("first-time", "", false, "Used for the first customer rotation. The command will download the initial root key.") + rotate.Flags().BoolP("first-time", "", false, + "Used for the first customer rotation. The command will download the initial root key.") rotate.Flags().StringP("key-type", "y", tufKeyTypeNameEd25519, "Key type, supported: Ed25519, RSA.") - rotate.Flags().StringP("changelog", "m", "", "Reason for doing rotation. Saved in root metadata for tracking change history.") + rotate.Flags().StringP("changelog", "m", "", + "Reason for doing rotation. Saved in root metadata for tracking change history.") tufCmd.AddCommand(rotate) } diff --git a/subcommands/keys/tuf_rotate_offline_key.go b/subcommands/keys/tuf_rotate_offline_key.go index 4859c5ff..31c04ce3 100644 --- a/subcommands/keys/tuf_rotate_offline_key.go +++ b/subcommands/keys/tuf_rotate_offline_key.go @@ -45,11 +45,14 @@ When you rotate the TUF targets offline signing key: rotate.Flags().StringP("keys", "k", "", "Path to used to sign TUF root.") _ = rotate.MarkFlagRequired("keys") _ = rotate.MarkFlagFilename("keys") - rotate.Flags().StringP("targets-keys", "K", "", "Path to used to sign prod & wave TUF targets.") + rotate.Flags().StringP("targets-keys", "K", "", + "Path to used to sign prod & wave TUF targets.") _ = rotate.MarkFlagFilename("targets-keys") - rotate.Flags().BoolP("first-time", "", false, "Used for the first customer rotation. The command will download the initial root key.") + rotate.Flags().BoolP("first-time", "", false, "Used for the first customer rotation. "+ + "The command will download the initial root key.") rotate.Flags().StringP("key-type", "y", tufKeyTypeNameEd25519, "Key type, supported: Ed25519, RSA.") - rotate.Flags().StringP("changelog", "m", "", "Reason for doing rotation. Saved in root metadata for tracking change history.") + rotate.Flags().StringP("changelog", "m", "", "Reason for doing rotation. "+ + "Saved in root metadata for tracking change history.") tufCmd.AddCommand(rotate) legacyRotateRoot := &cobra.Command{ @@ -65,9 +68,12 @@ Instead, please, use a new approach to rotate TUF root key: Annotations: map[string]string{tufCmdAnnotation: tufCmdRotateRootLegacy}, Args: cobra.ExactArgs(1), } - legacyRotateRoot.Flags().BoolP("initial", "", false, "Used for the first customer rotation. The command will download the initial root key") - legacyRotateRoot.Flags().StringP("changelog", "m", "", "Reason for doing rotation. Saved in root metadata for tracking change history") - legacyRotateRoot.Flags().StringP("key-type", "y", tufKeyTypeNameEd25519, "Key type, supported: Ed25519, RSA.") + legacyRotateRoot.Flags().BoolP("initial", "", false, + "Used for the first customer rotation. The command will download the initial root key") + legacyRotateRoot.Flags().StringP("changelog", "m", "", + "Reason for doing rotation. Saved in root metadata for tracking change history") + legacyRotateRoot.Flags().StringP("key-type", "y", tufKeyTypeNameEd25519, + "Key type, supported: Ed25519, RSA.") cmd.AddCommand(legacyRotateRoot) legacyRotateTargets := &cobra.Command{ @@ -88,7 +94,8 @@ Instead, please, use a new approach to rotate TUF targets key: Args: cobra.ExactArgs(1), } legacyRotateTargets.Flags().StringP("key-type", "y", tufKeyTypeNameEd25519, "Key type, supported: Ed25519, RSA.") - legacyRotateTargets.Flags().StringP("changelog", "m", "", "Reason for doing rotation. Saved in root metadata for tracking change history.") + legacyRotateTargets.Flags().StringP("changelog", "m", "", + "Reason for doing rotation. Saved in root metadata for tracking change history.") cmd.AddCommand(legacyRotateTargets) } diff --git a/subcommands/keys/tuf_updates_init.go b/subcommands/keys/tuf_updates_init.go index beee7a8a..a68a96a6 100644 --- a/subcommands/keys/tuf_updates_init.go +++ b/subcommands/keys/tuf_updates_init.go @@ -17,9 +17,11 @@ func init() { Short: "Start a new transaction to update TUF root keys", Run: doTufUpdatesInit, } - initCmd.Flags().StringP("changelog", "m", "", "Reason for doing this operation. Saved in root metadata to track change history.") + initCmd.Flags().StringP("changelog", "m", "", + "Reason for doing this operation. Saved in root metadata to track change history.") _ = initCmd.MarkFlagRequired("changelog") - initCmd.Flags().BoolP("first-time", "", false, "Used for the first customer rotation. The command will download the initial root key.") + initCmd.Flags().BoolP("first-time", "", false, + "Used for the first customer rotation. The command will download the initial root key.") initCmd.Flags().StringP("keys", "k", "", "Path to used to store initial root key.") _ = initCmd.MarkFlagFilename("keys") initCmd.MarkFlagsRequiredTogether("first-time", "keys") diff --git a/subcommands/keys/tuf_utils.go b/subcommands/keys/tuf_utils.go index 4b234d8c..c437b9e5 100644 --- a/subcommands/keys/tuf_utils.go +++ b/subcommands/keys/tuf_utils.go @@ -61,6 +61,7 @@ func ParseTufRoleNameOnline(s string) string { } func genTufKeyId(key crypto.Signer) string { + // nolint:lll // # This has to match the exact logic used by ota-tuf (required by garage-sign): // https://github.com/foundriesio/ota-tuf/blob/fio-changes/libtuf/src/main/scala/com/advancedtelematic/libtuf/crypt/TufCrypto.scala#L66-L71 // It sets a keyid to a signature of the key's canonical DER encoding (same logic for all keys). diff --git a/subcommands/login/cmd.go b/subcommands/login/cmd.go index e703fb9b..d9cc5132 100644 --- a/subcommands/login/cmd.go +++ b/subcommands/login/cmd.go @@ -27,9 +27,13 @@ func NewCommand() *cobra.Command { Short: "Access Foundries.io services with your client credentials", Run: doLogin, } - cmd.Flags().BoolVarP(&refreshToken, "refresh-access-token", "", false, "Refresh your current oauth2 access token. This is used when a token's scopes have been updated in app.foundries.io") - cmd.Flags().StringVarP(&authURL, "oauth-url", "", client.OauthURL, "OAuth URL to authenticate with") - cmd.Flags().BoolVarP(&insecure, "insecure-ssl", "", false, "Ignore TLS certificates from API servers.") + cmd.Flags().BoolVarP(&refreshToken, "refresh-access-token", "", false, + "Refresh your current oauth2 access token. This is used when a token's scopes have been "+ + "updated in app.foundries.io") + cmd.Flags().StringVarP(&authURL, "oauth-url", "", client.OauthURL, + "OAuth URL to authenticate with") + cmd.Flags().BoolVarP(&insecure, "insecure-ssl", "", false, + "Ignore TLS certificates from API servers.") _ = cmd.Flags().MarkHidden("insecure-ssl") return cmd } diff --git a/subcommands/status/cmd.go b/subcommands/status/cmd.go index 2dd3bea2..20d273bb 100644 --- a/subcommands/status/cmd.go +++ b/subcommands/status/cmd.go @@ -25,7 +25,8 @@ func NewCommand() *cobra.Command { }, } subcommands.RequireFactory(cmd) - cmd.Flags().IntVarP(&inactiveThreshold, "offline-threshold", "", 4, "Consider device 'OFFLINE' if not seen in the last X hours") + cmd.Flags().IntVarP(&inactiveThreshold, "offline-threshold", "", 4, + "Consider device 'OFFLINE' if not seen in the last X hours") return cmd } diff --git a/subcommands/targets/add.go b/subcommands/targets/add.go index 0d7a5703..ba7aa7b2 100644 --- a/subcommands/targets/add.go +++ b/subcommands/targets/add.go @@ -27,12 +27,14 @@ func init() { Use: "add", Short: "Compose and add Targets to Factory's TUF targets metadata", Run: doAdd, + //nolint:lll Long: ` Compose new Targets out of the latest Targets tagged with the specified source tag and the specified via the command arguments either OSTree commit hashes or App URIs. fioctl targets add --type --tags --src-tag [--targets-creator ]\ [ ] (for ostree type) [App #N URI] (for app type)`, + // nolint:lll Example: ` Add new ostree Targets: fioctl targets add --type ostree --tags dev,test --src-tag dev --targets-creator "custom jenkins ostree build" intel-corei7-64 00b2ad4a1dd7fe1e856a6d607ed492c354a423be22a44bad644092bb275e12fa raspberrypi4-64 5e05a59529dcdd54310945b2628d73c0533097d76cc483334925a901845b3794 @@ -47,7 +49,8 @@ Add new App Targets: addCmd.Flags().StringVarP(&addSrcTag, "src-tag", "", "", "OSTree Target tag to base app targets on") addCmd.Flags().BoolVarP(&addQuiet, "quiet", "", false, "don't print generated new Targets to stdout") addCmd.Flags().BoolVarP(&addDryRun, "dry-run", "", false, "don't post generated new Targets") - addCmd.Flags().StringVarP(&addTargetsCreator, "targets-creator", "", "fioctl", "optional name/comment/context about Targets origination") + addCmd.Flags().StringVarP(&addTargetsCreator, "targets-creator", "", "fioctl", + "optional name/comment/context about Targets origination") } func doAdd(cmd *cobra.Command, args []string) { @@ -100,7 +103,8 @@ func createAppTargets(factory string, tags []string, srcTag string, appUris []st newTargetApps[appName] = composeApp } // TBC: - // 1. Parse App manifests to determine supported platforms/archs, map it to hardware IDs and pass them as an input param to `deriveTargets` + // 1. Parse App manifests to determine supported platforms/archs, map it to hardware IDs and pass them as an + // input param to `deriveTargets` // 2. Add CLI param `hw-ids` to shortlist by hardware IDs when new App Targets are being added, // instead of generating Targets for each hardware ID of the specified source tag. return deriveTargets(factory, nil, srcTag, func(target *client.Target) error { @@ -137,7 +141,8 @@ func createOstreeTarget(factory string, tags []string, srcTag string, hwIdToHash }) } -func deriveTargets(factory string, hwIds map[string]interface{}, srcTag string, customizeFunc func(target *client.Target) error) (Targets, error) { +func deriveTargets(factory string, hwIds map[string]interface{}, srcTag string, + customizeFunc func(target *client.Target) error) (Targets, error) { latestBuild, err := api.JobservLatestBuild(factory, false) subcommands.DieNotNil(err) @@ -161,7 +166,8 @@ func deriveTargets(factory string, hwIds map[string]interface{}, srcTag string, continue } } - if latestTargetForSrcTag, exists := latestTargetsPerHwId[curTargetHwId]; !exists || latestTargetForSrcTag.Version() < curVer { + if latestTargetForSrcTag, exists := latestTargetsPerHwId[curTargetHwId]; !exists || + latestTargetForSrcTag.Version() < curVer { latestTargetsPerHwId[curTargetHwId] = target } } diff --git a/subcommands/targets/image.go b/subcommands/targets/image.go index 2972475e..62766a70 100644 --- a/subcommands/targets/image.go +++ b/subcommands/targets/image.go @@ -33,8 +33,11 @@ func init() { "comma,separate,list of Target apps to preload into a resultant image."+ " All apps of Target are preloaded if the flag is not defined or empty") imageCmd.Flags().BoolVarP(&noTail, "no-tail", "", false, "Don't tail output of CI Job") - imageCmd.Flags().StringVarP(&ciScriptsRepo, "ci-scripts-repo", "", "https://github.com/foundriesio/ci-scripts", "Override to custom version of ci-scripts") - imageCmd.Flags().StringVarP(&ciScriptsRef, "ci-scripts-ref", "", "master", "Override to a specific git-ref of ci-scripts") + imageCmd.Flags().StringVarP(&ciScriptsRepo, "ci-scripts-repo", "", + "https://github.com/foundriesio/ci-scripts", + "Override to custom version of ci-scripts") + imageCmd.Flags().StringVarP(&ciScriptsRef, "ci-scripts-ref", "", "master", + "Override to a specific git-ref of ci-scripts") } func validateAppShortlist() { diff --git a/subcommands/targets/offline-update.go b/subcommands/targets/offline-update.go index 40584133..c231ba36 100644 --- a/subcommands/targets/offline-update.go +++ b/subcommands/targets/offline-update.go @@ -41,6 +41,7 @@ func init() { Short: "Download Target content for an offline update", Run: doOfflineUpdate, Args: cobra.ExactArgs(2), + // nolint:lll Example: ` # Download update content of the production target #1451 tagged by "release-01" for "intel-corei7-64" hardware type fioctl targets offline-update intel-corei7-64-lmp-1451 /mnt/flash-drive/offline-update-content --tag release-01 --prod @@ -79,17 +80,21 @@ func doOfflineUpdate(cmd *cobra.Command, args []string) { subcommands.DieNotNil(err, "Failed to obtain Target's details:") fmt.Printf("Refreshing and downloading TUF metadata for Target %s to %s...\n", targetName, path.Join(dstDir, "tuf")) - subcommands.DieNotNil(downloadTufRepo(factory, targetName, ouTag, ouProd, ouExpiresIn, path.Join(dstDir, "tuf")), "Failed to download TUF metadata:") + subcommands.DieNotNil(downloadTufRepo(factory, targetName, ouTag, ouProd, ouExpiresIn, path.Join(dstDir, "tuf")), + "Failed to download TUF metadata:") fmt.Println("Successfully refreshed and downloaded TUF metadata") if !ouTufOnly { fmt.Printf("Downloading an ostree repo from the Target's OE build %d...\n", ti.ostreeVersion) - subcommands.DieNotNil(downloadOstree(factory, ti.ostreeVersion, ti.hardwareID, dstDir), "Failed to download Target's ostree repo:") + subcommands.DieNotNil(downloadOstree(factory, ti.ostreeVersion, ti.hardwareID, dstDir), + "Failed to download Target's ostree repo:") if !ouNoApps { - fmt.Printf("Downloading Apps fetched by the `assemble-system-image` run; build number: %d, tag: %s...\n", ti.version, ti.buildTag) + fmt.Printf("Downloading Apps fetched by the `assemble-system-image` run; build number: %d, tag: %s...\n", + ti.version, ti.buildTag) err = downloadApps(factory, targetName, ti.version, ti.buildTag, path.Join(dstDir, "apps")) if herr := client.AsHttpError(err); herr != nil && herr.Response.StatusCode == 404 { - fmt.Println("WARNING: The Target Apps were not fetched by the `assemble` run, make sure that App preloading is enabled if needed. The update won't include any Apps!") + fmt.Println("WARNING: The Target Apps were not fetched by the `assemble` run, make sure that " + + "App preloading is enabled if needed. The update won't include any Apps!") } else { subcommands.DieNotNil(err, "Failed to download Target's Apps:") } @@ -102,7 +107,8 @@ func checkIfTargetExists(factory string, targetName string, tag string, prod boo data, err := api.TufMetadataGet(factory, "targets.json", tag, prod) if err != nil { if herr := client.AsHttpError(err); herr != nil && herr.Response.StatusCode == 404 { - return fmt.Errorf("the specified Target has not been found; target: %s, tag: %s, production: %v", targetName, ouTag, ouProd) + return fmt.Errorf("the specified Target has not been found; target: %s, tag: %s, production: %v", + targetName, ouTag, ouProd) } return fmt.Errorf("failed to check whether Target exists: %s", err.Error()) } @@ -116,7 +122,8 @@ func checkIfTargetExists(factory string, targetName string, tag string, prod boo return nil } } - return fmt.Errorf("the specified Target has not been found; target: %s, tag: %s, production: %v", targetName, ouTag, ouProd) + return fmt.Errorf("the specified Target has not been found; target: %s, tag: %s, production: %v", + targetName, ouTag, ouProd) } func getTargetInfo(factory string, targetName string) (*ouTargetInfo, error) { @@ -135,6 +142,7 @@ func getTargetInfo(factory string, targetName string) (*ouTargetInfo, error) { return nil, err } info.hardwareID = custom.HardwareIds[0] + // nolint:lll info.buildTag = custom.Tags[0] // See the assemble.py script in ci-scripts https://github.com/foundriesio/ci-scripts/blob/18b4fb154c37b6ad1bc6e7b7903a540b7a758f5d/assemble.py#L300 info.ostreeVersion = info.version if len(custom.OrigUri) > 0 { @@ -240,14 +248,16 @@ func getTargetCustomInfo(factory string, targetName string) (*client.TufCustom, return custom, err } -func downloadItem(factory string, targetVer int, runName string, artifactPath string, storeHandler func(r io.Reader) error) error { +func downloadItem(factory string, targetVer int, runName string, artifactPath string, + storeHandler func(r io.Reader) error) error { resp, err := api.JobservRunArtifact(factory, targetVer, runName, artifactPath) if err != nil { return err } if resp.StatusCode < 200 || resp.StatusCode >= 300 { return &client.HttpError{ - Message: fmt.Sprintf("failed to download a CI artifact; status code: %d, artifact: %s", resp.StatusCode, artifactPath), + Message: fmt.Sprintf("failed to download a CI artifact; status code: %d, artifact: %s", + resp.StatusCode, artifactPath), Response: resp, } } diff --git a/subcommands/targets/show.go b/subcommands/targets/show.go index 11422161..5d6da31f 100644 --- a/subcommands/targets/show.go +++ b/subcommands/targets/show.go @@ -133,13 +133,16 @@ func doShow(cmd *cobra.Command, args []string) { fmt.Println() fmt.Println("\tSource:") if len(target.LmpManifestSha) > 0 { - fmt.Printf("\t\thttps://source.foundries.io/factories/%s/lmp-manifest.git/commit/?id=%s\n", factory, target.LmpManifestSha) + fmt.Printf("\t\thttps://source.foundries.io/factories/%s/lmp-manifest.git/commit/?id=%s\n", + factory, target.LmpManifestSha) } if len(target.OverridesSha) > 0 { - fmt.Printf("\t\thttps://source.foundries.io/factories/%s/meta-subscriber-overrides.git/commit/?id=%s\n", factory, target.OverridesSha) + fmt.Printf("\t\thttps://source.foundries.io/factories/%s/meta-subscriber-overrides.git/commit/?id=%s\n", + factory, target.OverridesSha) } if len(target.ContainersSha) > 0 { - fmt.Printf("\t\thttps://source.foundries.io/factories/%s/containers.git/commit/?id=%s\n", factory, target.ContainersSha) + fmt.Printf("\t\thttps://source.foundries.io/factories/%s/containers.git/commit/?id=%s\n", + factory, target.ContainersSha) } fmt.Println() t := subcommands.Tabby(1, "APP", "HASH") @@ -209,7 +212,8 @@ func doShowComposeApp(cmd *cobra.Command, args []string) { } } -func getTargets(factory string, prodTag string, version string) ([]string, map[string]string, map[string]client.TufCustom) { +func getTargets(factory string, prodTag string, version string) ([]string, map[string]string, + map[string]client.TufCustom) { var targets tuf.Files var prodMeta *client.AtsTufTargets diff --git a/subcommands/targets/tag.go b/subcommands/targets/tag.go index d3c7fb4c..c915050d 100644 --- a/subcommands/targets/tag.go +++ b/subcommands/targets/tag.go @@ -36,7 +36,8 @@ func init() { tagCmd.Flags().StringVarP(&tagTags, "tags", "T", "", "comma,separate,list") tagCmd.Flags().BoolVarP(&tagAppend, "append", "", false, "Append the given tags rather than set them") tagCmd.Flags().BoolVarP(&tagNoTail, "no-tail", "", false, "Don't tail output of CI Job") - tagCmd.Flags().BoolVarP(&tagByVersion, "by-version", "", false, "Apply tags to all targets matching the given version(s)") + tagCmd.Flags().BoolVarP(&tagByVersion, "by-version", "", false, + "Apply tags to all targets matching the given version(s)") tagCmd.Flags().BoolVarP(&dryRun, "dryrun", "", false, "Just show the changes that would be applied") } diff --git a/subcommands/version/cmd.go b/subcommands/version/cmd.go index dcf66a46..4722e4ed 100644 --- a/subcommands/version/cmd.go +++ b/subcommands/version/cmd.go @@ -38,7 +38,8 @@ func doVersion(cmd *cobra.Command, args []string) { } if err := update.Do(); err != nil { if os.IsPermission(err) { - DieNotNil(fmt.Errorf("there was a permission error while updating fioctl: %w. Please run again as an admin or root.", err)) + DieNotNil(fmt.Errorf("there was a permission error while updating fioctl: %w. "+ + "Please run again as an admin or root.", err)) } else { DieNotNil(err) } diff --git a/subcommands/waves/init.go b/subcommands/waves/init.go index 0bab2f07..ef7da885 100644 --- a/subcommands/waves/init.go +++ b/subcommands/waves/init.go @@ -46,11 +46,15 @@ The same expiration will be used for production targets when a wave is complete. The same expiration will be used for production targets when a wave is complete. When set this value overrides an 'expires-days' argument. Example: 2020-01-01T00:00:00Z`) - initCmd.Flags().BoolP("dry-run", "d", false, "Don't create a wave, print it to standard output.") - initCmd.Flags().StringSlice("prune", []string{}, `Prune old unused Target(s) from the production metadata. + initCmd.Flags().BoolP("dry-run", "d", false, + "Don't create a wave, print it to standard output.") + initCmd.Flags().StringSlice("prune", []string{}, + `Prune old unused Target(s) from the production metadata. Example: 1,2,3`) - initCmd.Flags().StringP("keys", "k", "", "Path to used to sign wave targets.") - initCmd.Flags().StringP("source-tag", "", "", "Match this tag when looking for target versions. Certain advanced tagging configurations may require this argument.") + initCmd.Flags().StringP("keys", "k", "", + "Path to used to sign wave targets.") + initCmd.Flags().StringP("source-tag", "", "", + "Match this tag when looking for target versions. Certain advanced tagging configurations may require this argument.") _ = initCmd.MarkFlagRequired("keys") } @@ -164,7 +168,8 @@ func pruneTargets(currentTargets *client.AtsTargetsMeta, versions []string) clie } } if len(missing) > 0 { - subcommands.DieNotNil(fmt.Errorf(""), fmt.Sprintf("Unable to prune following versions: %s", strings.Join(missing, ","))) + subcommands.DieNotNil(fmt.Errorf(""), + fmt.Sprintf("Unable to prune following versions: %s", strings.Join(missing, ","))) } return *currentTargets