How to access init.js file

workspace

#1

Hi,

I have created one workspace and I want to put one alert statement in init.js file, how can it possible through shell scritping(I mean through automation)

Siva.


#2

Hi,
Init.js is not stored in a file, it is in a database, and only way to modify it is to have password and username of a user for whom you want to modify it


#3

I have username and password then how can I put my statements in init.js using services (I mean using curl command)


#4

you can do it by using the code from https://github.com/c9/core/blob/master/plugins/c9.cli/auth.bootstrap.js, and inspecting network requests in browser devtools.

# get token using password
token=$(curl  https://c9.io/api/nc/auth -d '{"username": "'$USERNAME'", "password": "'$PASSWORD'", "client_id": "cli"}' -H "content-type: application/json"); echo $token      

# get settings
settings="$(curl https://api.c9.io/settings/user?access_token=$token -X GET)"

# script tht we want to add
script="alert(1)"

# add the script to settings
settings="$(node -p "
    s=JSON.parse(process.argv[1] || '{}');
    if (s.config == null) s.config = {};
    if (s.config['init.js'] == null) s.config['init.js']= {};
    s.config['init.js']['json()'] = '$script';
    JSON.stringify(s)" "$settings")"

# save settings
curl https://api.c9.io/settings/user?access_token=$token -X PUT  -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Accept: application/json' --data "settings=$settings"

# get settings again and verify that everything went well
curl https://api.c9.io/settings/user?access_token=$token -X GET


How can I confirm : workspace shared properly using curl command