You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: serve.go
    path of file: ./repos/cds/engine/hatchery
    
    the code of the file until where you have to start completion: package hatchery

import (
	"context"
	"crypto/rsa"
	"crypto/tls"
	"fmt"
	"net"
	"net/http"
	"net/http/pprof"
	"strconv"
	"strings"
	"sync"
	"time"

	"github.com/rockbears/log"

	"github.com/ovh/cds/engine/api"
	"github.com/ovh/cds/engine/service"
	"github.com/ovh/cds/engine/worker/pkg/workerruntime"
	"github.com/ovh/cds/sdk"
	"github.com/ovh/cds/sdk/cdsclie
    
func (c *Common) SigninV2(ctx context.Context, clientConfig cdsclient.ServiceConfig, srvConfig interface{}) error {
	if clientConfig.TokenV2 == "" {
		return nil
	}
	log.Info(ctx, "Init CDS client v2 for hatchery")
	ctxTimeout, cancel := context.WithTimeout(ctx, 5*time.Minute)
	defer cancel()
	ticker := time.NewTicker(10 * time.Second)
	defer ticker.Stop()

	serviceConfig, err := service.ParseServiceConfig(srvConfig)
	if err != nil {
		return err
	}

	var pubKey []byte
	if c.PrivateKey == nil {
		return sdk.WrapError(sdk.ErrInvalidData, "missing private key")
	}

	pubKey, err = jws.ExportPublicKey(c.PrivateKey)
	if err != nil {
		return err
	}

	registerPayload := &sdk.AuthConsumerHatcherySigninRequest{
		Token:        clientConfig.TokenV2,
		Version:      sdk.VERSION,
		PublicKey:    pubKey,
		Config:       serviceConfig,
		Name:         c.Name(),
		HTTPURL:      c.HTTPURL,
		HatcheryType: c.ModelType,
	}

	initClient := func(ctx context.Context) error {
		var err error
		// The call below should return the sdk.Service from the signin
		fmt.Printf("New Hatchery Client \n")
		c.Clientv2, c.APIPublicKey, c.Region, err = cdsclient.NewHatcheryServiceClient(ctx, clientConfig, registerPayload)
		if err != nil {
			fmt.Printf("Waiting for CDS API (%v)...\n", err)
		}
		return err
	}

	var lasterr error
	if err := initClient(ctxTimeout); err != nil {
		lasterr = err
	loop:
		for {
			select {
			case <-ctxTimeout.Done():
				if lasterr != nil {
					fmt.Printf("Timeout after 5min - last error: %v\n", lasterr)
				}
				return ctxTimeout.Err()
			case <-ticker.C:
				if err := initClient(ctxTimeout); err == nil {
					lasterr = err //lint:ignore SA4006 false positive
					break loop
				}
			}
		}
	}

	c.ParsedAPIPublicKey, err = jws.NewPublicKeyFromPEM(c.APIPublicKey)
	if err != nil {
		return sdk.WithStack(err)
	}

	return nil
}