Skip to content

Commit aba249b

Browse files
authored
Merge pull request #484 from kosli-dev/whitespace-artifact-name-fix
Whitespace artifact name fix
2 parents 5481e11 + 9f570f1 commit aba249b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

docs.kosli.com/content/faq/_index.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,17 @@ kosli attest generic Dockerfile true ...
242242
```
243243
The parser then sees `Dockerfile` and `true` as the two
244244
arguments to `kosli attest generic`.
245+
246+
## Path/Image name is a single whitespace character!
247+
248+
In order to calculate the fingerprint for an artifact, Kosli requires the path to the relevant file or directory, or the relevant image name. The command typically takes the form:
249+
```
250+
kosli attest generic [IMAGE-NAME | FILE-PATH | DIR-PATH] [flags]
251+
```
252+
253+
When using multi-line commands in the shell or a script, if the image name or path has not been provided as above and whitespace has unintentionally been added after the line-continuation backslash on one of the lines, this whitespace character is interpreted as the name or path.
254+
255+
If you're using multi-line commands and receive an error message similar to this, check your command for extraneous whitespace:
256+
```
257+
Error: failed to calculate artifact fingerprint: stat : no such file or directory. The directory path is ' '.
258+
```

internal/digest/digest.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ func DirSha256(dirPath string, excludePaths []string, logger *logger.Logger) (st
3535
logger.Debug("calculating fingerprint for path [%s] -- excluding paths: %s", dirPath, excludePaths)
3636
info, err := os.Stat(dirPath)
3737
if err != nil {
38+
if dirPath == " " {
39+
return "", fmt.Errorf("%s. The directory path is '%s'. https://docs.kosli.com/faq/#pathimage-name-is-a-single-whitespace-character", err, dirPath)
40+
}
3841
return "", err
3942
}
4043
if !info.IsDir() {
@@ -83,6 +86,9 @@ func OciSha256(artifactName string, registryUsername string, registryPassword st
8386
// Parse image reference
8487
ref, err := docker.ParseReference(imageName)
8588
if err != nil {
89+
if artifactName == " " {
90+
return "", fmt.Errorf("%w. The artifact name is '%s'. https://docs.kosli.com/faq/#pathimage-name-is-a-single-whitespace-character", err, artifactName)
91+
}
8692
return "", fmt.Errorf("failed to parse image reference for %s: %w", imageName, err)
8793
}
8894

@@ -171,6 +177,9 @@ func FileSha256(filepath string) (string, error) {
171177
hasher := sha256.New()
172178
f, err := os.Open(filepath)
173179
if err != nil {
180+
if filepath == " " {
181+
return "", fmt.Errorf("%s. The filename is '%s'. https://docs.kosli.com/faq/#pathimage-name-is-a-single-whitespace-character", err, filepath)
182+
}
174183
return "", err
175184
}
176185
defer f.Close()
@@ -191,6 +200,9 @@ func DockerImageSha256(imageID string) (string, error) {
191200
}
192201
imageInspect, err := cli.ImageInspect(context.Background(), imageID)
193202
if err != nil {
203+
if imageID == " " {
204+
return "", fmt.Errorf("%s. The image ID is '%s'. https://docs.kosli.com/faq/#pathimage-name-is-a-single-whitespace-character", err, imageID)
205+
}
194206
return "", err
195207
}
196208
repoDigests := imageInspect.RepoDigests

0 commit comments

Comments
 (0)