本文整理汇总了Golang中github.com/juju/juju/utils/ssh.ListKeys函数的典型用法代码示例。如果您正苦于以下问题:Golang ListKeys函数的具体用法?Golang ListKeys怎么用?Golang ListKeys使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ListKeys函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestMachineAgentRunsAuthorisedKeysWorker
func (s *MachineSuite) TestMachineAgentRunsAuthorisedKeysWorker(c *gc.C) {
// Start the machine agent.
m, _, _ := s.primeAgent(c, version.Current, state.JobHostUnits)
a := s.newAgent(c, m)
go func() { c.Check(a.Run(nil), gc.IsNil) }()
defer func() { c.Check(a.Stop(), gc.IsNil) }()
// Update the keys in the environment.
sshKey := sshtesting.ValidKeyOne.Key + " [email protected]"
err := s.BackingState.UpdateEnvironConfig(map[string]interface{}{"authorized-keys": sshKey}, nil, nil)
c.Assert(err, gc.IsNil)
// Wait for ssh keys file to be updated.
s.State.StartSync()
timeout := time.After(coretesting.LongWait)
sshKeyWithCommentPrefix := sshtesting.ValidKeyOne.Key + " Juju:[email protected]"
for {
select {
case <-timeout:
c.Fatalf("timeout while waiting for authorised ssh keys to change")
case <-time.After(coretesting.ShortWait):
keys, err := ssh.ListKeys(authenticationworker.SSHUser, ssh.FullKeys)
c.Assert(err, gc.IsNil)
keysStr := strings.Join(keys, "\n")
if sshKeyWithCommentPrefix != keysStr {
continue
}
return
}
}
}
开发者ID:klyachin,项目名称:juju,代码行数:31,代码来源:machine_test.go
示例2: SetUp
// SetUp is defined on the worker.NotifyWatchHandler interface.
func (kw *keyupdaterWorker) SetUp() (watcher.NotifyWatcher, error) {
// Record the keys Juju knows about.
// TODO(dfc)
jujuKeys, err := kw.st.AuthorisedKeys(kw.tag.String())
if err != nil {
return nil, errors.LoggedErrorf(logger, "reading Juju ssh keys for %q: %v", kw.tag, err)
}
kw.jujuKeys = set.NewStrings(jujuKeys...)
// Read the keys currently in ~/.ssh/authorised_keys.
sshKeys, err := ssh.ListKeys(SSHUser, ssh.FullKeys)
if err != nil {
return nil, errors.LoggedErrorf(logger, "reading ssh authorized keys for %q: %v", kw.tag, err)
}
// Record any keys not added by Juju.
for _, key := range sshKeys {
_, comment, err := ssh.KeyFingerprint(key)
// Also record keys which we cannot parse.
if err != nil || !strings.HasPrefix(comment, ssh.JujuCommentPrefix) {
kw.nonJujuKeys = append(kw.nonJujuKeys, key)
}
}
// Write out the ssh authorised keys file to match the current state of the world.
if err := kw.writeSSHKeys(jujuKeys); err != nil {
return nil, errors.LoggedErrorf(logger, "adding current Juju keys to ssh authorised keys: %v", err)
}
w, err := kw.st.WatchAuthorisedKeys(kw.tag.String())
if err != nil {
return nil, errors.LoggedErrorf(logger, "starting key updater worker: %v", err)
}
logger.Infof("%q key updater worker started", kw.tag)
return w, nil
}
开发者ID:klyachin,项目名称:juju,代码行数:35,代码来源:worker.go
示例3: TestAddNewKey
func (s *AuthorisedKeysKeysSuite) TestAddNewKey(c *gc.C) {
key := sshtesting.ValidKeyOne.Key + " [email protected]"
err := ssh.AddKeys(testSSHUser, key)
c.Assert(err, gc.IsNil)
actual, err := ssh.ListKeys(testSSHUser, ssh.FullKeys)
c.Assert(err, gc.IsNil)
c.Assert(actual, gc.DeepEquals, []string{key})
}
开发者ID:kapilt,项目名称:juju,代码行数:8,代码来源:authorisedkeys_test.go
示例4: TestListKeysFull
func (s *AuthorisedKeysKeysSuite) TestListKeysFull(c *gc.C) {
keys := []string{
sshtesting.ValidKeyOne.Key + " [email protected]",
sshtesting.ValidKeyTwo.Key + " [email protected]",
}
writeAuthKeysFile(c, keys)
actual, err := ssh.ListKeys(testSSHUser, ssh.FullKeys)
c.Assert(err, gc.IsNil)
c.Assert(actual, gc.DeepEquals, keys)
}
开发者ID:kapilt,项目名称:juju,代码行数:10,代码来源:authorisedkeys_test.go
示例5: TestDeleteKeys
func (s *AuthorisedKeysKeysSuite) TestDeleteKeys(c *gc.C) {
firstKey := sshtesting.ValidKeyOne.Key + " [email protected]"
anotherKey := sshtesting.ValidKeyTwo.Key
thirdKey := sshtesting.ValidKeyThree.Key + " [email protected]"
writeAuthKeysFile(c, []string{firstKey, anotherKey, thirdKey})
err := ssh.DeleteKeys(testSSHUser, "[email protected]", sshtesting.ValidKeyTwo.Fingerprint)
c.Assert(err, gc.IsNil)
actual, err := ssh.ListKeys(testSSHUser, ssh.FullKeys)
c.Assert(err, gc.IsNil)
c.Assert(actual, gc.DeepEquals, []string{thirdKey})
}
开发者ID:kapilt,项目名称:juju,代码行数:11,代码来源:authorisedkeys_test.go
示例6: TestListKeys
func (s *AuthorisedKeysKeysSuite) TestListKeys(c *gc.C) {
keys := []string{
sshtesting.ValidKeyOne.Key + " [email protected]",
sshtesting.ValidKeyTwo.Key,
}
writeAuthKeysFile(c, keys)
keys, err := ssh.ListKeys(testSSHUser, ssh.Fingerprints)
c.Assert(err, gc.IsNil)
c.Assert(
keys, gc.DeepEquals,
[]string{sshtesting.ValidKeyOne.Fingerprint + " ([email protected])", sshtesting.ValidKeyTwo.Fingerprint})
}
开发者ID:kapilt,项目名称:juju,代码行数:12,代码来源:authorisedkeys_test.go
示例7: TestAddMoreKeys
func (s *AuthorisedKeysKeysSuite) TestAddMoreKeys(c *gc.C) {
firstKey := sshtesting.ValidKeyOne.Key + " [email protected]"
writeAuthKeysFile(c, []string{firstKey})
moreKeys := []string{
sshtesting.ValidKeyTwo.Key + " [email protected]",
sshtesting.ValidKeyThree.Key + " [email protected]",
}
err := ssh.AddKeys(testSSHUser, moreKeys...)
c.Assert(err, gc.IsNil)
actual, err := ssh.ListKeys(testSSHUser, ssh.FullKeys)
c.Assert(err, gc.IsNil)
c.Assert(actual, gc.DeepEquals, append([]string{firstKey}, moreKeys...))
}
开发者ID:kapilt,项目名称:juju,代码行数:13,代码来源:authorisedkeys_test.go
示例8: TestReplaceKeys
func (s *AuthorisedKeysKeysSuite) TestReplaceKeys(c *gc.C) {
firstKey := sshtesting.ValidKeyOne.Key + " [email protected]"
anotherKey := sshtesting.ValidKeyTwo.Key
writeAuthKeysFile(c, []string{firstKey, anotherKey})
// replaceKey is created without a comment so test that
// ReplaceKeys handles keys without comments. This is
// because existing keys may not have a comment and
// ReplaceKeys is used to rewrite the entire authorized_keys
// file when adding new keys.
replaceKey := sshtesting.ValidKeyThree.Key
err := ssh.ReplaceKeys(testSSHUser, replaceKey)
c.Assert(err, gc.IsNil)
actual, err := ssh.ListKeys(testSSHUser, ssh.FullKeys)
c.Assert(err, gc.IsNil)
c.Assert(actual, gc.DeepEquals, []string{replaceKey})
}
开发者ID:kapilt,项目名称:juju,代码行数:17,代码来源:authorisedkeys_test.go
示例9: waitSSHKeys
func (s *workerSuite) waitSSHKeys(c *gc.C, expected []string) {
timeout := time.After(worstCase)
for {
select {
case <-timeout:
c.Fatalf("timeout while waiting for authoirsed ssh keys to change")
case <-time.After(coretesting.ShortWait):
keys, err := ssh.ListKeys(authenticationworker.SSHUser, ssh.FullKeys)
c.Assert(err, gc.IsNil)
keysStr := strings.Join(keys, "\n")
expectedStr := strings.Join(expected, "\n")
if expectedStr != keysStr {
continue
}
return
}
}
}
开发者ID:kapilt,项目名称:juju,代码行数:18,代码来源:worker_test.go
注:本文中的github.com/juju/juju/utils/ssh.ListKeys函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论