package com.atlassian.bitbucket.internal.mirroring.upstream;

import com.atlassian.bitbucket.mirroring.upstream.MirrorServer;

import javax.annotation.Nonnull;
import java.util.Optional;

/**
 * A service to allow generating REST URLs with JWT tokens that can call the upstream server's REST resource on the
 * mirror server.
 */
public interface MirrorLinkService {

    /**
     * Generate a JWT token for requests to the specified {@link MirrorServer mirror}. The generated token will include
     * the calling user as the subject claim. These tokens expire after 24 hours and only support GET requests.
     *
     * @param mirrorServer the mirror to generate a token for
     * @param restResource the upstream server rest resource to generate the token for
     * @return an authorized link containing the url and appropriate JWT token
     */
    @Nonnull
    Optional<String> generateAuthorizedLink(@Nonnull InternalMirrorServer mirrorServer, @Nonnull String restResource);
}
