예제 #1
0
파일: group.go 프로젝트: jjacquay712/GoRods
// FetchUsers returns a slice of fresh *User from the iCAT server
func (grp *Group) FetchUsers() (Users, error) {

	var (
		result C.goRodsStringResult_t
		err    *C.char
	)

	result.size = C.int(0)

	cGroupName := C.CString(grp.name)
	defer C.free(unsafe.Pointer(cGroupName))

	ccon := grp.con.GetCcon()

	if status := C.gorods_get_group(ccon, &result, cGroupName, &err); status != 0 {
		grp.con.ReturnCcon(ccon)
		if status == C.CAT_NO_ROWS_FOUND {
			return make(Users, 0), nil
		} else {

			return nil, newError(Fatal, fmt.Sprintf("iRODS Get Group %v Failed: %v", grp.name, C.GoString(err)))
		}

	}

	grp.con.ReturnCcon(ccon)
	defer C.gorods_free_string_result(&result)

	unsafeArr := unsafe.Pointer(result.strArr)
	arrLen := int(result.size)

	// Convert C array to slice, backed by arr *C.char
	slice := (*[1 << 30]*C.char)(unsafeArr)[:arrLen:arrLen]

	if usrs, err := grp.con.Users(); err == nil {
		response := make(Users, 0)

		for _, userNames := range slice {

			usrFrags := strings.Split(C.GoString(userNames), "#")

			if usr := usrs.FindByName(usrFrags[0], grp.con); usr != nil {
				response = append(response, usr)
			} else {
				return nil, newError(Fatal, fmt.Sprintf("iRODS FetchUsers Failed: User in response not found in cache"))
			}

		}

		return response, nil
	} else {
		return nil, err
	}

}
예제 #2
0
파일: user.go 프로젝트: jjacquay712/GoRods
// FetchGroups fetches and returns fresh data about the user's groups from the iCAT server.
func (usr *User) FetchGroups() (Groups, error) {
	var (
		result C.goRodsStringResult_t
		err    *C.char
	)

	cName := C.CString(usr.name)
	defer C.free(unsafe.Pointer(cName))

	result.size = C.int(0)

	ccon := usr.con.GetCcon()

	if status := C.gorods_get_user_groups(ccon, cName, &result, &err); status != 0 {
		usr.con.ReturnCcon(ccon)
		return nil, newError(Fatal, fmt.Sprintf("iRODS Get Groups Failed: %v", C.GoString(err)))
	}

	usr.con.ReturnCcon(ccon)

	defer C.gorods_free_string_result(&result)

	unsafeArr := unsafe.Pointer(result.strArr)
	arrLen := int(result.size)

	// Convert C array to slice, backed by arr *C.char
	slice := (*[1 << 30]*C.char)(unsafeArr)[:arrLen:arrLen]

	if grps, err := usr.con.Groups(); err == nil {
		response := make(Groups, 0)

		for _, groupName := range slice {

			gName := C.GoString(groupName)

			if gName != usr.name {
				grp := grps.FindByName(gName, usr.con)

				if grp != nil {
					response = append(response, grp)
				} else {
					return nil, newError(Fatal, fmt.Sprintf("iRODS FetchGroups Failed: Group in response not found in cache"))
				}
			}
		}

		return response, nil
	} else {
		return nil, err
	}

}
예제 #3
0
파일: user.go 프로젝트: jjacquay712/GoRods
// FetchInfo fetches fresh user info from the iCAT server, and returns it as a map.
func (usr *User) FetchInfo() (map[string]string, error) {
	var (
		result C.goRodsStringResult_t
		err    *C.char
	)

	result.size = C.int(0)

	cUser := C.CString(usr.name)
	defer C.free(unsafe.Pointer(cUser))

	ccon := usr.con.GetCcon()

	if status := C.gorods_get_user(cUser, ccon, &result, &err); status != 0 {
		usr.con.ReturnCcon(ccon)
		return nil, newError(Fatal, fmt.Sprintf("iRODS Get Users Failed: %v", C.GoString(err)))
	}

	usr.con.ReturnCcon(ccon)

	defer C.gorods_free_string_result(&result)

	unsafeArr := unsafe.Pointer(result.strArr)
	arrLen := int(result.size)

	// Convert C array to slice, backed by arr *C.char
	slice := (*[1 << 30]*C.char)(unsafeArr)[:arrLen:arrLen]

	//response := make(Users, 0)
	response := make(map[string]string)

	for _, userInfo := range slice {

		userAttributes := strings.Split(strings.Trim(C.GoString(userInfo), " \n"), "\n")

		for _, attr := range userAttributes {

			split := strings.Split(attr, ": ")

			attrName := split[0]
			attrVal := split[1]

			response[attrName] = attrVal

		}

	}

	return response, nil
}
예제 #4
0
// FetchZones returns a slice of *Zone, fresh from the iCAT server.
func (con *Connection) FetchZones() (Zones, error) {
	var (
		result C.goRodsStringResult_t
		err    *C.char
	)

	result.size = C.int(0)

	ccon := con.GetCcon()

	if status := C.gorods_get_zones(ccon, &result, &err); status != 0 {
		con.ReturnCcon(ccon)
		return nil, newError(Fatal, fmt.Sprintf("iRODS Get Zones Failed: %v", C.GoString(err)))
	}

	con.ReturnCcon(ccon)

	defer C.gorods_free_string_result(&result)

	unsafeArr := unsafe.Pointer(result.strArr)
	arrLen := int(result.size)

	// Convert C array to slice, backed by arr *C.char
	slice := (*[1 << 30]*C.char)(unsafeArr)[:arrLen:arrLen]

	response := make(Zones, 0)

	for _, cZoneName := range slice {

		zoneNames := strings.Split(strings.Trim(C.GoString(cZoneName), " \n"), "\n")

		for _, name := range zoneNames {

			if zne, err := initZone(name, con); err == nil {
				response = append(response, zne)
			} else {
				return nil, err
			}

		}

	}

	return response, nil
}
예제 #5
0
// FetchResources returns a slice of *Resource, fresh from the iCAT server.
func (con *Connection) FetchResources() (Resources, error) {
	var (
		result C.goRodsStringResult_t
		err    *C.char
	)

	result.size = C.int(0)

	ccon := con.GetCcon()

	if status := C.gorods_get_resources_new(ccon, &result, &err); status != 0 {
		con.ReturnCcon(ccon)
		return nil, newError(Fatal, fmt.Sprintf("iRODS  Get Resources Failed: %v", C.GoString(err)))
	}

	con.ReturnCcon(ccon)

	defer C.gorods_free_string_result(&result)

	unsafeArr := unsafe.Pointer(result.strArr)
	arrLen := int(result.size)

	// Convert C array to slice, backed by arr *C.char
	slice := (*[1 << 30]*C.char)(unsafeArr)[:arrLen:arrLen]

	response := make(Resources, 0)

	for _, cResourceName := range slice {

		name := C.GoString(cResourceName)

		if resc, err := initResource(name, con); err == nil {
			response = append(response, resc)
		} else {
			return nil, err
		}

	}

	return response, nil
}
예제 #6
0
// FetchUsers returns a slice of *User, fresh from the iCAT server.
func (con *Connection) FetchUsers() (Users, error) {
	var (
		result C.goRodsStringResult_t
		err    *C.char
	)

	result.size = C.int(0)

	ccon := con.GetCcon()

	if status := C.gorods_get_users(ccon, &result, &err); status != 0 {
		con.ReturnCcon(ccon)
		return nil, newError(Fatal, fmt.Sprintf("iRODS Get Users Failed: %v", C.GoString(err)))
	}

	con.ReturnCcon(ccon)

	defer C.gorods_free_string_result(&result)

	unsafeArr := unsafe.Pointer(result.strArr)
	arrLen := int(result.size)

	// Convert C array to slice, backed by arr *C.char
	slice := (*[1 << 30]*C.char)(unsafeArr)[:arrLen:arrLen]

	response := make(Users, 0)

	for _, userNames := range slice {

		nameZone := strings.Split(strings.Trim(C.GoString(userNames), " \n"), "\n")

		for _, name := range nameZone {

			split := strings.Split(name, "#")

			user := split[0]
			zonename := split[1]
			var zone *Zone

			if zones, err := con.Zones(); err != nil {
				return nil, err
			} else {
				if zne := zones.FindByName(zonename, con); zne != nil {
					zone = zne
				} else {
					return nil, newError(Fatal, fmt.Sprintf("iRODS Fetch Users Failed: Unable to locate zone in cache"))
				}
			}

			if usr, err := initUser(user, zone, con); err == nil {
				response = append(response, usr)
			} else {
				return nil, err
			}

		}

	}

	return response, nil
}