Is there a way to add users automatically into gitlab? - ruby-on-rails

I've got a gitlab running on server. For now, I've also got just a list of users and emails needed to be add into gitlab. Is there a way to do this automatically? (i.e. by script/service)

You can use the GitLab API to create users in a script. Recent versions of curl can url-encode POST data for you. Otherwise spaces will have to be %20 and --data instead of --data-urlencode.
curl --header "PRIVATE-TOKEN: QVy1PB7sTxfy4pqfZM1U" --data-urlencode "email=jon#doe.com&password=defaultpassword&username=jdoe&name=Jon Doe" "http://example.com/api/v3/users"
Curl is the path of least resistance with your preferred shell language (in my case Bash). If you don't want to use curl to script creating your users there are numerous libraries for different languages to interact with the GitLab API. Take your pick. Popular libraries include:
Java - java-gitlab-api
PHP - php-gitlab-api
Python - pyapi-gitlab, python-gitlab, or python-gitlab3
Ruby - Gitlab wrapper
I'm sure there are many more API libs for other languages just google for your preferred language and include GitLab API as part of the query.

If it is possible (not tested yet), it could have been done through the gitlab-shell library, which exposes the API of gitlab.
But adding a user isn't part of its API yet (it only add ssh keys).
Issue 1942 does mention there is an API in gitlab itself.
You can take example on tester like spec/features/gitlab_flavored_markdown_spec.rb:
require 'spec_helper'
describe "GitLab Flavored Markdown" do
let(:project) { create(:project_with_code) }
let(:issue) { create(:issue, project: project) }
let(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let(:fred) do
u = create(:user, name: "fred")
project.team << [u, :master]
u
end

cli-gitlab installed through npm is working pretty well for me for both LDAP (AD) and local users. It saves the token of the 'admin' user which makes it a lot easier to script/automate things.

Related

Add a URL path prefix to artifactory installation (Docker)

I'm running Artifactory CPP CE 7.7.3 and Traefik v2.2 using docker-compose. The service is only available over http://localhost/ui/. Now, what I need is an option which allows to add a URL path-prefix (e. g. http://localhost/artifactroy/ui).
My Setup
I used the described setup process from the Artifactory Docs suggest it.
My docker.compose.yaml is the official extracted from the jfrog-artifactory-cpp-ce-7.7.3-compose.tar.gz: ./templates/docker-compose.yaml.
I'm using a reverse proxy (traefik). For this, I've added the necessary traefik configuration lines to the docker-compose-file. Here is a small extract what I've added:
[...]
labels:
- "traefik.http.routers.artifactory.rule=Host(`localhost`) && PathPrefix(`/ui`)"
- "traefik.http.routers.artifactory.middlewares=artifactory-stripprefix"
- "traefik.http.middlewares.artifactory-stripprefix.stripprefix.prefixes=/"
- "traefik.http.services.artifactory.loadbalancer.server.port=8082"
With this I managed to access artifactory over http://localhost/ui/.
Problem:
I have multiple small services running on my server, each of this service is accusable via http://localhost/<service-name>. This is very convenient and want to make clear that this URL is related to this service on my production server.
Because of this, I want to have an URL like http://localhost/artifactroy/ui/... instead of http://localhost/ui/...
I struggled getting artifactory setup in that way. I already managed to get a redirection from typing e. g. http://localhost/artifactroy/ to http://localhost/ui/ but this is not what I want on my production server.
What I did
Went through the documentation in hope of finding an option which I just can passt to artifactroy to add a prefix (Not successful).
Tried configure traefik two full days, to alter headers to get the repose point to http://localhost/artifactroy/ui/... (Only partially successful, redirection didn’t work afterwards)
Tried finding the configuration which is responsible for configure artifactory in $JFROG_HOME/artifactory/var/etc (Not successful)
Is this even possible? Help is highly appreciated..
This example (even though not traefic example) gives you a direction to implement it. There are certain routes already used within the product. You need to add a context over and above it to ensure all comes via the new context path.
https://jfrog.com/knowledge-base/how-to-remove-artifactory-from-the-context-url-in-artifactory-7/

Electron development - Generate API client based on swagger definition

I am very new to electron, trying to use it to build a cross-platform app which should be able to run natively on the machines. On the server side, I already have an application which exposes a REST API, documented with swagger.
Now I am trying to generate a client stub for this swagger definition, which I can then use with electron. How is that accomplished? Should I just generate JS code and use it (how would that work?)? Or is there another (better) way to do it as Electron has build in functions to access REST APIs like
I spent a considerable amount if time searching for a solution and did not find one. Now I wonder if that is such an uncommon scenario to use Electron as framework accessing REST APIs, and auto-generating the code using swagger codegen.
The great thing is that Electron apps can be very similarly developed to normal web applications. This is possibly why you didn't find specific instructions for using Electron with the tools you are used to using.
You should be able to go ahead and use whichever tools you would normally use to generate stubs for calling REST from any web application, and the stubs should work fine when referenced within Electron (as long as they generate in Javascript or Typescript).
Have you tried using Swagger codegen, did you try use the resulting client code API, and did it give you an error? Try posting any specific errors as new questions on Stack Overflow for solutions (or edit this question to be more specific).
Electron is almost like a blank canvas - there is no "right" or "wrong" way to develop, although there are certainly "good practises" and "bad practises".
There are definitely concepts that are unique to developing applications within Electron and for this it would be good to couple your development experience with some general Electron reading and learning.
You will very soon run in to "unique" Electron concepts such as "main" and "renderer" and it will be much easier if you have learning material to guide you. There is a lot of material for learning Electron so I won't try make a list here.
Also note that Stack Overflow is more useful when specific errors or minimum examples are provided and you'll probably get better answers that way :-) See: https://stackoverflow.com/help/mcve for more info on this.
I actually ended up swagger-codegen as GrahamMc suggested.
The general approach was like that:
rm -rf api
wget http://localhost/site/json-schema -O api.json
docker run --user `id -u`:`id -g` --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli generate -i /local/api.json -l javascript -o /local/api
rm api.json
cd api
npm install
Step 1 is cleaning up old generated code and step 2 is downloading the swagger spec which is not available from within the docker-container. The rest is cleaning up and installing dependencies.
From within the code, it can then be used like that:
var jtm_api = require('.api/')
var userApi = new jtm_api.UserApi()
var cb = function(error, data, response) {
if (response.status == 200) {
//do whatever
} else {
//do whatever
}
}
userApi.usersLoginPost(txtUser, txtPwd, cb)
There is an extensive documentation available on how to use the generated code starting from the README.md file within the generated folder.

PHPUnit: 404 code on every request

I have project A and project B in my vagrant machine. Both working and accessible via http://a.local/ and http//b.local/ . These are Apigility APIs.
I am now writing tests with PHPUnit.
I want to test that project A can call services on project B and check that:
Response code is 200.
Response is JSON.
etc...
PHPUnit keeps on failing because the response is 404 when calling any service (from a to b or from b to a):
{404 => string(54) "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html"
'title' =>
string(9) "Not Found"
'status' =>
int(404)
'detail' =>
string(15) "Page not found."}
All URLs are accesible via browser.
All URLs are accesible via Curl.
Browser and Curl return the same (identical) responses and http codes.
/etc/hosts file is properly configured.
PHP.ini file are identical for cli and fmp.
Any ideas what am I doing wrong? Thanks!
php-unit is probably more suitable for testing smaller parts of your application (unit testing). You can also do Curl tests of course but there are probably much better solutions (REST testing solutions/frameworks) to do this.
If you want to test your full application using Curl, you have to make sure that your php-unit bootstrap loads all the application dependencies.
It would also be a good idea to write a abstract wrapper or a test case specifically for testing your rest-api with Curl requests so you don't have to repeat too much code. Check this answer on stackoverflow to get an idea on how you could do this. But I bet there are a lot more examples available online and maybe you should do some googling.
You don't have ZF\Rest installed. The abstract factory to create rest resources, including doctrine controllers, is in that module.

Setting Jira Projects Type, Workflow and Screens Scheme Via API

I am running JIRA 6.1 and I'm trying to use the API to create a new project. Since JIRA 6.1's Rest API doesn't support creating a project I'm using the Soap API.
Note I'm doing this using the Atlassian .net SDK, but I imagine the solution is irrelevant to that.
I have managed to create the project no problem, but I am now trying to set the following schemes in the project
Issue Type
Workflow
Screens
As far as I can tell the 6.1 Soap API (and the 7 Rest API) doesn't actually allow you to modify these schemes, only allowing you to set the Permission, Security and Notification schemes - https://docs.atlassian.com/jira/REST/latest/#api/2/project-createProject
Is that the case or am I missing something?
If it is possible to set the scheme's I want, does anyone have any examples I could base my work off?
Thanks
Got an answer from Atlassian support, and as I suspected this isn't possible.
No, you're correct, the SOAP and REST APIs do not have those
functions.
You're going to need to write type-2 add-ons to provide the functions
you need if you're going to do this remotely, but with the caveat that
if you're willing to do that, you will probably find it a lot easier
to simply write add-ons that do all the work instead of just providing
the external hooks. (Let's put it this way - I was able to code
post-functions to create an entire customised project for JIRA 4 in a
couple of days. Versus a week to add a single SOAP call for feeding
back some simple user data)
I won't mutter too much about using SOAP - I'm assuming you know it's
dead, gone and mostly pointless to code for
Of course, there is the CLI plug-in which I think I'd be silly to ignore
JIRA Command Line Interface (CLI) support this for 6.1 through 7.0
including setting schemes that are not supported by SOAP or REST
except for screens. See the createProject action for details of what
is supported.
Starting from Jira 7.0.0, we can use Create project REST API [POST /rest/api/2/project]
which also allows setting following schemes while creating the project,
issueSecurityScheme
permissionScheme
notificationScheme
workflowSchemeId
Sample Request Payload:
{
"key": "EX",
"name": "Example",
"projectTypeKey": "business",
"projectTemplateKey": "com.atlassian.jira-core-project-templates:jira-core-project-management",
"description": "Example Project description",
"lead": "Charlie",
"url": "http://atlassian.com",
"assigneeType": "PROJECT_LEAD",
"avatarId": 10200,
"issueSecurityScheme": 10001,
"permissionScheme": 10011,
"notificationScheme": 10021,
"workflowSchemeId": 10031,
"categoryId": 10120
}
For issuetype and screen schemes, there is no such parameter available which can be set using the above create project rest api.
You can also try to use the following Rest endpoint to create jira project using shared configuration which will allow you to reuse all schemes which are present in the template project.
/rest/project-templates/1.0/createshared/{{projectid}}
More information on the Jira rest API can be found at https://docs.atlassian.com/software/jira/docs/api/REST/8.9.0/#api/2/project-createProject
You can try the following curl request for creating jira project
curl -D- \
-u admin:sphere \
-X POST \
-H "X-Atlassian-Token: nocheck" \
-H "Content-Type: application/x-www-form-urlencoded" \
"http://localhost:port/rest/project-templates/1.0/templates?projectTemplateWebItemKey=com.atlassian.jira-legacy-project-templates%3Ajira-blank-item&projectTemplateModuleKey=com.atlassian.jira-legacy-project-templates%3Ajira-blank-item&name=SECOND+Create+from+REST+API&key=CFRAPI&lead=admin&keyEdited=false"

Routing in Symfony 1.4: Is there a way to allow sf_method = OPTIONS for preflight HTTP requests

you all might know that browsers do preflighted HTTP requests in some cases:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Preflighted_requests
My web application is still on Symfony1. I want to implement a RESTful service and therefore using Symfony routing to allow specific HTTP request methods like GET or POST (http://symfony.com/legacy/doc/reference/1_4/en/10-Routing#chapter_10_sub_sf_method).
Example:
login:
url: /v1/login
class: sfRequestRoute
param: { module: rest, action: login }
requirements:
sf_method: [post, put, delete]
#sf_method: [options] NOT WORKING
It seems to me that OPTIONS requests cannot be defined/handled as sf_method value. Because I couldn't find any information if my idea is right, I'm wondering if I'm right or maybe there is a solution I couldn't find, too.
Thanks in advance!
Sorry to revive this old question but I found a solution. I ran into the same issue and I added the request method OPTIONS to the allowed methods in lib/sfRequest.class.php and lib/sfWebRequest.class.php You can check the latest commit here to see the differences: 6ad018c
Since I cannot update the original Symfony1 GitHub repository, I created a copy with additional fixes needed due to the various PHP upgrades. This fixes the PHP deprecated warnings due to use of the /e modifier in preg_replace calls as well.
Note that this still doesn't make Symfony1 PHP7 compatible. I'm running this successfully with PHP 5.6.30
The repository is https://github.com/diem-project/symfony.git
Background: Diem uses Symfony1 (1.4.20), hence the GitHub organisation diem-project

Resources