質問編集履歴

8

修正

2016/05/24 12:00

投稿

kensin93
kensin93

スコア8

test CHANGED
File without changes
test CHANGED
@@ -64,6 +64,8 @@
64
64
 
65
65
  $uri = '/';
66
66
 
67
+ $secretkey = 'シークレットキー';
68
+
67
69
 
68
70
 
69
71
  $params = [
@@ -98,7 +100,7 @@
98
100
 
99
101
 
100
102
 
101
- return base64_encode(hash_hmac('sha256', $string_to_sign, {シークレットキー}, true));
103
+ return base64_encode(hash_hmac('sha256', $string_to_sign, $secretkey, true));
102
104
 
103
105
  }
104
106
 

7

修正

2016/05/24 12:00

投稿

kensin93
kensin93

スコア8

test CHANGED
File without changes
test CHANGED
@@ -98,7 +98,7 @@
98
98
 
99
99
 
100
100
 
101
- return base64_encode(hash_hmac('sha256', $string_to_sign, self::SECRET, true));
101
+ return base64_encode(hash_hmac('sha256', $string_to_sign, {シークレットキー}, true));
102
102
 
103
103
  }
104
104
 

6

修正

2016/05/24 11:57

投稿

kensin93
kensin93

スコア8

test CHANGED
File without changes
test CHANGED
@@ -58,6 +58,14 @@
58
58
 
59
59
  private function _buildSignature() {
60
60
 
61
+
62
+
63
+ $domain = 'rdb.jp-east-1.api.cloud.nifty.com';
64
+
65
+ $uri = '/';
66
+
67
+
68
+
61
69
  $params = [
62
70
 
63
71
  'AccessKeyId' => 'アクセスキー',
@@ -86,7 +94,7 @@
86
94
 
87
95
 
88
96
 
89
- $string_to_sign = "GET\n" . self::DOMAIN . "\n" . self::ENDPOINT . "\n{$query}";
97
+ $string_to_sign = "GET\n" . $domain . "\n" . $uri . "\n".$query;
90
98
 
91
99
 
92
100
 

5

内容修正

2016/05/24 11:56

投稿

kensin93
kensin93

スコア8

test CHANGED
@@ -1 +1 @@
1
- niftyCloud クラウドAPI(RDB:NiftyGetMetricStatistics)で"SignatureDoesNotMatch"と怒られ
1
+ niftyCloud クラウドAPI(RDB:NiftyGetMetricStatistics)でエラーが返ってく
test CHANGED
File without changes

4

内容修正

2016/05/24 11:46

投稿

kensin93
kensin93

スコア8

test CHANGED
File without changes
test CHANGED
@@ -60,9 +60,9 @@
60
60
 
61
61
  $params = [
62
62
 
63
- 'AccessKeyId' => $this->_access_key,
63
+ 'AccessKeyId' => 'アクセスキー',
64
64
 
65
- 'Action' => self::ACTION,
65
+ 'Action' => 'NiftyGetMetricStatistics',
66
66
 
67
67
  'Dimensions.member.1.Name' => 'DBInstanceIdentifier',
68
68
 

3

内容修正

2016/05/24 10:39

投稿

kensin93
kensin93

スコア8

test CHANGED
File without changes
test CHANGED
@@ -58,35 +58,39 @@
58
58
 
59
59
  private function _buildSignature() {
60
60
 
61
- $domain = 'rdb.jp-east-1.api.cloud.nifty.com';
61
+ $params = [
62
62
 
63
+ 'AccessKeyId' => $this->_access_key,
64
+
65
+ 'Action' => self::ACTION,
66
+
67
+ 'Dimensions.member.1.Name' => 'DBInstanceIdentifier',
68
+
63
- $uri = '/api/services/NiftyCloud/'; // ここに何を入れるべきか不明
69
+ 'Dimensions.member.1.Value' => 'DBサーバー名',
70
+
71
+ 'MetricName' => 'メトリック名',
72
+
73
+ 'SignatureMethod' => 'HmacSHA256',
74
+
75
+ 'SignatureVersion' => 2
76
+
77
+ ];
64
78
 
65
79
 
66
80
 
67
- $params = [
81
+ ksort($params);
68
-
69
- 'AccessKeyId' => 'アクセスキー',
70
-
71
- 'Action' => 'NiftyGetMetricStatistics',
72
-
73
- 'SignatureMethod' => 'HmacSHA256',
74
-
75
- 'SignatureVersion' => 2
76
-
77
- ];
78
82
 
79
83
 
80
84
 
81
- $query = http_build_query($params);
85
+ $query = http_build_query($params);
82
86
 
83
87
 
84
88
 
85
- $string_to_sign = "GET\n".$domain."\n".$uri."\n".$query;
89
+ $string_to_sign = "GET\n" . self::DOMAIN . "\n" . self::ENDPOINT . "\n{$query}";
86
90
 
87
91
 
88
92
 
89
- return base64_encode(hash_hmac('sha256', $string_to_sign, 'シークレットキー', true));
93
+ return base64_encode(hash_hmac('sha256', $string_to_sign, self::SECRET, true));
90
94
 
91
95
  }
92
96
 
@@ -98,11 +102,7 @@
98
102
 
99
103
  ```
100
104
 
101
- SignatureDoesNotMatch
102
-
103
-
104
-
105
- The request signature we calculated does not match the signature you provided. Check your Secret Access Key and signing method. Consult the service documentation for details.
105
+ AccessDenied User: nrn:nifty:ma::******:user/{ユーザーID} is not authorized to perform
106
106
 
107
107
 
108
108
 
@@ -110,7 +110,31 @@
110
110
 
111
111
 
112
112
 
113
+ こちらのエラーの原因と解決策をご教示いただけると助かります。
114
+
115
+
116
+
117
+
118
+
119
+ また一点自信がない点はURLエンコードしたendpointのパス部分です。
120
+
121
+ 公式サイトの「URLエンコードしたendpointのパス部分」のサンプルは"/api/services/NiftyCloud/"と記載があり、今回の用途の場合ここに何を入れるべきか色々試しましたが、"/"で上記エラーが出て、その他思いつくパスを入力した場合は下記エラーが返ってきました。
122
+
123
+
124
+
125
+ ```
126
+
127
+ SignatureDoesNotMatch
128
+
129
+
130
+
131
+ The request signature we calculated does not match the signature you provided
132
+
133
+ ```
134
+
135
+
136
+
113
- まず今回の用途([クラウドAPI(RDB:NiftyGetMetricStatistics)](http://cloud.nifty.com/api/rdb/NiftyGetMetricStatistics.htm))でAPIを使用しSignatureを作成する場合、URLエンコードしたendpointのパス部分になにを入れるべきわかりません。
137
+ 今回の用途([クラウドAPI(RDB:NiftyGetMetricStatistics)](http://cloud.nifty.com/api/rdb/NiftyGetMetricStatistics.htm))でAPIを使用しSignatureを作成する場合、URLエンコードしたendpointのパス部分は"/"でいいのでしょう
114
138
 
115
139
 
116
140
 

2

文法修正

2016/05/24 10:37

投稿

kensin93
kensin93

スコア8

test CHANGED
File without changes
test CHANGED
@@ -114,4 +114,4 @@
114
114
 
115
115
 
116
116
 
117
- また、上記コードに間違いがあったり、不足しているパラメータ、他に確認すべきポイントなどございましたら教えていただけると助かります。
117
+ また、上記コードに間違いがあったり、他に確認すべきポイントなどございましたら教えていただけると助かります。

1

文法の修正

2016/05/24 10:15

投稿

kensin93
kensin93

スコア8

test CHANGED
File without changes
test CHANGED
@@ -110,4 +110,8 @@
110
110
 
111
111
 
112
112
 
113
- おそらくURLエンコードしたendpointのパス部分(/api/services/NiftyCloud/)が違うのかとは思うのですが、こちら今回の用途([クラウドAPI(RDB:NiftyGetMetricStatistics)](http://cloud.nifty.com/api/rdb/NiftyGetMetricStatistics.htm))でAPIを使用しSignatureを作成する場合、URLエンコードしたendpointのパス部分はどういったパスとりますでしょうか?また上記エラーの場合、他確認すべきポイントなどあれば教えていただけると助かりま
113
+ まず今回の用途([クラウドAPI(RDB:NiftyGetMetricStatistics)](http://cloud.nifty.com/api/rdb/NiftyGetMetricStatistics.htm))でAPIを使用しSignatureを作成する場合、URLエンコードしたendpointのパス部分なにを入れるべきかわかりません
114
+
115
+
116
+
117
+ また、上記コードに間違いがあったり、不足しているパラメータ、他に確認すべきポイントなどございましたら教えていただけると助かります。