You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

97 lines
2.5 KiB

  1. package rds
  2. import (
  3. "encoding/xml"
  4. "github.com/goamz/goamz/aws"
  5. "log"
  6. "net/http/httputil"
  7. "strconv"
  8. )
  9. const debug = false
  10. const (
  11. ServiceName = "rds"
  12. ApiVersion = "2013-09-09"
  13. )
  14. // The RDS type encapsulates operations within a specific EC2 region.
  15. type RDS struct {
  16. Service aws.AWSService
  17. }
  18. // New creates a new RDS Client.
  19. func New(auth aws.Auth, region aws.Region) (*RDS, error) {
  20. service, err := aws.NewService(auth, region.RDSEndpoint)
  21. if err != nil {
  22. return nil, err
  23. }
  24. return &RDS{
  25. Service: service,
  26. }, nil
  27. }
  28. // ----------------------------------------------------------------------------
  29. // Request dispatching logic.
  30. // query dispatches a request to the RDS API signed with a version 2 signature
  31. func (rds *RDS) query(method, path string, params map[string]string, resp interface{}) error {
  32. // Add basic RDS param
  33. params["Version"] = ApiVersion
  34. r, err := rds.Service.Query(method, path, params)
  35. if err != nil {
  36. return err
  37. }
  38. defer r.Body.Close()
  39. if debug {
  40. dump, _ := httputil.DumpResponse(r, true)
  41. log.Printf("response:\n")
  42. log.Printf("%v\n}\n", string(dump))
  43. }
  44. if r.StatusCode != 200 {
  45. return rds.Service.BuildError(r)
  46. }
  47. err = xml.NewDecoder(r.Body).Decode(resp)
  48. return err
  49. }
  50. // ----------------------------------------------------------------------------
  51. // API methods and corresponding response types.
  52. // Response to a DescribeDBInstances request
  53. //
  54. // See http://goo.gl/KSPlAl for more details.
  55. type DescribeDBInstancesResponse struct {
  56. DBInstances []DBInstance `xml:"DescribeDBInstancesResult>DBInstances>DBInstance"` // The list of database instances
  57. Marker string `xml:"DescribeDBInstancesResult>Marker"` // An optional pagination token provided by a previous request
  58. RequestId string `xml:"ResponseMetadata>RequestId"`
  59. }
  60. // DescribeDBInstances - Returns a description of each Database Instance
  61. // Supports pagination by using the "Marker" parameter, and "maxRecords" for subsequent calls
  62. // Unfortunately RDS does not currently support filtering
  63. //
  64. // See http://goo.gl/lzZMyz for more details.
  65. func (rds *RDS) DescribeDBInstances(id string, maxRecords int, marker string) (*DescribeDBInstancesResponse, error) {
  66. params := aws.MakeParams("DescribeDBInstances")
  67. if id != "" {
  68. params["DBInstanceIdentifier"] = id
  69. }
  70. if maxRecords != 0 {
  71. params["MaxRecords"] = strconv.Itoa(maxRecords)
  72. }
  73. if marker != "" {
  74. params["Marker"] = marker
  75. }
  76. resp := &DescribeDBInstancesResponse{}
  77. err := rds.query("POST", "/", params, resp)
  78. return resp, err
  79. }