4 * Copyright 2016 RIFT.IO Inc
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import $ from 'jquery';
20 let Utils
= require('utils/utils.js');
21 let rw
= require('utils/rw.js');
22 const API_SERVER
= require('utils/rw.js').getSearchParams(window
.location
).api_server
;
23 const API_PORT
= require('utils/rw.js').getSearchParams(window
.location
).api_port
;
24 export default function(Alt
){
25 const Actions
= Alt
.actions
.global
;
29 return new Promise((resolve
,reject
) => {
31 url
: 'api/ssh-key?api_server=' + API_SERVER
,
33 beforeSend
: Utils
.addAuthorizationStub
,
34 success: function (data
) {
37 }).fail(function(xhr
){
39 //Authentication and the handling of fail states should be wrapped up into a connection class.
40 Utils
.checkAuthentication(xhr
.status
);
44 loading
: Actions
.getSshKeyLoading
,
45 success
: Actions
.getSshKeySuccess
,
46 error
: Actions
.getSshKeyError
49 remote (state
, pair
) {
50 return new Promise((resolve
, reject
) => {
52 url
: 'api/ssh-key?api_server=' + API_SERVER
,
54 beforeSend
: Utils
.addAuthorizationStub
,
58 success: function (data
) {
61 error: function (err
) {
62 console
.log('There was an error saving the ssh key')
64 }).fail(function(xhr
){
65 //Authentication and the handling of fail states should be wrapped up into a connection class.
66 Utils
.checkAuthentication(xhr
.status
);
71 loading
: Actions
.saveSshKeyLoading
,
72 success
: Actions
.saveSshKeySuccess
,
73 error
: Actions
.saveSshKeyError
76 remote (state
, pair
) {
77 return new Promise((resolve
, reject
) => {
79 url
: 'api/ssh-key?api_server=' + API_SERVER
,
81 beforeSend
: Utils
.addAuthorizationStub
,
85 success: function (data
) {
88 error: function (err
) {
89 console
.log('There was an error updating the ssh key')
91 }).fail(function(xhr
){
92 //Authentication and the handling of fail states should be wrapped up into a connection class.
93 Utils
.checkAuthentication(xhr
.status
);
98 loading
: Actions
.saveSshKeyLoading
,
99 success
: Actions
.updateSshKeySuccess
,
100 error
: Actions
.saveSshKeyError
103 remote (state
, name
) {
104 return new Promise((resolve
, reject
) => {
106 url
: 'api/ssh-key/'+ encodeURI(name
) + '?api_server=' + API_SERVER
,
108 beforeSend
: Utils
.addAuthorizationStub
,
109 success: function (data
) {
115 error: function (err
) {
116 console
.log('There was an error updating the ssh key')
118 }).fail(function(xhr
){
119 //Authentication and the handling of fail states should be wrapped up into a connection class.
120 Utils
.checkAuthentication(xhr
.status
);
125 loading
: Actions
.saveSshKeyLoading
,
126 success
: Actions
.deleteSshKeySuccess
,
127 error
: Actions
.saveSshKeyError