Skip to content

Commit

Permalink
(chore): Add max lll = 120 linter check and fix issues
Browse files Browse the repository at this point in the history
Signed-off-by: Camila Macedo <[email protected]>
  • Loading branch information
Camila Macedo committed Sep 28, 2023
1 parent 3d5d748 commit 97e96f0
Show file tree
Hide file tree
Showing 25 changed files with 165 additions and 78 deletions.
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ linters:
- typecheck
- unparam
- unused
- lll

linters-settings:
lll:
line-length: 120
15 changes: 10 additions & 5 deletions client/foundries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions client/foundries_el2g.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion client/foundries_sboms.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion subcommands/config/rotate_certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion subcommands/config/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 8 additions & 4 deletions subcommands/devices/config_rotate_certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion subcommands/devices/config_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
32 changes: 20 additions & 12 deletions subcommands/devices/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion subcommands/docker/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
19 changes: 13 additions & 6 deletions subcommands/git/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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()
Expand All @@ -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)
}
Expand Down
9 changes: 6 additions & 3 deletions subcommands/keys/ca_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 6 additions & 3 deletions subcommands/keys/tuf_rotate_all_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <offline-creds.tgz> used to sign TUF root.")
_ = rotate.MarkFlagRequired("keys")
_ = rotate.MarkFlagFilename("keys")
rotate.Flags().StringP("targets-keys", "K", "", "Path to <offline-targets-creds.tgz> used to sign prod & wave TUF targets.")
rotate.Flags().StringP("targets-keys", "K", "",
"Path to <offline-targets-creds.tgz> 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)
}

Expand Down
21 changes: 14 additions & 7 deletions subcommands/keys/tuf_rotate_offline_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ When you rotate the TUF targets offline signing key:
rotate.Flags().StringP("keys", "k", "", "Path to <offline-creds.tgz> used to sign TUF root.")
_ = rotate.MarkFlagRequired("keys")
_ = rotate.MarkFlagFilename("keys")
rotate.Flags().StringP("targets-keys", "K", "", "Path to <offline-targets-creds.tgz> used to sign prod & wave TUF targets.")
rotate.Flags().StringP("targets-keys", "K", "",
"Path to <offline-targets-creds.tgz> 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{
Expand All @@ -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{
Expand All @@ -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)
}

Expand Down
6 changes: 4 additions & 2 deletions subcommands/keys/tuf_updates_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <offline-creds.tgz> used to store initial root key.")
_ = initCmd.MarkFlagFilename("keys")
initCmd.MarkFlagsRequiredTogether("first-time", "keys")
Expand Down
Loading

0 comments on commit 97e96f0

Please sign in to comment.