hancock

Check-in [15250ce5f7]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:cmd/hancock: introduce strict mode
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 15250ce5f7d50fa30d242ea654a5dea1b2b9ec31ed1898e984c62c6162b61076
User & Date: dnc 2019-06-07 13:32:22
Context
2019-06-07
13:32
cmd/hancock: show publish count per directory check-in: b975cd947c user: dnc tags: trunk
13:32
cmd/hancock: introduce strict mode check-in: 15250ce5f7 user: dnc tags: trunk
00:03
cmd/hancock: support testimony to local file, publish later introducing publish operation check-in: 0cefd98c32 user: dnc tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to cmd/hancock/verify.go.

61
62
63
64
65
66
67

68
69
70
71
72
73
74
...
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
...
225
226
227
228
229
230
231

232
233
234




235
236
237
238
239
240
241
242
243
244
245
func verifyMain() error {
	cfg, err := command.Config()
	command.Check(err)

	defaultIndex := cfg.Section("").Key("index").MustString("https://hancock.beyondcentral.com")
	defaultIPFS := cfg.Section("").Key("ipfs").MustString("http://localhost:8080")


	command.OperationFlagSet.Var(&verifyIndexFlag, "index", fmt.Sprintf("URL of authenticity index (default %s)", defaultIndex))
	ipfsFlag := command.OperationFlagSet.String("ipfs", defaultIPFS, "URL of manifests")
	recurseFlag := command.OperationFlagSet.Bool("r", false, "verify all files in directory")
	err = command.OperationFlagSet.Parse(command.Args()[1:])
	if err != nil {
		return err
	}
................................................................................
					switch resp.StatusCode {
					case http.StatusOK:
						body, err := ioutil.ReadAll(resp.Body)
						if err != nil {
							command.Error(err)
							continue
						}
						// body is the CID of a manifest that authenticates the source CID

						u, err = url.Parse(*ipfsFlag)
						command.Check(err) // TODO(dnc): validate earlier
						u.Path = path.Join(u.Path, "ipfs", string(body))
						resp, err = httpclient.Get(u.String())
						if err != nil {
							command.Info(err)
................................................................................
					default:
						command.V(2).Info(filepath, u.String(), resp.Status)
					} // end index status
				} // end index loop
			} // end authority loop

			if !verified {

				// command.Error sets exit status code (not zero)
				command.Errorf("%q not verified", filepath)
				// TODO(dnc): exit early on fail to validate (strict mode)




			}
			return nil // continue file walk
		})
		if err == noRecurse {
			return fmt.Errorf("Expected file name. Use -r to recurse directories (%q).", arg)
		} else if err != nil {
			command.Error(err) // log error, continue arg loop
		}
	}
	return nil
}







>







 







|







 







>
|
|
<
>
>
>
>











61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
...
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
...
226
227
228
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
func verifyMain() error {
	cfg, err := command.Config()
	command.Check(err)

	defaultIndex := cfg.Section("").Key("index").MustString("https://hancock.beyondcentral.com")
	defaultIPFS := cfg.Section("").Key("ipfs").MustString("http://localhost:8080")

	strictFlag := command.OperationFlagSet.Bool("strict", false, "strict mode requires source to be endorsed")
	command.OperationFlagSet.Var(&verifyIndexFlag, "index", fmt.Sprintf("URL of authenticity index (default %s)", defaultIndex))
	ipfsFlag := command.OperationFlagSet.String("ipfs", defaultIPFS, "URL of manifests")
	recurseFlag := command.OperationFlagSet.Bool("r", false, "verify all files in directory")
	err = command.OperationFlagSet.Parse(command.Args()[1:])
	if err != nil {
		return err
	}
................................................................................
					switch resp.StatusCode {
					case http.StatusOK:
						body, err := ioutil.ReadAll(resp.Body)
						if err != nil {
							command.Error(err)
							continue
						}
						// body is the CID of testimony regarding the source CID

						u, err = url.Parse(*ipfsFlag)
						command.Check(err) // TODO(dnc): validate earlier
						u.Path = path.Join(u.Path, "ipfs", string(body))
						resp, err = httpclient.Get(u.String())
						if err != nil {
							command.Info(err)
................................................................................
					default:
						command.V(2).Info(filepath, u.String(), resp.Status)
					} // end index status
				} // end index loop
			} // end authority loop

			if !verified {
				if *strictFlag {
					// command.Error sets exit status code (not zero)
					command.Errorf("%q not verified", filepath)

					command.Exit() // exit early when strict mode (should this be only when verbose is off?)
				} else if command.V(2) {
					command.Infof("%q not verified", filepath)
				}
			}
			return nil // continue file walk
		})
		if err == noRecurse {
			return fmt.Errorf("Expected file name. Use -r to recurse directories (%q).", arg)
		} else if err != nil {
			command.Error(err) // log error, continue arg loop
		}
	}
	return nil
}