17170: Merge branch 'master'
[arvados.git] / sdk / go / arvados / api.go
index 7d6ddb317621fde9800c385cc024218d16eb4630..37a3e007b16108cb6a2f9c6627c29106eee52bca 100644 (file)
@@ -5,8 +5,12 @@
 package arvados
 
 import (
+       "bufio"
        "context"
        "encoding/json"
+       "net"
+
+       "github.com/sirupsen/logrus"
 )
 
 type APIEndpoint struct {
@@ -19,6 +23,7 @@ type APIEndpoint struct {
 var (
        EndpointConfigGet                     = APIEndpoint{"GET", "arvados/v1/config", ""}
        EndpointLogin                         = APIEndpoint{"GET", "login", ""}
+       EndpointLogout                        = APIEndpoint{"GET", "logout", ""}
        EndpointCollectionCreate              = APIEndpoint{"POST", "arvados/v1/collections", "collection"}
        EndpointCollectionUpdate              = APIEndpoint{"PATCH", "arvados/v1/collections/{uuid}", "collection"}
        EndpointCollectionGet                 = APIEndpoint{"GET", "arvados/v1/collections/{uuid}", ""}
@@ -40,6 +45,12 @@ var (
        EndpointContainerDelete               = APIEndpoint{"DELETE", "arvados/v1/containers/{uuid}", ""}
        EndpointContainerLock                 = APIEndpoint{"POST", "arvados/v1/containers/{uuid}/lock", ""}
        EndpointContainerUnlock               = APIEndpoint{"POST", "arvados/v1/containers/{uuid}/unlock", ""}
+       EndpointContainerSSH                  = APIEndpoint{"GET", "arvados/v1/connect/{uuid}/ssh", ""} // move to /containers after #17014 fixes routing
+       EndpointContainerRequestCreate        = APIEndpoint{"POST", "arvados/v1/container_requests", "container_request"}
+       EndpointContainerRequestUpdate        = APIEndpoint{"PATCH", "arvados/v1/container_requests/{uuid}", "container_request"}
+       EndpointContainerRequestGet           = APIEndpoint{"GET", "arvados/v1/container_requests/{uuid}", ""}
+       EndpointContainerRequestList          = APIEndpoint{"GET", "arvados/v1/container_requests", ""}
+       EndpointContainerRequestDelete        = APIEndpoint{"DELETE", "arvados/v1/container_requests/{uuid}", ""}
        EndpointUserActivate                  = APIEndpoint{"POST", "arvados/v1/users/{uuid}/activate", ""}
        EndpointUserCreate                    = APIEndpoint{"POST", "arvados/v1/users", "user"}
        EndpointUserCurrent                   = APIEndpoint{"GET", "arvados/v1/users/current", ""}
@@ -49,19 +60,34 @@ var (
        EndpointUserGetSystem                 = APIEndpoint{"GET", "arvados/v1/users/system", ""}
        EndpointUserList                      = APIEndpoint{"GET", "arvados/v1/users", ""}
        EndpointUserMerge                     = APIEndpoint{"POST", "arvados/v1/users/merge", ""}
-       EndpointUserSetup                     = APIEndpoint{"POST", "arvados/v1/users/setup", ""}
+       EndpointUserSetup                     = APIEndpoint{"POST", "arvados/v1/users/setup", "user"}
        EndpointUserSystem                    = APIEndpoint{"GET", "arvados/v1/users/system", ""}
        EndpointUserUnsetup                   = APIEndpoint{"POST", "arvados/v1/users/{uuid}/unsetup", ""}
        EndpointUserUpdate                    = APIEndpoint{"PATCH", "arvados/v1/users/{uuid}", "user"}
        EndpointUserUpdateUUID                = APIEndpoint{"POST", "arvados/v1/users/{uuid}/update_uuid", ""}
-       EndpointUserBatchUpdate               = APIEndpoint{"PATCH", "arvados/v1/users/batch", ""}
+       EndpointUserBatchUpdate               = APIEndpoint{"PATCH", "arvados/v1/users/batch_update", ""}
+       EndpointUserAuthenticate              = APIEndpoint{"POST", "arvados/v1/users/authenticate", ""}
        EndpointAPIClientAuthorizationCurrent = APIEndpoint{"GET", "arvados/v1/api_client_authorizations/current", ""}
 )
 
+type ContainerSSHOptions struct {
+       UUID          string `json:"uuid"`
+       DetachKeys    string `json:"detach_keys"`
+       LoginUsername string `json:"login_username"`
+}
+
+type ContainerSSHConnection struct {
+       Conn   net.Conn           `json:"-"`
+       Bufrw  *bufio.ReadWriter  `json:"-"`
+       Logger logrus.FieldLogger `json:"-"`
+}
+
 type GetOptions struct {
-       UUID         string   `json:"uuid"`
+       UUID         string   `json:"uuid,omitempty"`
        Select       []string `json:"select"`
        IncludeTrash bool     `json:"include_trash"`
+       ForwardedFor string   `json:"forwarded_for,omitempty"`
+       Remote       string   `json:"remote,omitempty"`
 }
 
 type UntrashOptions struct {
@@ -74,13 +100,15 @@ type ListOptions struct {
        Select             []string               `json:"select"`
        Filters            []Filter               `json:"filters"`
        Where              map[string]interface{} `json:"where"`
-       Limit              int                    `json:"limit"`
-       Offset             int                    `json:"offset"`
+       Limit              int64                  `json:"limit"`
+       Offset             int64                  `json:"offset"`
        Order              []string               `json:"order"`
        Distinct           bool                   `json:"distinct"`
        Count              string                 `json:"count"`
        IncludeTrash       bool                   `json:"include_trash"`
        IncludeOldVersions bool                   `json:"include_old_versions"`
+       BypassFederation   bool                   `json:"bypass_federation"`
+       ForwardedFor       string                 `json:"forwarded_for,omitempty"`
 }
 
 type CreateOptions struct {
@@ -91,8 +119,9 @@ type CreateOptions struct {
 }
 
 type UpdateOptions struct {
-       UUID  string                 `json:"uuid"`
-       Attrs map[string]interface{} `json:"attrs"`
+       UUID             string                 `json:"uuid"`
+       Attrs            map[string]interface{} `json:"attrs"`
+       BypassFederation bool                   `json:"bypass_federation"`
 }
 
 type UpdateUUIDOptions struct {
@@ -105,19 +134,21 @@ type UserActivateOptions struct {
 }
 
 type UserSetupOptions struct {
-       UUID                  string                 `json:"uuid"`
-       Email                 string                 `json:"email"`
-       OpenIDPrefix          string                 `json:"openid_prefix"`
-       RepoName              string                 `json:"repo_name"`
-       VMUUID                string                 `json:"vm_uuid"`
-       SendNotificationEmail bool                   `json:"send_notification_email"`
+       UUID                  string                 `json:"uuid,omitempty"`
+       Email                 string                 `json:"email,omitempty"`
+       OpenIDPrefix          string                 `json:"openid_prefix,omitempty"`
+       RepoName              string                 `json:"repo_name,omitempty"`
+       VMUUID                string                 `json:"vm_uuid,omitempty"`
+       SendNotificationEmail bool                   `json:"send_notification_email,omitempty"`
        Attrs                 map[string]interface{} `json:"attrs"`
 }
 
 type UserMergeOptions struct {
-       NewUserUUID  string `json:"new_user_uuid,omitempty"`
-       OldUserUUID  string `json:"old_user_uuid,omitempty"`
-       NewUserToken string `json:"new_user_token,omitempty"`
+       NewUserUUID       string `json:"new_user_uuid,omitempty"`
+       OldUserUUID       string `json:"old_user_uuid,omitempty"`
+       NewOwnerUUID      string `json:"new_owner_uuid,omitempty"`
+       NewUserToken      string `json:"new_user_token,omitempty"`
+       RedirectToNewUser bool   `json:"redirect_to_new_user"`
 }
 
 type UserBatchUpdateOptions struct {
@@ -137,9 +168,19 @@ type LoginOptions struct {
        State    string `json:"state,omitempty"`  // OAuth2 callback state
 }
 
+type UserAuthenticateOptions struct {
+       Username string `json:"username,omitempty"` // PAM username
+       Password string `json:"password,omitempty"` // PAM password
+}
+
+type LogoutOptions struct {
+       ReturnTo string `json:"return_to"` // Redirect to this URL after logging out
+}
+
 type API interface {
        ConfigGet(ctx context.Context) (json.RawMessage, error)
        Login(ctx context.Context, options LoginOptions) (LoginResponse, error)
+       Logout(ctx context.Context, options LogoutOptions) (LogoutResponse, error)
        CollectionCreate(ctx context.Context, options CreateOptions) (Collection, error)
        CollectionUpdate(ctx context.Context, options UpdateOptions) (Collection, error)
        CollectionGet(ctx context.Context, options GetOptions) (Collection, error)
@@ -156,6 +197,12 @@ type API interface {
        ContainerDelete(ctx context.Context, options DeleteOptions) (Container, error)
        ContainerLock(ctx context.Context, options GetOptions) (Container, error)
        ContainerUnlock(ctx context.Context, options GetOptions) (Container, error)
+       ContainerSSH(ctx context.Context, options ContainerSSHOptions) (ContainerSSHConnection, error)
+       ContainerRequestCreate(ctx context.Context, options CreateOptions) (ContainerRequest, error)
+       ContainerRequestUpdate(ctx context.Context, options UpdateOptions) (ContainerRequest, error)
+       ContainerRequestGet(ctx context.Context, options GetOptions) (ContainerRequest, error)
+       ContainerRequestList(ctx context.Context, options ListOptions) (ContainerRequestList, error)
+       ContainerRequestDelete(ctx context.Context, options DeleteOptions) (ContainerRequest, error)
        SpecimenCreate(ctx context.Context, options CreateOptions) (Specimen, error)
        SpecimenUpdate(ctx context.Context, options UpdateOptions) (Specimen, error)
        SpecimenGet(ctx context.Context, options GetOptions) (Specimen, error)
@@ -174,5 +221,6 @@ type API interface {
        UserList(ctx context.Context, options ListOptions) (UserList, error)
        UserDelete(ctx context.Context, options DeleteOptions) (User, error)
        UserBatchUpdate(context.Context, UserBatchUpdateOptions) (UserList, error)
+       UserAuthenticate(ctx context.Context, options UserAuthenticateOptions) (APIClientAuthorization, error)
        APIClientAuthorizationCurrent(ctx context.Context, options GetOptions) (APIClientAuthorization, error)
 }