2016-10-10 18:37:26 +03:00
const RoleType = require ( '../types/role' ) ;
const api = require ( '../../api' ) ;
const {
GraphQLNonNull ,
GraphQLString ,
GraphQLID ,
GraphQLList
} = require ( 'graphql' ) ;
module . exports . createRole = {
type : RoleType ,
description : 'Create a new role for your account' ,
args : {
name : {
type : new GraphQLNonNull ( GraphQLString ) ,
2017-04-27 21:26:15 +03:00
description : "The role's name"
2016-10-10 18:37:26 +03:00
} ,
policies : {
type : new GraphQLList ( GraphQLString ) ,
2017-04-27 21:26:15 +03:00
description : "This account's policies to be given to this role (Optional)"
2016-10-10 18:37:26 +03:00
} ,
members : {
type : new GraphQLList ( GraphQLString ) ,
2017-06-12 01:58:22 +03:00
description :
"This account's user logins to be added to this role (Optional)"
2016-10-10 18:37:26 +03:00
} ,
2017-05-18 21:21:33 +03:00
defaultMembers : {
2016-10-10 18:37:26 +03:00
type : new GraphQLList ( GraphQLString ) ,
2017-06-12 01:58:22 +03:00
description :
"This account's user logins to be added to this role and have it enabled by default (Optional)"
2016-10-10 18:37:26 +03:00
}
} ,
resolve : ( root , args ) => {
return api . roles . create ( args ) ;
}
} ;
module . exports . updateRole = {
type : RoleType ,
description : 'Modifies an account role. Anything but id can be modified' ,
args : {
id : {
type : new GraphQLNonNull ( GraphQLID )
} ,
name : {
type : GraphQLString ,
2017-04-27 21:26:15 +03:00
description : "The role's name"
2016-10-10 18:37:26 +03:00
} ,
policies : {
type : new GraphQLList ( GraphQLString ) ,
2017-04-27 21:26:15 +03:00
description : "This account's policies to be given to this role (Optional)"
2016-10-10 18:37:26 +03:00
} ,
members : {
type : new GraphQLList ( GraphQLString ) ,
2017-06-12 01:58:22 +03:00
description :
"This account's user logins to be added to this role (Optional)"
2016-10-10 18:37:26 +03:00
} ,
2017-05-18 21:21:33 +03:00
defaultMembers : {
2016-10-10 18:37:26 +03:00
type : new GraphQLList ( GraphQLString ) ,
2017-06-12 01:58:22 +03:00
description :
"This account's user logins to be added to this role and have it enabled by default (Optional)"
2016-10-10 18:37:26 +03:00
}
} ,
resolve : ( root , args ) => {
return api . roles . update ( args ) ;
}
} ;
module . exports . deleteRole = {
type : GraphQLID ,
description : 'Remove a role' ,
args : {
id : {
type : new GraphQLNonNull ( GraphQLID )
}
} ,
resolve : ( root , args ) => {
return api . roles . destroy ( args ) . then ( ( ) => {
return args . id ;
} ) ;
}
} ;
module . exports . setRoleTags = {
type : RoleType . tag ,
2017-06-12 01:58:22 +03:00
description :
"Sets the given role tags to the provided resource path. resource_path can be the path to any of the CloudAPI resources described in this document: account, keys, users, roles, policies, user's ssh keys, datacenters, images, packages, instances, analytics, instrumentations, firewall rules and networks." ,
2016-10-10 18:37:26 +03:00
args : {
resource : {
type : new GraphQLNonNull ( GraphQLString ) ,
description : 'The resource type e.g. `machines`, `policies`...'
} ,
id : {
type : GraphQLID ,
description : 'The resource id'
} ,
role : {
type : new GraphQLNonNull ( new GraphQLList ( GraphQLString ) ) ,
description : 'The list role-tags to be added to this resource'
}
} ,
resolve : ( root , args ) => {
2017-04-27 21:26:15 +03:00
const { set } = api . roles ;
2016-10-10 18:37:26 +03:00
return set ( args ) ;
}
} ;