本文整理汇总了Golang中camlistore/org/pkg/osutil.CamliConfigDir函数的典型用法代码示例。如果您正苦于以下问题:Golang CamliConfigDir函数的具体用法?Golang CamliConfigDir怎么用?Golang CamliConfigDir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CamliConfigDir函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestStarts
func TestStarts(t *testing.T) {
td, err := ioutil.TempDir("", "camlistored-test")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(td)
fakeHome := filepath.Join(td, "fakeHome")
confDir := filepath.Join(fakeHome, "conf")
defer pushEnv("HOME", fakeHome)()
defer pushEnv("HOMEPATH", fakeHome)()
defer pushEnv("APPDATA", filepath.Join(fakeHome, "appdata"))()
defer pushEnv("CAMLI_CONFIG_DIR", confDir)()
if _, err := os.Stat(osutil.CamliConfigDir()); !os.IsNotExist(err) {
t.Fatalf("expected conf dir %q to not exist", osutil.CamliConfigDir())
}
if !strings.Contains(osutil.CamliBlobRoot(), td) {
t.Fatalf("blob root %q should contain the temp dir %q", osutil.CamliBlobRoot(), td)
}
if _, err := os.Stat(osutil.CamliBlobRoot()); !os.IsNotExist(err) {
t.Fatalf("expected blobroot dir %q to not exist", osutil.CamliBlobRoot())
}
if fi, err := os.Stat(osutil.UserServerConfigPath()); !os.IsNotExist(err) {
t.Errorf("expected no server config file; got %v, %v", fi, err)
}
mkdir(t, confDir)
*flagOpenBrowser = false
defaultListenAddr = ":0"
up := make(chan struct{})
down := make(chan struct{})
dead := make(chan int, 1)
osExit = func(status int) {
dead <- status
close(dead)
runtime.Goexit()
}
go Main(up, down)
select {
case status := <-dead:
t.Errorf("os.Exit(%d) before server came up", status)
return
case <-up:
t.Logf("server is up")
case <-time.After(10 * time.Second):
t.Fatal("timeout starting server")
}
if _, err := os.Stat(osutil.UserServerConfigPath()); err != nil {
t.Errorf("expected a server config file; got %v", err)
}
down <- struct{}{}
<-dead
}
示例2: doConfig
// Reads google storage config and creates a Client. Exits on error.
func doConfig(t *testing.T) (gsa *Client, bucket string) {
gsConfigPath := filepath.Join(osutil.CamliConfigDir(), "gstestconfig.json")
if _, err := os.Stat(gsConfigPath); os.IsNotExist(err) {
test.DependencyErrorOrSkip(t)
t.Fatalf("Missing config file: %v", err)
}
cf, err := jsonconfig.ReadFile(gsConfigPath)
if err != nil {
t.Fatalf("Failed to read config: %v", err)
}
var config jsonconfig.Obj
config = cf.RequiredObject("gsconf")
if err := cf.Validate(); err != nil {
t.Fatalf("Invalid config: %v", err)
}
auth := config.RequiredObject("auth")
bucket = config.RequiredString("bucket")
if err := config.Validate(); err != nil {
t.Fatalf("Invalid config: %v", err)
}
gsa = NewClient(MakeOauthTransport(auth.RequiredString("client_id"),
auth.RequiredString("client_secret"),
auth.RequiredString("refresh_token")))
if err := auth.Validate(); err != nil {
t.Fatalf("Invalid config: %v", err)
}
return
}
示例3: gceDeployHandlerConfig
func gceDeployHandlerConfig(ctx context.Context) (*gce.Config, error) {
if inProd {
return deployerCredsFromGCS(ctx)
}
clientId := os.Getenv("CAMLI_GCE_CLIENTID")
if clientId != "" {
return &gce.Config{
ClientID: clientId,
ClientSecret: os.Getenv("CAMLI_GCE_CLIENTSECRET"),
Project: os.Getenv("CAMLI_GCE_PROJECT"),
ServiceAccount: os.Getenv("CAMLI_GCE_SERVICE_ACCOUNT"),
DataDir: os.Getenv("CAMLI_GCE_DATA"),
}, nil
}
configFile := filepath.Join(osutil.CamliConfigDir(), "launcher-config.json")
data, err := ioutil.ReadFile(configFile)
if err != nil {
return nil, fmt.Errorf("error reading launcher-config.json (expected of type https://godoc.org/camlistore.org/pkg/deploy/gce#Config): %v", err)
}
var config gce.Config
if err := json.Unmarshal(data, &config); err != nil {
return nil, err
}
return &config, nil
}
示例4: loadConfig
// loadConfig returns the server's parsed config file, locating it using the provided arg.
//
// The arg may be of the form:
// - empty, to mean automatic (will write a default high-level config if
// no cloud config is available)
// - a filepath absolute or relative to the user's configuration directory,
// - a URL
func loadConfig(arg string) (conf *serverinit.Config, isNewConfig bool, err error) {
if strings.HasPrefix(arg, "http://") || strings.HasPrefix(arg, "https://") {
contents, err := slurpURL(arg, 256<<10)
if err != nil {
return nil, false, err
}
conf, err = serverinit.Load(contents)
return conf, false, err
}
var absPath string
switch {
case arg == "":
absPath = osutil.UserServerConfigPath()
_, err = wkfs.Stat(absPath)
if err != nil {
if !os.IsNotExist(err) {
return
}
conf, err = serverinit.DefaultEnvConfig()
if err != nil || conf != nil {
return
}
err = wkfs.MkdirAll(osutil.CamliConfigDir(), 0700)
if err != nil {
return
}
log.Printf("Generating template config file %s", absPath)
if err = serverinit.WriteDefaultConfigFile(absPath, sqlite.CompiledIn()); err == nil {
isNewConfig = true
}
}
case filepath.IsAbs(arg):
absPath = arg
default:
absPath = filepath.Join(osutil.CamliConfigDir(), arg)
}
conf, err = serverinit.LoadFile(absPath)
return
}
示例5: findConfigFile
// findConfigFile returns the absolute path of the user's
// config file.
// The provided file may be absolute or relative
// to the user's configuration directory.
// If file is empty, a default high-level config is written
// for the user.
func findConfigFile(file string) (absPath string, err error) {
switch {
case file == "":
absPath = osutil.UserServerConfigPath()
_, err = os.Stat(absPath)
if os.IsNotExist(err) {
err = os.MkdirAll(osutil.CamliConfigDir(), 0700)
if err != nil {
return
}
log.Printf("Generating template config file %s", absPath)
err = newDefaultConfigFile(absPath)
}
return
case filepath.IsAbs(file):
absPath = file
default:
absPath = filepath.Join(osutil.CamliConfigDir(), file)
}
_, err = os.Stat(absPath)
return
}
示例6: findConfigFile
// findConfigFile returns the absolute path of the user's
// config file.
// The provided file may be absolute or relative
// to the user's configuration directory.
// If file is empty, a default high-level config is written
// for the user.
func findConfigFile(file string) (absPath string, isNewConfig bool, err error) {
switch {
case file == "":
absPath = osutil.UserServerConfigPath()
_, err = os.Stat(absPath)
if os.IsNotExist(err) {
err = os.MkdirAll(osutil.CamliConfigDir(), 0700)
if err != nil {
return
}
log.Printf("Generating template config file %s", absPath)
if err = serverinit.WriteDefaultConfigFile(absPath, sqlite.CompiledIn()); err == nil {
isNewConfig = true
}
}
return
case filepath.IsAbs(file):
absPath = file
default:
absPath = filepath.Join(osutil.CamliConfigDir(), file)
}
_, err = os.Stat(absPath)
return
}
示例7: Write
}
func (rb *ringBuffer) Write(buf []byte) (int, error) {
ringLen := cap(rb.buf)
for i, b := range buf {
rb.buf[(rb.off+i)%ringLen] = b
}
rb.off = (rb.off + len(buf)) % ringLen
rb.l = rb.l + len(buf)
if rb.l > ringLen {
rb.l = ringLen
}
return len(buf), nil
}
var userAuthFile = filepath.Join(osutil.CamliConfigDir(), "masterbot-config.json")
type userAuth struct {
sync.Mutex // guards userPass map.
userPass map[string]string
configFile string
pollInterval time.Duration
lastModTime time.Time
}
func newUserAuth(configFile string) (*userAuth, error) {
ua := &userAuth{
configFile: configFile,
pollInterval: time.Minute,
}
if _, err := os.Stat(configFile); err != nil {
示例8: RunCommand
func (c *initCmd) RunCommand(args []string) error {
if len(args) > 0 {
return cmdmain.ErrUsage
}
if c.newKey && c.gpgkey != "" {
log.Fatal("--newkey and --gpgkey are mutually exclusive")
}
blobDir := path.Join(osutil.CamliConfigDir(), "keyblobs")
os.Mkdir(osutil.CamliConfigDir(), 0700)
os.Mkdir(blobDir, 0700)
var keyId string
var err error
secRing := osutil.IdentitySecretRing()
if c.newKey {
keyId, err = jsonsign.GenerateNewSecRing(secRing)
if err != nil {
return err
}
} else {
keyId, err = c.keyId(secRing)
if err != nil {
return err
}
}
if os.Getenv("GPG_AGENT_INFO") == "" {
log.Printf("No GPG_AGENT_INFO found in environment; you should setup gnupg-agent. camput might be annoying otherwise, if your private key is encrypted.")
}
pubArmor, err := c.getPublicKeyArmored(keyId)
if err != nil {
return err
}
bref := blobref.SHA1FromString(string(pubArmor))
keyBlobPath := path.Join(blobDir, bref.String()+".camli")
if err = ioutil.WriteFile(keyBlobPath, pubArmor, 0644); err != nil {
log.Fatalf("Error writing public key blob to %q: %v", keyBlobPath, err)
}
if ok, err := jsonsign.VerifyPublicKeyFile(keyBlobPath, keyId); !ok {
log.Fatalf("Error verifying public key at %q: %v", keyBlobPath, err)
}
log.Printf("Your Camlistore identity (your GPG public key's blobref) is: %s", bref.String())
configFilePath := osutil.UserClientConfigPath()
_, err = os.Stat(configFilePath)
if err == nil {
log.Fatalf("Config file %q already exists; quitting without touching it.", configFilePath)
}
if f, err := os.OpenFile(configFilePath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0600); err == nil {
defer f.Close()
m := make(map[string]interface{})
m["keyId"] = keyId // TODO(bradfitz): make this 'identity' to match server config?
m["publicKeyBlobref"] = bref.String() // TODO(bradfitz): not used anymore?
m["server"] = "http://localhost:3179/"
m["selfPubKeyDir"] = blobDir
m["auth"] = "localhost"
jsonBytes, err := json.MarshalIndent(m, "", " ")
if err != nil {
log.Fatalf("JSON serialization error: %v", err)
}
_, err = f.Write(jsonBytes)
if err != nil {
log.Fatalf("Error writing to %q: %v", configFilePath, err)
}
log.Printf("Wrote %q; modify as necessary.", configFilePath)
}
return nil
}
示例9: NewConfigDirFetcher
func NewConfigDirFetcher() *DirFetcher {
configDir := filepath.Join(osutil.CamliConfigDir(), "keyblobs")
return NewSimpleDirectoryFetcher(configDir)
}
示例10: loadMasterHosts
u, err := url.Parse(l)
if err != nil {
return nil, err
}
if u.Host == "" {
return nil, fmt.Errorf("URL missing Host: %q", l)
}
hosts = append(hosts, u.String())
}
if err := scanner.Err(); err != nil {
return nil, err
}
return hosts, nil
}
var masterHostsFile = filepath.Join(osutil.CamliConfigDir(), "builderbot-config")
func loadMasterHosts() error {
r, err := os.Open(masterHostsFile)
if err != nil {
return err
}
defer r.Close()
hosts, err := masterHostsReader(r)
if err != nil {
return err
}
if *masterHosts != "" {
*masterHosts += ","
}
示例11: ConfigFilePath
func ConfigFilePath() string {
return filepath.Join(osutil.CamliConfigDir(), "config")
}
示例12: RunCommand
func (c *initCmd) RunCommand(_ *Uploader, args []string) error {
if len(args) > 0 {
return ErrUsage
}
blobDir := path.Join(osutil.CamliConfigDir(), "keyblobs")
os.Mkdir(osutil.CamliConfigDir(), 0700)
os.Mkdir(blobDir, 0700)
keyId, err := c.keyId()
if err != nil {
return err
}
if os.Getenv("GPG_AGENT_INFO") == "" {
log.Printf("No GPG_AGENT_INFO found in environment; you should setup gnupg-agent. camput might be annoying otherwise, if your private key is encrypted.")
}
pubArmor, err := c.getPublicKeyArmored(keyId)
if err != nil {
return err
}
bref := blobref.SHA1FromString(string(pubArmor))
keyBlobPath := path.Join(blobDir, bref.String()+".camli")
if err = ioutil.WriteFile(keyBlobPath, pubArmor, 0644); err != nil {
log.Fatalf("Error writing public key blob to %q: %v", keyBlobPath, err)
}
if ok, err := jsonsign.VerifyPublicKeyFile(keyBlobPath, keyId); !ok {
log.Fatalf("Error verifying public key at %q: %v", keyBlobPath, err)
}
log.Printf("Your Camlistore identity (your GPG public key's blobref) is: %s", bref.String())
_, err = os.Stat(client.ConfigFilePath())
if err == nil {
log.Fatalf("Config file %q already exists; quitting without touching it.", client.ConfigFilePath())
}
if f, err := os.OpenFile(client.ConfigFilePath(), os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0600); err == nil {
defer f.Close()
m := make(map[string]interface{})
m["keyId"] = keyId // TODO(bradfitz): make this 'identity' to match server config?
m["publicKeyBlobref"] = bref.String() // TODO(bradfitz): not used anymore?
m["blobServer"] = "http://localhost:3179/"
m["selfPubKeyDir"] = blobDir
m["auth"] = "none"
blobPut := make([]map[string]string, 1)
blobPut[0] = map[string]string{
"alias": "local",
"host": "http://localhost:3179/",
"password": "",
}
m["blobPut"] = blobPut
blobGet := make([]map[string]string, 2)
blobGet[0] = map[string]string{
"alias": "keyblobs",
"path": blobDir,
}
blobGet[1] = map[string]string{
"alias": "local",
"host": "http://localhost:3179/",
"password": "",
}
m["blobGet"] = blobGet
jsonBytes, err := json.MarshalIndent(m, "", " ")
if err != nil {
log.Fatalf("JSON serialization error: %v", err)
}
_, err = f.Write(jsonBytes)
if err != nil {
log.Fatalf("Error writing to %q: %v", client.ConfigFilePath(), err)
}
log.Printf("Wrote %q; modify as necessary.", client.ConfigFilePath())
}
return nil
}