Exemple #1
0
func (command *commandUpload) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsUpload).opts
	keypair, err := keypairs.Create(command.Ctx.ServiceClient, opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(keypair)
}
func createServerKeyPair(t *testing.T, client *gophercloud.ServiceClient) *oskey.KeyPair {
	name := tools.RandomString("importedkey-", 8)
	pubkey := "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDlIQ3r+zd97kb9Hzmujd3V6pbO53eb3Go4q2E8iqVGWQfZTrFdL9KACJnqJIm9HmncfRkUTxE37hqeGCCv8uD+ZPmPiZG2E60OX1mGDjbbzAyReRwYWXgXHopggZTLak5k4mwZYaxwaufbVBDRn847e01lZnaXaszEToLM37NLw+uz29sl3TwYy2R0RGHPwPc160aWmdLjSyd1Nd4c9pvvOP/EoEuBjIC6NJJwg2Rvg9sjjx9jYj0QUgc8CqKLN25oMZ69kNJzlFylKRUoeeVr89txlR59yehJWk6Uw6lYFTdJmcmQOFVAJ12RMmS1hLWCM8UzAgtw+EDa0eqBxBDl smash@winter"

	k, err := keypairs.Create(client, oskey.CreateOpts{
		Name:      name,
		PublicKey: pubkey,
	}).Extract()
	th.AssertNoErr(t, err)

	return k
}
Exemple #3
0
func (command *commandGenerate) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsGenerate).opts
	keypair, err := keypairs.Create(command.Ctx.ServiceClient, opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	c := command.Ctx.CLIContext
	if c.IsSet("json") || c.IsSet("csv") || c.GlobalIsSet("json") || c.GlobalIsSet("csv") {
		resource.Result = structs.Map(keypair)
	} else {
		resource.Result = printGenerate(keypair)
	}
}
Exemple #4
0
func TestCreateKeyPair(t *testing.T) {
	client, err := newClient()
	th.AssertNoErr(t, err)

	name := tools.RandomString("createdkey-", 8)
	k, err := keypairs.Create(client, os.CreateOpts{Name: name}).Extract()
	th.AssertNoErr(t, err)
	defer deleteKeyPair(t, client, name)

	t.Logf("Created a new keypair:")
	t.Logf("        name=[%s]", k.Name)
	t.Logf(" fingerprint=[%s]", k.Fingerprint)
	t.Logf("   publickey=[%s]", tools.Elide(k.PublicKey))
	t.Logf("  privatekey=[%s]", tools.Elide(k.PrivateKey))
	t.Logf("      userid=[%s]", k.UserID)
}
Exemple #5
0
func TestImportKeyPair(t *testing.T) {
	client, err := newClient()
	th.AssertNoErr(t, err)

	name := tools.RandomString("importedkey-", 8)
	pubkey := "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDlIQ3r+zd97kb9Hzmujd3V6pbO53eb3Go4q2E8iqVGWQfZTrFdL9KACJnqJIm9HmncfRkUTxE37hqeGCCv8uD+ZPmPiZG2E60OX1mGDjbbzAyReRwYWXgXHopggZTLak5k4mwZYaxwaufbVBDRn847e01lZnaXaszEToLM37NLw+uz29sl3TwYy2R0RGHPwPc160aWmdLjSyd1Nd4c9pvvOP/EoEuBjIC6NJJwg2Rvg9sjjx9jYj0QUgc8CqKLN25oMZ69kNJzlFylKRUoeeVr89txlR59yehJWk6Uw6lYFTdJmcmQOFVAJ12RMmS1hLWCM8UzAgtw+EDa0eqBxBDl smash@winter"

	k, err := keypairs.Create(client, os.CreateOpts{
		Name:      name,
		PublicKey: pubkey,
	}).Extract()
	th.AssertNoErr(t, err)
	defer deleteKeyPair(t, client, name)

	th.CheckEquals(t, pubkey, k.PublicKey)
	th.CheckEquals(t, "", k.PrivateKey)

	t.Logf("Imported an existing keypair:")
	t.Logf("        name=[%s]", k.Name)
	t.Logf(" fingerprint=[%s]", k.Fingerprint)
	t.Logf("   publickey=[%s]", tools.Elide(k.PublicKey))
	t.Logf("  privatekey=[%s]", tools.Elide(k.PrivateKey))
	t.Logf("      userid=[%s]", k.UserID)
}