syntax = "proto3";
option go_package = "github.com/argoproj/argo-cd/v2/pkg/apiclient/repository";

// Repository Service
//
// Repository Service API performs CRUD actions against repository resources
package repository;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "k8s.io/api/core/v1/generated.proto";
import "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1/generated.proto";
import "github.com/argoproj/argo-cd/v2/reposerver/repository/repository.proto";

// RepoAppsQuery is a query for Repository apps
message RepoAppsQuery {
	string repo = 1;
	string revision = 2;
}


// AppInfo contains application type and app file path
message AppInfo {
	string type = 1;
	string path = 2;
}

// RepoAppDetailsQuery contains query information for app details request
message RepoAppDetailsQuery {
	github.com.argoproj.argo_cd.v2.pkg.apis.application.v1alpha1.ApplicationSource source = 1;
	string appName = 2;
}

// RepoAppsResponse contains applications of specified repository
message RepoAppsResponse {
	repeated AppInfo items = 1;
}

// RepoQuery is a query for Repository resources
message RepoQuery {
	// Repo URL for query
	string repo = 1;
	// Whether to force a cache refresh on repo's connection state
	bool forceRefresh = 2;
}

// RepoAccessQuery is a query for checking access to a repo
message RepoAccessQuery {
	// The URL to the repo
	string repo = 1;
	// Username for accessing repo
	string username = 2;
	// Password for accessing repo
	string password = 3;
	// Private key data for accessing SSH repository
	string sshPrivateKey = 4;
	// Whether to skip certificate or host key validation
	bool   insecure = 5;
	// TLS client cert data for accessing HTTPS repository
	string tlsClientCertData = 6;
	// TLS client cert key for accessing HTTPS repository
	string tlsClientCertKey = 7;
	// The type of the repo
	string type = 9;
	// The name of the repo
	string name = 10;
	// Whether helm-oci support should be enabled for this repo
	bool enableOci = 11;
	// Github App Private Key PEM data
	string githubAppPrivateKey = 12;
	// Github App ID of the app used to access the repo
	int64 githubAppID = 13;
	// Github App Installation ID of the installed GitHub App
	int64 githubAppInstallationID = 14;
	// Github App Enterprise base url if empty will default to https://api.github.com
	string githubAppEnterpriseBaseUrl = 15;
	// HTTP/HTTPS proxy to access the repository
	string proxy = 16;
}

message RepoResponse {}

// RepoCreateRequest is a request for creating repository config
message RepoCreateRequest {
	// Repository definition
	github.com.argoproj.argo_cd.v2.pkg.apis.application.v1alpha1.Repository repo = 1;
	// Whether to create in upsert mode
	bool upsert = 2;
	// Whether to operate on credential set instead of repository
	bool credsOnly = 3;
}

message RepoUpdateRequest {
	github.com.argoproj.argo_cd.v2.pkg.apis.application.v1alpha1.Repository repo = 1;
}

// RepositoryService
service RepositoryService {

	// List returns list of repos or repository credentials
	rpc List(RepoQuery) returns (github.com.argoproj.argo_cd.v2.pkg.apis.application.v1alpha1.RepositoryList) {
		option (google.api.http).get = "/api/v1/repositories";
		option deprecated = true;
	}

		// Get returns a repository or its credentials
	rpc Get(RepoQuery) returns (github.com.argoproj.argo_cd.v2.pkg.apis.application.v1alpha1.Repository) {
		option (google.api.http).get = "/api/v1/repositories/{repo}";
	}

	// ListRepositories gets a list of all configured repositories
	rpc ListRepositories(RepoQuery) returns (github.com.argoproj.argo_cd.v2.pkg.apis.application.v1alpha1.RepositoryList) {
		option (google.api.http).get = "/api/v1/repositories";
	}

	rpc ListRefs(RepoQuery) returns (Refs) {
		option (google.api.http).get = "/api/v1/repositories/{repo}/refs";
	}

	// ListApps returns list of apps in the repo
	rpc ListApps(RepoAppsQuery) returns (RepoAppsResponse) {
		option (google.api.http).get = "/api/v1/repositories/{repo}/apps";
	}

	// GetAppDetails returns application details by given path
	rpc GetAppDetails(RepoAppDetailsQuery) returns (repository.RepoAppDetailsResponse) {
		option (google.api.http) = {
			post: "/api/v1/repositories/{source.repoURL}/appdetails"
			body: "*"
		};
	}

	// GetHelmCharts returns list of helm charts in the specified repository
	rpc GetHelmCharts(RepoQuery) returns (repository.HelmChartsResponse) {
		option (google.api.http).get = "/api/v1/repositories/{repo}/helmcharts";
	}

	// Create creates a repo or a repo credential set
	rpc Create(RepoCreateRequest) returns (github.com.argoproj.argo_cd.v2.pkg.apis.application.v1alpha1.Repository) {
		option (google.api.http) = {
			post: "/api/v1/repositories"
			body: "repo"
		};
		option deprecated = true;
	}

	// CreateRepository creates a new repository configuration
	rpc CreateRepository(RepoCreateRequest) returns (github.com.argoproj.argo_cd.v2.pkg.apis.application.v1alpha1.Repository) {
		option (google.api.http) = {
			post: "/api/v1/repositories"
			body: "repo"
		};
	}

	// Update updates a repo or repo credential set
	rpc Update(RepoUpdateRequest) returns (github.com.argoproj.argo_cd.v2.pkg.apis.application.v1alpha1.Repository) {
		option (google.api.http) = {
			put: "/api/v1/repositories/{repo.repo}"
			body: "repo"
		};
		option deprecated = true;
	}

	// UpdateRepository updates a repository configuration
	rpc UpdateRepository(RepoUpdateRequest) returns (github.com.argoproj.argo_cd.v2.pkg.apis.application.v1alpha1.Repository) {
		option (google.api.http) = {
			put: "/api/v1/repositories/{repo.repo}"
			body: "repo"
		};
	}

	// Delete deletes a repository from the configuration
	rpc Delete(RepoQuery) returns (RepoResponse) {
		option (google.api.http).delete = "/api/v1/repositories/{repo}";
		option deprecated = true;
	}

	// DeleteRepository deletes a repository from the configuration
	rpc DeleteRepository(RepoQuery) returns (RepoResponse) {
		option (google.api.http).delete = "/api/v1/repositories/{repo}";
	}

	// ValidateAccess validates access to a repository with given parameters
	rpc ValidateAccess(RepoAccessQuery) returns (RepoResponse) {
		option (google.api.http) = {
			post: "/api/v1/repositories/{repo}/validate"
			body: "repo"
		};
	}
}
