2016-12-03 09:42:26 +00:00
|
|
|
// +-------------------------------------------------------------------------
|
|
|
|
// | Copyright (C) 2016 Yunify, Inc.
|
|
|
|
// +-------------------------------------------------------------------------
|
|
|
|
// | Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// | you may not use this work except in compliance with the License.
|
|
|
|
// | You may obtain a copy of the License in the LICENSE file, or at:
|
|
|
|
// |
|
|
|
|
// | http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
// |
|
|
|
|
// | Unless required by applicable law or agreed to in writing, software
|
|
|
|
// | distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// | See the License for the specific language governing permissions and
|
|
|
|
// | limitations under the License.
|
|
|
|
// +-------------------------------------------------------------------------
|
|
|
|
|
2016-12-08 13:02:38 +00:00
|
|
|
package service
|
2016-12-03 09:42:26 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/yunify/qingcloud-sdk-go/config"
|
|
|
|
"github.com/yunify/qingcloud-sdk-go/request"
|
|
|
|
"github.com/yunify/qingcloud-sdk-go/request/data"
|
2017-01-05 14:03:55 +00:00
|
|
|
"github.com/yunify/qingcloud-sdk-go/request/errors"
|
2016-12-03 09:42:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ fmt.State
|
|
|
|
var _ time.Time
|
|
|
|
|
|
|
|
type KeyPairService struct {
|
|
|
|
Config *config.Config
|
|
|
|
Properties *KeyPairServiceProperties
|
|
|
|
}
|
|
|
|
|
|
|
|
type KeyPairServiceProperties struct {
|
|
|
|
// QingCloud Zone ID
|
2017-01-05 14:03:55 +00:00
|
|
|
Zone *string `json:"zone" name:"zone"` // Required
|
2016-12-03 09:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *QingCloudService) KeyPair(zone string) (*KeyPairService, error) {
|
|
|
|
properties := &KeyPairServiceProperties{
|
2017-01-05 14:03:55 +00:00
|
|
|
Zone: &zone,
|
2016-12-03 09:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &KeyPairService{Config: s.Config, Properties: properties}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Documentation URL: https://docs.qingcloud.com/api/keypair/attach_key_pairs.html
|
|
|
|
func (s *KeyPairService) AttachKeyPairs(i *AttachKeyPairsInput) (*AttachKeyPairsOutput, error) {
|
|
|
|
if i == nil {
|
|
|
|
i = &AttachKeyPairsInput{}
|
|
|
|
}
|
|
|
|
o := &data.Operation{
|
|
|
|
Config: s.Config,
|
|
|
|
Properties: s.Properties,
|
|
|
|
APIName: "AttachKeyPairs",
|
|
|
|
RequestMethod: "GET",
|
|
|
|
}
|
|
|
|
|
|
|
|
x := &AttachKeyPairsOutput{}
|
|
|
|
r, err := request.New(o, i, x)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = r.Send()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return x, err
|
|
|
|
}
|
|
|
|
|
|
|
|
type AttachKeyPairsInput struct {
|
2017-01-05 14:03:55 +00:00
|
|
|
Instances []*string `json:"instances" name:"instances" location:"params"` // Required
|
|
|
|
KeyPairs []*string `json:"keypairs" name:"keypairs" location:"params"` // Required
|
2016-12-03 09:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *AttachKeyPairsInput) Validate() error {
|
|
|
|
|
|
|
|
if len(v.Instances) == 0 {
|
2017-01-05 14:03:55 +00:00
|
|
|
return errors.ParameterRequiredError{
|
2016-12-03 09:42:26 +00:00
|
|
|
ParameterName: "Instances",
|
|
|
|
ParentName: "AttachKeyPairsInput",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(v.KeyPairs) == 0 {
|
2017-01-05 14:03:55 +00:00
|
|
|
return errors.ParameterRequiredError{
|
2016-12-03 09:42:26 +00:00
|
|
|
ParameterName: "KeyPairs",
|
|
|
|
ParentName: "AttachKeyPairsInput",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type AttachKeyPairsOutput struct {
|
2017-01-05 14:03:55 +00:00
|
|
|
Message *string `json:"message" name:"message"`
|
|
|
|
Action *string `json:"action" name:"action" location:"elements"`
|
|
|
|
JobID *string `json:"job_id" name:"job_id" location:"elements"`
|
|
|
|
RetCode *int `json:"ret_code" name:"ret_code" location:"elements"`
|
2016-12-03 09:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Documentation URL: https://docs.qingcloud.com/api/keypair/create_key_pairs.html
|
|
|
|
func (s *KeyPairService) CreateKeyPair(i *CreateKeyPairInput) (*CreateKeyPairOutput, error) {
|
|
|
|
if i == nil {
|
|
|
|
i = &CreateKeyPairInput{}
|
|
|
|
}
|
|
|
|
o := &data.Operation{
|
|
|
|
Config: s.Config,
|
|
|
|
Properties: s.Properties,
|
|
|
|
APIName: "CreateKeyPair",
|
|
|
|
RequestMethod: "GET",
|
|
|
|
}
|
|
|
|
|
|
|
|
x := &CreateKeyPairOutput{}
|
|
|
|
r, err := request.New(o, i, x)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = r.Send()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return x, err
|
|
|
|
}
|
|
|
|
|
|
|
|
type CreateKeyPairInput struct {
|
|
|
|
|
|
|
|
// EncryptMethod's available values: ssh-rsa, ssh-dss
|
2017-01-05 14:03:55 +00:00
|
|
|
EncryptMethod *string `json:"encrypt_method" name:"encrypt_method" default:"ssh-rsa" location:"params"`
|
|
|
|
KeyPairName *string `json:"keypair_name" name:"keypair_name" location:"params"`
|
2016-12-03 09:42:26 +00:00
|
|
|
// Mode's available values: system, user
|
2017-01-05 14:03:55 +00:00
|
|
|
Mode *string `json:"mode" name:"mode" default:"system" location:"params"`
|
|
|
|
PublicKey *string `json:"public_key" name:"public_key" location:"params"`
|
2016-12-03 09:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *CreateKeyPairInput) Validate() error {
|
|
|
|
|
2017-01-05 14:03:55 +00:00
|
|
|
if v.EncryptMethod != nil {
|
2016-12-03 09:42:26 +00:00
|
|
|
encryptMethodValidValues := []string{"ssh-rsa", "ssh-dss"}
|
2017-01-05 14:03:55 +00:00
|
|
|
encryptMethodParameterValue := fmt.Sprint(*v.EncryptMethod)
|
2016-12-03 09:42:26 +00:00
|
|
|
|
|
|
|
encryptMethodIsValid := false
|
|
|
|
for _, value := range encryptMethodValidValues {
|
|
|
|
if value == encryptMethodParameterValue {
|
|
|
|
encryptMethodIsValid = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !encryptMethodIsValid {
|
2017-01-05 14:03:55 +00:00
|
|
|
return errors.ParameterValueNotAllowedError{
|
2016-12-03 09:42:26 +00:00
|
|
|
ParameterName: "EncryptMethod",
|
|
|
|
ParameterValue: encryptMethodParameterValue,
|
|
|
|
AllowedValues: encryptMethodValidValues,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-05 14:03:55 +00:00
|
|
|
if v.Mode != nil {
|
2016-12-03 09:42:26 +00:00
|
|
|
modeValidValues := []string{"system", "user"}
|
2017-01-05 14:03:55 +00:00
|
|
|
modeParameterValue := fmt.Sprint(*v.Mode)
|
2016-12-03 09:42:26 +00:00
|
|
|
|
|
|
|
modeIsValid := false
|
|
|
|
for _, value := range modeValidValues {
|
|
|
|
if value == modeParameterValue {
|
|
|
|
modeIsValid = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !modeIsValid {
|
2017-01-05 14:03:55 +00:00
|
|
|
return errors.ParameterValueNotAllowedError{
|
2016-12-03 09:42:26 +00:00
|
|
|
ParameterName: "Mode",
|
|
|
|
ParameterValue: modeParameterValue,
|
|
|
|
AllowedValues: modeValidValues,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type CreateKeyPairOutput struct {
|
2017-01-05 14:03:55 +00:00
|
|
|
Message *string `json:"message" name:"message"`
|
|
|
|
Action *string `json:"action" name:"action" location:"elements"`
|
|
|
|
KeyPairID *string `json:"keypair_id" name:"keypair_id" location:"elements"`
|
|
|
|
PrivateKey *string `json:"private_key" name:"private_key" location:"elements"`
|
|
|
|
RetCode *int `json:"ret_code" name:"ret_code" location:"elements"`
|
2016-12-03 09:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Documentation URL: https://docs.qingcloud.com/api/keypair/delete_key_pairs.html
|
|
|
|
func (s *KeyPairService) DeleteKeyPairs(i *DeleteKeyPairsInput) (*DeleteKeyPairsOutput, error) {
|
|
|
|
if i == nil {
|
|
|
|
i = &DeleteKeyPairsInput{}
|
|
|
|
}
|
|
|
|
o := &data.Operation{
|
|
|
|
Config: s.Config,
|
|
|
|
Properties: s.Properties,
|
|
|
|
APIName: "DeleteKeyPairs",
|
|
|
|
RequestMethod: "GET",
|
|
|
|
}
|
|
|
|
|
|
|
|
x := &DeleteKeyPairsOutput{}
|
|
|
|
r, err := request.New(o, i, x)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = r.Send()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return x, err
|
|
|
|
}
|
|
|
|
|
|
|
|
type DeleteKeyPairsInput struct {
|
2017-01-05 14:03:55 +00:00
|
|
|
KeyPairs []*string `json:"keypairs" name:"keypairs" location:"params"` // Required
|
2016-12-03 09:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *DeleteKeyPairsInput) Validate() error {
|
|
|
|
|
|
|
|
if len(v.KeyPairs) == 0 {
|
2017-01-05 14:03:55 +00:00
|
|
|
return errors.ParameterRequiredError{
|
2016-12-03 09:42:26 +00:00
|
|
|
ParameterName: "KeyPairs",
|
|
|
|
ParentName: "DeleteKeyPairsInput",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type DeleteKeyPairsOutput struct {
|
2017-01-05 14:03:55 +00:00
|
|
|
Message *string `json:"message" name:"message"`
|
|
|
|
Action *string `json:"action" name:"action" location:"elements"`
|
|
|
|
KeyPairs []*string `json:"keypairs" name:"keypairs" location:"elements"`
|
|
|
|
RetCode *int `json:"ret_code" name:"ret_code" location:"elements"`
|
2016-12-03 09:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Documentation URL: https://docs.qingcloud.com/api/keypair/describe_key_pairs.html
|
|
|
|
func (s *KeyPairService) DescribeKeyPairs(i *DescribeKeyPairsInput) (*DescribeKeyPairsOutput, error) {
|
|
|
|
if i == nil {
|
|
|
|
i = &DescribeKeyPairsInput{}
|
|
|
|
}
|
|
|
|
o := &data.Operation{
|
|
|
|
Config: s.Config,
|
|
|
|
Properties: s.Properties,
|
|
|
|
APIName: "DescribeKeyPairs",
|
|
|
|
RequestMethod: "GET",
|
|
|
|
}
|
|
|
|
|
|
|
|
x := &DescribeKeyPairsOutput{}
|
|
|
|
r, err := request.New(o, i, x)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = r.Send()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return x, err
|
|
|
|
}
|
|
|
|
|
|
|
|
type DescribeKeyPairsInput struct {
|
|
|
|
|
|
|
|
// EncryptMethod's available values: ssh-rsa, ssh-dss
|
2017-01-05 14:03:55 +00:00
|
|
|
EncryptMethod *string `json:"encrypt_method" name:"encrypt_method" location:"params"`
|
|
|
|
InstanceID *string `json:"instance_id" name:"instance_id" location:"params"`
|
|
|
|
KeyPairs []*string `json:"keypairs" name:"keypairs" location:"params"`
|
|
|
|
Limit *int `json:"limit" name:"limit" default:"20" location:"params"`
|
|
|
|
Offset *int `json:"offset" name:"offset" default:"0" location:"params"`
|
2018-08-16 08:13:35 +00:00
|
|
|
Owner *string `json:"owner" name:"owner" location:"params"`
|
2019-07-14 02:27:58 +00:00
|
|
|
ProjectID *string `json:"project_id" name:"project_id" location:"params"`
|
2017-01-05 14:03:55 +00:00
|
|
|
SearchWord *string `json:"search_word" name:"search_word" location:"params"`
|
|
|
|
Tags []*string `json:"tags" name:"tags" location:"params"`
|
|
|
|
Verbose *int `json:"verbose" name:"verbose" default:"0" location:"params"`
|
2016-12-03 09:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *DescribeKeyPairsInput) Validate() error {
|
|
|
|
|
2017-01-05 14:03:55 +00:00
|
|
|
if v.EncryptMethod != nil {
|
2016-12-03 09:42:26 +00:00
|
|
|
encryptMethodValidValues := []string{"ssh-rsa", "ssh-dss"}
|
2017-01-05 14:03:55 +00:00
|
|
|
encryptMethodParameterValue := fmt.Sprint(*v.EncryptMethod)
|
2016-12-03 09:42:26 +00:00
|
|
|
|
|
|
|
encryptMethodIsValid := false
|
|
|
|
for _, value := range encryptMethodValidValues {
|
|
|
|
if value == encryptMethodParameterValue {
|
|
|
|
encryptMethodIsValid = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !encryptMethodIsValid {
|
2017-01-05 14:03:55 +00:00
|
|
|
return errors.ParameterValueNotAllowedError{
|
2016-12-03 09:42:26 +00:00
|
|
|
ParameterName: "EncryptMethod",
|
|
|
|
ParameterValue: encryptMethodParameterValue,
|
|
|
|
AllowedValues: encryptMethodValidValues,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type DescribeKeyPairsOutput struct {
|
2017-01-05 14:03:55 +00:00
|
|
|
Message *string `json:"message" name:"message"`
|
|
|
|
Action *string `json:"action" name:"action" location:"elements"`
|
2016-12-03 09:42:26 +00:00
|
|
|
KeyPairSet []*KeyPair `json:"keypair_set" name:"keypair_set" location:"elements"`
|
2017-01-05 14:03:55 +00:00
|
|
|
RetCode *int `json:"ret_code" name:"ret_code" location:"elements"`
|
|
|
|
TotalCount *int `json:"total_count" name:"total_count" location:"elements"`
|
2016-12-03 09:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Documentation URL: https://docs.qingcloud.com/api/keypair/detach_key_pairs.html
|
|
|
|
func (s *KeyPairService) DetachKeyPairs(i *DetachKeyPairsInput) (*DetachKeyPairsOutput, error) {
|
|
|
|
if i == nil {
|
|
|
|
i = &DetachKeyPairsInput{}
|
|
|
|
}
|
|
|
|
o := &data.Operation{
|
|
|
|
Config: s.Config,
|
|
|
|
Properties: s.Properties,
|
|
|
|
APIName: "DetachKeyPairs",
|
|
|
|
RequestMethod: "GET",
|
|
|
|
}
|
|
|
|
|
|
|
|
x := &DetachKeyPairsOutput{}
|
|
|
|
r, err := request.New(o, i, x)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = r.Send()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return x, err
|
|
|
|
}
|
|
|
|
|
|
|
|
type DetachKeyPairsInput struct {
|
2017-01-05 14:03:55 +00:00
|
|
|
Instances []*string `json:"instances" name:"instances" location:"params"` // Required
|
|
|
|
KeyPairs []*string `json:"keypairs" name:"keypairs" location:"params"` // Required
|
2016-12-03 09:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *DetachKeyPairsInput) Validate() error {
|
|
|
|
|
|
|
|
if len(v.Instances) == 0 {
|
2017-01-05 14:03:55 +00:00
|
|
|
return errors.ParameterRequiredError{
|
2016-12-03 09:42:26 +00:00
|
|
|
ParameterName: "Instances",
|
|
|
|
ParentName: "DetachKeyPairsInput",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(v.KeyPairs) == 0 {
|
2017-01-05 14:03:55 +00:00
|
|
|
return errors.ParameterRequiredError{
|
2016-12-03 09:42:26 +00:00
|
|
|
ParameterName: "KeyPairs",
|
|
|
|
ParentName: "DetachKeyPairsInput",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type DetachKeyPairsOutput struct {
|
2017-01-05 14:03:55 +00:00
|
|
|
Message *string `json:"message" name:"message"`
|
|
|
|
Action *string `json:"action" name:"action" location:"elements"`
|
|
|
|
JobID *string `json:"job_id" name:"job_id" location:"elements"`
|
|
|
|
RetCode *int `json:"ret_code" name:"ret_code" location:"elements"`
|
2016-12-03 09:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Documentation URL: https://docs.qingcloud.com/api/keypair/modify_key_pair_attributes.html
|
|
|
|
func (s *KeyPairService) ModifyKeyPairAttributes(i *ModifyKeyPairAttributesInput) (*ModifyKeyPairAttributesOutput, error) {
|
|
|
|
if i == nil {
|
|
|
|
i = &ModifyKeyPairAttributesInput{}
|
|
|
|
}
|
|
|
|
o := &data.Operation{
|
|
|
|
Config: s.Config,
|
|
|
|
Properties: s.Properties,
|
|
|
|
APIName: "ModifyKeyPairAttributes",
|
|
|
|
RequestMethod: "GET",
|
|
|
|
}
|
|
|
|
|
|
|
|
x := &ModifyKeyPairAttributesOutput{}
|
|
|
|
r, err := request.New(o, i, x)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = r.Send()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return x, err
|
|
|
|
}
|
|
|
|
|
|
|
|
type ModifyKeyPairAttributesInput struct {
|
2017-01-05 14:03:55 +00:00
|
|
|
Description *string `json:"description" name:"description" location:"params"`
|
|
|
|
KeyPair *string `json:"keypair" name:"keypair" location:"params"` // Required
|
|
|
|
KeyPairName *string `json:"keypair_name" name:"keypair_name" location:"params"`
|
2016-12-03 09:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *ModifyKeyPairAttributesInput) Validate() error {
|
|
|
|
|
2017-01-05 14:03:55 +00:00
|
|
|
if v.KeyPair == nil {
|
|
|
|
return errors.ParameterRequiredError{
|
2016-12-03 09:42:26 +00:00
|
|
|
ParameterName: "KeyPair",
|
|
|
|
ParentName: "ModifyKeyPairAttributesInput",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type ModifyKeyPairAttributesOutput struct {
|
2017-01-05 14:03:55 +00:00
|
|
|
Message *string `json:"message" name:"message"`
|
|
|
|
Action *string `json:"action" name:"action" location:"elements"`
|
|
|
|
RetCode *int `json:"ret_code" name:"ret_code" location:"elements"`
|
2016-12-03 09:42:26 +00:00
|
|
|
}
|