Exemple #1
0
func (gf *GistFs) Open(n string, _ uint32, c *fuse.Context) (nodefs.File, fuse.Status) {
	if gf.files == nil {
		log.Println("Nil map. Files have not been queried yet.")
		return nil, fuse.ENOENT
	}

	if f, ok := gf.files[n]; ok {

		if f.contents != nil {
			//Cached copy
			return nodefs.NewDataFile(f.contents), fuse.OK
		}

		res, err := http.Get(f.RawUrl)
		defer res.Body.Close()
		if err != nil {
			log.Println(err)
			return nil, fuse.ENOENT
		}

		bs, err := ioutil.ReadAll(res.Body)
		if err != nil {
			log.Println(err)
			return nil, fuse.ENOENT
		}

		f.contents = bs

		return nodefs.NewDataFile(bs), fuse.OK
	}
	return nil, fuse.ENOENT
}
Exemple #2
0
func (vfs FuseVfs) Open(name string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
	log.Infof(2, "BEGIN Open(%v)", name)
	defer log.Infof(2, "END Open(%v)", name)

	switch name {
	case filepath.Join(queriesDir, helpFilename):
		return nodefs.NewDataFile([]byte(queryDirHelp)), fuse.OK
	case filepath.Join(tagsDir, helpFilename):
		return nodefs.NewDataFile([]byte(tagsDirHelp)), fuse.OK
	}

	return nil, fuse.ENOSYS
}
Exemple #3
0
// Open is a FUSE function where an in-memory open file struct is constructed.
func (f *fs) Open(name string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
	var file nodefs.File
	switch {
	case name == "":
		return nil, EISDIR
	case name == "secret":
		return nil, EISDIR
	default:
		s, err := f.client.Logical().Read(name)
		if err != nil {
			return nil, fuse.ENOENT
		}

		if s == nil || s.Data == nil {
			return nil, fuse.ENOENT
		}

		file = nodefs.NewDataFile([]byte(s.Data["value"].(string)))
	}

	if file != nil {
		file = nodefs.NewReadOnlyFile(file)
		return file, fuse.OK
	}
	return nil, fuse.ENOENT
}
// Open is a FUSE function where an in-memory open file struct is constructed.
func (f *fs) Open(name string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
	log.Printf("Open '%s'\n", name)
	var file nodefs.File
	switch {
	case name == "":
		return nil, EISDIR
	case name == "secret" || name == "sys":
		return nil, EISDIR
	case strings.HasPrefix(name, "secret/"):
		fmt.Println("got here")
		s, err := f.client.Logical().Read(name)
		if err != nil {
			log.Println(err)
			return nil, fuse.ENOENT
		}

		if s == nil || s.Data == nil {
			return nil, fuse.ENOENT
		}

		file = nodefs.NewDataFile([]byte(s.Data["value"].(string) + "\n"))
	}

	if file != nil {
		file = nodefs.NewReadOnlyFile(file)
		return file, fuse.OK
	}
	return nil, fuse.ENOENT
}
// Open returns a datafile representing the HTTP response body
func (fs *MetadataFs) Open(name string, flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
	url := fs.Endpoint + name

	log.Printf("[DEBUG] issuing HTTP GET to AWS metadata API for path: '%s'", url)
	resp, err := fs.Client.Get(url)
	if err != nil {
		log.Printf("[ERROR] failed to query AWS metadata API: %s", err)
		return nil, fuse.EIO
	}

	log.Printf("[DEBUG] got %d from AWS metadata API for path %s", resp.StatusCode, url)
	switch resp.StatusCode {
	case http.StatusNotFound:
		return nil, fuse.ENOENT
	case http.StatusOK:
		body, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			log.Printf("[ERROR] failed to query AWS metadata API: %s", err)
			return nil, fuse.EIO
		}

		return nodefs.NewDataFile(body), fuse.OK
	default:
		log.Printf("[ERROR] unknown HTTP status code from AWS metadata API: %d", resp.StatusCode)
		return nil, fuse.EIO
	}
}
func (me *P9Fs) Open(name string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {

	var user go9p.User
	var err error
	var c *clnt.Clnt
	var file *clnt.File
	var f []byte

	user = go9p.OsUsers.Uid2User(os.Geteuid())
	clnt.DefaultDebuglevel = 0
	c, err = clnt.Mount("tcp", address, "", user)
	if err != nil {
		goto error
	}

	file, err = c.FOpen("/tmp/anaconda-post.log", go9p.OREAD)
	if err != nil {
		goto error
	}
	defer file.Close()
	f, err = ioutil.ReadAll(file)

	if err != nil && err != io.EOF {
		goto error
	}

	return nodefs.NewDataFile(f), fuse.OK

error:
	log.Println("Error", err)
	return nil, fuse.EPERM
}
Exemple #7
0
func (n *memNode) Open(flags uint32, context *fuse.Context) (fuseFile nodefs.File, code fuse.Status) {
	if flags&fuse.O_ANYWRITE != 0 {
		return nil, fuse.EPERM
	}

	return nodefs.NewDataFile(n.file.Data()), fuse.OK
}
Exemple #8
0
func (me *HelloFs) Open(name string, flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
	if name != "file.txt" {
		return nil, fuse.ENOENT
	}
	if flags&fuse.O_ANYWRITE != 0 {
		return nil, fuse.EPERM
	}
	return nodefs.NewDataFile([]byte(name)), fuse.OK
}
Exemple #9
0
func (me *DropboxFs) Open(name string, flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
	path := get_path(name)
	log.Printf("Open: '%s'\n", name)
	if flags&fuse.O_ANYWRITE != 0 {
		return nil, fuse.EPERM
	}
	// XXX: errors!
	res, _ := GetFile(path)
	return nodefs.NewDataFile(res), fuse.OK
}
func (me *RdiffFs) Open(name string, flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {

	// fmt.Println("Open", name)
	// if name != "file.txt" {
	// 	return nil, fuse.ENOENT
	// }
	// if flags&fuse.O_ANYWRITE != 0 {
	// 	return nil, fuse.EPERM
	// }
	return nodefs.NewDataFile([]byte(name)), fuse.OK
}
Exemple #11
0
func (fs *nonseekFs) Open(name string, flags uint32, context *fuse.Context) (fuseFile nodefs.File, status fuse.Status) {
	if name != "file" {
		return nil, fuse.ENOENT
	}

	data := bytes.Repeat([]byte{42}, fs.Length)
	f := nodefs.NewDataFile(data)
	return &nodefs.WithFlags{
		File:      f,
		FuseFlags: fuse.FOPEN_NONSEEKABLE,
	}, fuse.OK
}
Exemple #12
0
// Open is a FUSE function where an in-memory open file struct is constructed.
func (kwfs KeywhizFs) Open(name string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
	kwfs.Debugf("Open called with '%v'", name)

	var file nodefs.File
	switch {
	case name == "", name == ".json", name == ".json/secret":
		return nil, EISDIR
	case name == ".version":
		file = nodefs.NewDataFile([]byte(VERSION))
	case name == ".clear_cache":
		file = nodefs.NewDevNullFile()
	case name == ".running":
		file = nodefs.NewDataFile(running())
	case name == ".json/secrets":
		data, ok := kwfs.Client.RawSecretList()
		if ok {
			file = nodefs.NewDataFile(data)
		}
	case strings.HasPrefix(name, ".json/secret/"):
		name = name[len(".json/secret/"):]
		data, ok := kwfs.Client.RawSecret(name)
		if ok {
			file = nodefs.NewDataFile(data)
			kwfs.Infof("Access to %s by uid %d, with gid %d", name, context.Uid, context.Gid)
		}
	default:
		secret, ok := kwfs.Cache.Secret(name)
		if ok {
			file = nodefs.NewDataFile(secret.Content)
			kwfs.Infof("Access to %s by uid %d, with gid %d", name, context.Uid, context.Gid)
		}
	}

	if file != nil {
		file = nodefs.NewReadOnlyFile(file)
		return file, fuse.OK
	}
	return nil, fuse.ENOENT
}
Exemple #13
0
func (fs *GrpcFs) Create(name string, flags uint32, mode uint32, ctx *fuse.Context) (nodefs.File, fuse.Status) {
	req := &pb.CreateRequest{
		Name:    name,
		Flags:   flags,
		Mode:    mode,
		Context: pbContext(ctx),
	}
	resp, err := fs.client.Create(context.Background(), req)
	if err != nil {
		return nil, fuse.ToStatus(err)
	}
	return nodefs.NewDataFile(resp.File.Data), resp.Status.Code
}
Exemple #14
0
func (fs *autoUnionFs) Open(path string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
	if path == filepath.Join(_STATUS, _DEBUG) {
		if flags&fuse.O_ANYWRITE != 0 {
			return nil, fuse.EPERM
		}

		return nodefs.NewDataFile([]byte(fs.DebugData())), fuse.OK
	}
	if path == filepath.Join(_STATUS, _VERSION) {
		if flags&fuse.O_ANYWRITE != 0 {
			return nil, fuse.EPERM
		}
		return nodefs.NewDataFile([]byte(fs.options.Version)), fuse.OK
	}
	if path == filepath.Join(_CONFIG, _SCAN_CONFIG) {
		if flags&fuse.O_ANYWRITE != 0 {
			fs.updateKnownFses()
		}
		return nodefs.NewDevNullFile(), fuse.OK
	}
	return nil, fuse.ENOENT
}
Exemple #15
0
func (gfs *GoMonitorFs) Open(name string, flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
	if flags&fuse.O_ANYWRITE != 0 {
		return nil, fuse.EPERM
	}
	parts := strings.Split(name, string(os.PathSeparator))
	if source, ok := gfs.Sources[parts[0]]; ok {
		content, found := source.Contents(parts[1])
		if !found {
			return nil, fuse.EPERM
		}
		return nodefs.NewDataFile(content), fuse.OK
	}
	return nil, fuse.EPERM
}
Exemple #16
0
func (fs *GrpcFs) Open(name string, flags uint32, ctx *fuse.Context) (nodefs.File, fuse.Status) {
	req := &pb.OpenRequest{
		Name:    name,
		Flags:   flags,
		Context: pbContext(ctx),
	}
	resp, err := fs.client.Open(context.Background(), req)
	if err != nil {
		return nil, fuse.ToStatus(err)
	}
	if resp.Status.Code != fuse.OK {
		return nil, resp.Status.Code
	}
	return nodefs.NewDataFile(resp.File.Data), fuse.OK
}
Exemple #17
0
func TestLoggingFile(t *testing.T) {
	var logOut bytes.Buffer
	cli.Log = &logrus.Logger{
		Out:       &logOut,
		Formatter: new(logrus.JSONFormatter),
		Level:     logrus.DebugLevel,
	}
	flags := 42

	file := newLoggingFile(nodefs.NewDataFile([]byte{}), "")
	code := file.Fsync(flags)
	assert.False(t, code.Ok())

	var output map[string]interface{}
	assert.NoError(t, json.Unmarshal(logOut.Bytes(), &output))

	assert.NotEmpty(t, output["status"])
	assert.Equal(t, "File Fsync", output["msg"])
	assert.True(t, output["duration_ms"].(float64) >= 0)
	assert.Equal(t, "[42]", output["args"])
	assert.NotEmpty(t, output["time"])
}
Exemple #18
0
// Open returns a datafile representing the tag value
func (fs *TagsFs) Open(name string, flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
	log.Printf("[DEBUG] issuing request to AWS API for tag: %s", name)

	resp, err := fs.Client.DescribeTags(&ec2.DescribeTagsInput{
		Filters: []*ec2.Filter{
			{Name: aws.String("key"), Values: []*string{aws.String(name)}},
			{Name: aws.String("resource-id"), Values: []*string{aws.String(fs.InstanceID)}},
		},
	})

	if err != nil {
		log.Printf("[ERROR] failed to query AWS API: %s", err)
		return nil, fuse.EIO
	}

	if len(resp.Tags) == 0 {
		log.Printf("[DEBUG] no tag found for %s", name)
		return nil, fuse.ENOENT
	}

	return nodefs.NewDataFile([]byte(*resp.Tags[0].Value)), fuse.OK
}
Exemple #19
0
func (fs *KafkaRoFs) Open(name string, flags uint32,
	context *fuse.Context) (nodefs.File, fuse.Status) {
	parsed, err := fs.parseAndValidate(name)
	if err != nil {
		return nil, fuse.EIO
	}

	if !parsed.IsValid || parsed.Offset == -1 {
		return nil, fuse.ENOENT
	}

	if flags&fuse.O_ANYWRITE != 0 {
		return nil, fuse.EPERM
	}

	msgBytes, ferr := fs.getMessage(parsed.Topic, parsed.Partition, parsed.Offset)

	if ferr != fuse.OK {
		return nil, ferr
	}

	return nodefs.NewDataFile(msgBytes), fuse.OK
}
Exemple #20
0
func (fs *ElasticFs) Create(name string, flags uint32, mode uint32, context *fuse.Context) (fuseFile nodefs.File, code fuse.Status) {
	fmt.Printf("Create %s", name)
	return nodefs.NewDataFile([]byte(name)), fuse.OK
}
Exemple #21
0
func (n *myNode) Open(flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
	return nodefs.NewDataFile(n.content), fuse.OK
}
Exemple #22
0
func (sn *StrNode) Open(flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
	return nodefs.NewDataFile([]byte(sn.s)), fuse.OK
}
Exemple #23
0
func (fs *NotifyFs) Open(name string, f uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
	return nodefs.NewDataFile([]byte{42}), fuse.OK
}