Skip to content

Implementing basic Claim API

Omar Qunsul requested to merge 469076-basic-claims-api into main

What does this MR do?

This MR is Addressing: gitlab-org/gitlab#469076

In this MR, we are implementing a basic functionality for the Claims Service / Create Claim.

This MR doesn't implement:

  1. Persisting the Claims, or checks if the claim existed before in the system.
  2. All the validations. For now we do basic validation on the Attribute Types + Some tests on the Ruby client.
  3. HTTP Interface for Claims. As this is called from Rails Application, GRPC will suffice for now.

What about the ClaimStore ?

This is a placeholder for Claims Persistence layer / Query Interface. We haven't agreed on how to implement this functionality yet. There is an issue for this: gitlab-org/gitlab#451050

ClaimStore is only about indicating that the service itself should not contain this functionality in the future, but not an indication about any future internal architecture of the service.

How to validate locally?

In case you wanted to test the GRPC Interface locally. You can follow these steps.

  • Run the Topology Service using go run . serve. If it wasn't build, build it using make build before
  • In a separate temporary folder create a Gemfile that contains the following

Make sure it contains the correct Ruby Version, and the path and path of the Topology Service

Gemfile
source 'https://rubygems.org'

ruby '3.1.2'

gem 'gitlab-topology-service-client', :path => '/Users/USERNAME/.../topology-service/clients/ruby'

Create this main.rb file, and run it using ruby main.rb. Feel free to change the parameters and experiment with the service

main.rb
require 'bundler/setup'
require 'gitlab/cells/topology_service'

def test_with_mtls?; true; end

def file_path(file)
	File.join("/Users", "omar", "topology-service", "tmp", "certs", file)
end

def service_credentials
	GRPC::Core::ChannelCredentials.new(
		File.read(file_path("ca-cert.pem")),
		(File.read(file_path("client-key.pem")) if test_with_mtls?),
		(File.read(file_path("client-cert.pem")) if test_with_mtls?)
	)
end

claim_service = Gitlab::Cells::TopologyService::ClaimService::Stub.new('localhost:9095', service_credentials)

#claim_metadata = Gitlab::Cells::TopologyService.build_metadata(cell_name: "cell-1")

claim_details = Gitlab::Cells::TopologyService::ClaimDetails.new(
		claim_type: Gitlab::Cells::TopologyService::ClaimType::Emails,
		claim_value: "omar@test.com",
		owner_type: Gitlab::Cells::TopologyService::OwnerType::User,
		owner_id: 1,
		database_table: Gitlab::Cells::TopologyService::DatabaseTable::Users,
		database_id: 1
		)

create_claim_request = Gitlab::Cells::TopologyService::CreateClaimRequest.new(
	details: claim_details
	
		)

response = claim_service.create_claim(create_claim_request)

puts response

What are the next possible steps for Claims?

Edited by Omar Qunsul

Merge request reports