yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/hcs/shell/dbinstance_account.go (about)

     1  // Copyright 2019 Yunion
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package shell
    16  
    17  import (
    18  	huawei "yunion.io/x/cloudmux/pkg/multicloud/hcso"
    19  	"yunion.io/x/onecloud/pkg/util/shellutils"
    20  )
    21  
    22  func init() {
    23  	type DBInstanceIdOptions struct {
    24  		ID string `help:"DBInstance ID"`
    25  	}
    26  
    27  	shellutils.R(&DBInstanceIdOptions{}, "dbinstance-account-list", "Show dbinstance accounts", func(cli *huawei.SRegion, args *DBInstanceIdOptions) error {
    28  		accounts, err := cli.GetDBInstanceAccounts(args.ID)
    29  		if err != nil {
    30  			return err
    31  		}
    32  		printList(accounts, 0, 0, 0, nil)
    33  		return nil
    34  	})
    35  
    36  	type DBInstanceAccountDeleteOptions struct {
    37  		INSTANCE string
    38  		ACCOUNT  string
    39  	}
    40  
    41  	shellutils.R(&DBInstanceAccountDeleteOptions{}, "dbinstance-account-delete", "Delete dbinstance account", func(cli *huawei.SRegion, args *DBInstanceAccountDeleteOptions) error {
    42  		return cli.DeleteDBInstanceAccount(args.INSTANCE, args.ACCOUNT)
    43  	})
    44  
    45  	type DBInstanceAccountCreateOptions struct {
    46  		INSTANCE string
    47  		ACCOUNT  string
    48  		PASSWORD string
    49  	}
    50  
    51  	shellutils.R(&DBInstanceAccountCreateOptions{}, "dbinstance-account-create", "Create dbinstance account", func(cli *huawei.SRegion, args *DBInstanceAccountCreateOptions) error {
    52  		return cli.CreateDBInstanceAccount(args.INSTANCE, args.ACCOUNT, args.PASSWORD)
    53  	})
    54  
    55  	type DBInstanceAccountRevokePrivilegeOptions struct {
    56  		INSTANCE string
    57  		ACCOUNT  string
    58  		DATABASE string
    59  	}
    60  
    61  	shellutils.R(&DBInstanceAccountRevokePrivilegeOptions{}, "dbinstance-account-revoke-provilege", "Revoke dbinstance account privilege", func(cli *huawei.SRegion, args *DBInstanceAccountRevokePrivilegeOptions) error {
    62  		return cli.RevokeDBInstancePrivilege(args.INSTANCE, args.ACCOUNT, args.DATABASE)
    63  	})
    64  
    65  	type DBInstanceAccountGrantPrivilegeOptions struct {
    66  		INSTANCE  string
    67  		ACCOUNT   string
    68  		DATABASE  string
    69  		PRIVILEGE string `help:"database privilege" choices:"r|rw"`
    70  	}
    71  
    72  	shellutils.R(&DBInstanceAccountGrantPrivilegeOptions{}, "dbinstance-account-grant-provilege", "Grant dbinstance account privilege", func(cli *huawei.SRegion, args *DBInstanceAccountGrantPrivilegeOptions) error {
    73  		return cli.GrantDBInstancePrivilege(args.INSTANCE, args.ACCOUNT, args.DATABASE, args.PRIVILEGE)
    74  	})
    75  
    76  }