github.com/rohankumardubey/proxyfs@v0.0.0-20210108201508-653efa9ab00e/confgen/api.go (about) 1 // Package confgen provides a mechanism by which a supplied configuration is converted into a 2 // set of configuration files to be supplied to ProxyFS (proxyfsd), Samba (smbd et. al.), and 3 // NFS (nfsd). In (at least) the case of Samba, multiple configuration files will be produced 4 // with a per-IP path. 5 // 6 // Only the configuration files for the Cluster.WhoAmI-identified Peer will be produced though, 7 // in the case of the ProxyFS configuration file, all VolumeGroups will be included given that 8 // ProxyFS needs to know the mapping of VolumeGroup to Peer. This allows one ProxyFS instance 9 // to redirect a JSONRPC client to the appropriate ProxyFS instance servicing the refernected 10 // Volume. The Cluster.WhoAmI can either already be present in the `confFilePath` or be provided 11 // as an element of the `confOverrides` argument in each of the APIs below. 12 // 13 // As would be typical in a deployment where the placement of VolumeGroups on Peers in dynamic, 14 // the `confFilePath` would provide `VirtualIPAddr` values as opposed to fixed `PrimaryPeer` 15 // assignments. It is the callers responsibility to compute the assignments of VolumeGroups 16 // to Peers and either modify the provided `confFilePath` to include PrimaryPeer values or to 17 // supply those via the `confOverrides` (e.g. "VolumeGroup:CommonVolumeGroup.PrimaryPeer=Peer0"). 18 package confgen 19 20 // EnvMap allows the caller to provide environment-specific paths for various programs invoked 21 // by this API as well as customize the scripts produced by this API. 22 type EnvMap map[string]string 23 24 const ( 25 // LinuxUserCommentDefault is the default value of environment variable LinuxUserCommentEnv. 26 LinuxUserCommentDefault = "user-created-for-samba" 27 // LinuxUserCommentEnv specifies a comment to be applied to each Linux user created 28 // to be referenced by the SMB user system as provided by SAMBA(7). 29 LinuxUserCommentEnv = "LINUX_USER_COMMENT" 30 31 // PathToNetDefault is the default value of environment variable PathToNetEnv. 32 PathToNetDefault = "/usr/bin/net" 33 // PathToNetEnv is the name of the environment variable used to specify the path to the 34 // NET(8) tool used to administer a SAMBA(7) installation. 35 PathToNetEnv = "PATH_TO_NET" 36 37 // PathToKRB5ConfDirDefault is the default value of environment variable PathToKRB5ConfDirEnv. 38 PathToKRB5ConfDirDefault = "/etc/krb5.conf.d" 39 // PathToKRB5ConfDirEnv is the name of the environment variable used to specify the path to 40 // the KRB5 configuration directory where realm declarations are placed. This method is used 41 // to avoid having to merge all realm declarations into a common KRB5 configuration file. 42 PathToKRB5ConfDirEnv = "PATH_TO_KRB5_CONF_DIR" 43 44 // PathToPDBEditDefault is the default value of environment variable PathToPDBEditEnv. 45 PathToPDBEditDefault = "/usr/bin/pdbedit" 46 // PathToPDBEditEnv is the name of the environment variable used to specify the path to 47 // the PDBEDIT(8) tool used to administer a SAMBA(7) installation. 48 PathToPDBEditEnv = "PATH_TO_PDBEDIT" 49 50 // PathToPerVirtualIPAddrDirDefault is the default value of environment variable PathToPerVirtualIPAddrDirEnv. 51 PathToPerVirtualIPAddrDirDefault = "/var/lib/vips" 52 // PathToPerVirtualIPAddrDirEnv is the name of the environment variable used to specify the 53 // path to a directory containing a set of subdirectories each named for the corresponding 54 // VirtualIPAddr to which they pertain. In particular, each such subdirectory will contain 55 // a "samba" subdirectory containing all files referenced by that VirtualIPAddr's instance 56 // of SAMBA(7). 57 PathToPerVirtualIPAddrDirEnv = "PATH_TO_PER_VIRTUAL_IP_ADDR_DIR" 58 59 // PathToSMBDDefault is the default value of environment variable PathToSMBDEnv. 60 PathToSMBDDefault = "/usr/bin/smbd" 61 // PathToSMBDEnv is the name of the environment variable used to specify the path to the 62 // SMBD(8) program in a SAMBA(7) installation used to provide SMB file serving to clients. 63 PathToSMBDEnv = "PATH_TO_SMBD" 64 65 // PathToSMBPasswdDefault is the default value of environment variable PathToSMBPasswdEnv. 66 PathToSMBPasswdDefault = "/usr/bin/smbpasswd" 67 // PathToSMBPasswdEnv is the name of the environment variable used to specify the path to 68 // the SMBPASSWD(8) tool used to add an SMB user or update an SMB user's password in a 69 // SAMBA(7) installation. 70 PathToSMBPasswdEnv = "PATH_TO_SMBPASSWD" 71 ) 72 73 // ComputeInitial takes a supplied ConfFile, overlays ConfOverrides, and computes an initial 74 // set of configuration files that are used by a per-IPAddr set of Samba instances as well as 75 // NFSd & ProxyFS. 76 func ComputeInitial(envMap EnvMap, confFilePath string, confOverrides []string, initialDirPath string) (err error) { 77 err = computeInitial(envMap, confFilePath, confOverrides, initialDirPath) 78 return 79 } 80 81 // ComputePhases takes a supplied initial set of conf files (such as produced by ComputeInitial() 82 // above) along with a new ConfFile and new ConfOverrides and produces two sets of conf files 83 // used in a 2-phase migration from the initial config to a new config. Presumably, the 2nd phase 84 // produced will be used as the initial config in the next call to ComputePhases(). 85 func ComputePhases(envMap EnvMap, initialDirPath string, confFilePath string, confOverrides []string, phaseOneDirPath string, phaseTwoDirPath string) (err error) { 86 err = computePhases(envMap, initialDirPath, confFilePath, confOverrides, phaseOneDirPath, phaseTwoDirPath) 87 return 88 }