Help us shape the future of Go! Take the 2026 Go Developer Survey

iam

package module
v1.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2021 License: GPL-3.0 Imports: 23 Imported by: 5

README

Go API client for iam

API for managing and authenticating Netsoc users.

Overview

This API client was generated by the OpenAPI Generator project. By using the OpenAPI-spec from a remote server, you can easily generate an API client.

  • API version: 1.0.11
  • Package version: 1.0.0
  • Build package: org.openapitools.codegen.languages.GoClientCodegen

Installation

Install the following dependencies:

go get github.com/stretchr/testify/assert
go get golang.org/x/oauth2
go get golang.org/x/net/context
go get github.com/antihax/optional

Put the package under your project folder and add the following in import:

import "./iam"

Documentation for API Endpoints

All URIs are relative to https://iam.netsoc.ie/v1

Class Method HTTP request Description
UsersApi CreateUser Post /users Create a new user
UsersApi DeleteUser Delete /users/{username} Delete a user by their username
UsersApi GetUser Get /users/{username} Get a user by their username
UsersApi GetUserByID Get /users/id:{uid} Get a user by their ID
UsersApi GetUsers Get /users List users
UsersApi IssueToken Post /users/{username}/token Issue a token
UsersApi Login Post /users/{username}/login Log into a user account (obtain JWT)
UsersApi Logout Delete /users/{username}/login Log out of a user account (invalidate existing JWT's)
UsersApi ResetPassword Put /users/{username}/login Reset password
UsersApi UpdateUser Patch /users/{username} Update a user by their username
UsersApi ValidateToken Get /users/self/token Validate a token
UsersApi Verify Patch /users/{username}/login Verify email address

Documentation For Models

Documentation For Authorization

jwt

  • Type: HTTP basic authentication

Example

auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
    UserName: "username",
    Password: "password",
})
r, err := client.Service.Operation(auth, args)

jwt_admin

  • Type: HTTP basic authentication

Example

auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
    UserName: "username",
    Password: "password",
})
r, err := client.Service.Operation(auth, args)

jwt_reset

  • Type: HTTP basic authentication

Example

auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
    UserName: "username",
    Password: "password",
})
r, err := client.Service.Operation(auth, args)

jwt_verify

  • Type: HTTP basic authentication

Example

auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
    UserName: "username",
    Password: "password",
})
r, err := client.Service.Operation(auth, args)

Author

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ContextOAuth2 takes an oauth2.TokenSource as authentication for the request.
	ContextOAuth2 = contextKey("token")

	// ContextBasicAuth takes BasicAuth as authentication for the request.
	ContextBasicAuth = contextKey("basic")

	// ContextAccessToken takes a string oauth2 access token as authentication for the request.
	ContextAccessToken = contextKey("accesstoken")

	// ContextAPIKey takes an APIKey as authentication for the request
	ContextAPIKey = contextKey("apikey")
)

Functions

func CacheExpires

func CacheExpires(r *http.Response) time.Time

CacheExpires helper function to determine remaining time before repeating a request.

Types

type APIClient

type APIClient struct {
	UsersApi *UsersApiService
	// contains filtered or unexported fields
}

APIClient manages communication with the Netsoc IAM API v1.0.11 In most cases there should be only one, shared, APIClient.

func NewAPIClient

func NewAPIClient(cfg *Configuration) *APIClient

NewAPIClient creates a new API client. Requires a userAgent string describing your application. optionally a custom http.Client to allow for advanced features such as caching.

func (*APIClient) ChangeBasePath

func (c *APIClient) ChangeBasePath(path string)

ChangeBasePath changes base path to allow switching to mocks

func (*APIClient) GetConfig

func (c *APIClient) GetConfig() *Configuration

Allow modification of underlying config for alternate implementations and testing Caution: modifying the configuration while live can cause data races and potentially unwanted behavior

type APIKey

type APIKey struct {
	Key    string
	Prefix string
}

APIKey provides API key based authentication to a request passed via context using ContextAPIKey

type APIResponse

type APIResponse struct {
	*http.Response `json:"-"`
	Message        string `json:"message,omitempty"`
	// Operation is the name of the OpenAPI operation.
	Operation string `json:"operation,omitempty"`
	// RequestURL is the request URL. This value is always available, even if the
	// embedded *http.Response is nil.
	RequestURL string `json:"url,omitempty"`
	// Method is the HTTP method used for the request.  This value is always
	// available, even if the embedded *http.Response is nil.
	Method string `json:"method,omitempty"`
	// Payload holds the contents of the response body (which may be nil or empty).
	// This is provided here as the raw response.Body() reader will have already
	// been drained.
	Payload []byte `json:"-"`
}

APIResponse stores the API response returned by the server.

func NewAPIResponse

func NewAPIResponse(r *http.Response) *APIResponse

NewAPIResponse returns a new APIResonse object.

func NewAPIResponseWithError

func NewAPIResponseWithError(errorMessage string) *APIResponse

NewAPIResponseWithError returns a new APIResponse object with the provided error message.

type BasicAuth

type BasicAuth struct {
	UserName string `json:"userName,omitempty"`
	Password string `json:"password,omitempty"`
}

BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth

type Configuration

type Configuration struct {
	BasePath      string            `json:"basePath,omitempty"`
	Host          string            `json:"host,omitempty"`
	Scheme        string            `json:"scheme,omitempty"`
	DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
	UserAgent     string            `json:"userAgent,omitempty"`
	Debug         bool              `json:"debug,omitempty"`
	Servers       []ServerConfiguration
	HTTPClient    *http.Client
}

Configuration stores the configuration of the API client

func NewConfiguration

func NewConfiguration() *Configuration

NewConfiguration returns a new Configuration object

func (*Configuration) AddDefaultHeader

func (c *Configuration) AddDefaultHeader(key string, value string)

AddDefaultHeader adds a new HTTP header to the default header in the request

func (*Configuration) ServerUrl

func (c *Configuration) ServerUrl(index int, variables map[string]string) (string, error)

ServerUrl returns URL based on server settings

type Error

type Error struct {
	// Message explaining the error
	Message string `json:"message"`
}

Error struct for Error

type GenericOpenAPIError

type GenericOpenAPIError struct {
	// contains filtered or unexported fields
}

GenericOpenAPIError Provides access to the body, error and model on returned errors.

func (GenericOpenAPIError) Body

func (e GenericOpenAPIError) Body() []byte

Body returns the raw bytes of the response

func (GenericOpenAPIError) Error

func (e GenericOpenAPIError) Error() string

Error returns non-empty string if there was an error.

func (GenericOpenAPIError) Model

func (e GenericOpenAPIError) Model() interface{}

Model returns the unpacked model of the error

type IssueTokenRequest

type IssueTokenRequest struct {
	// Duration of validity for token. Follows [Go's `time.Duration` format](https://pkg.go.dev/time#ParseDuration)
	Duration string `json:"duration,omitempty"`
}

IssueTokenRequest struct for IssueTokenRequest

type LoginRequest

type LoginRequest struct {
	Password string `json:"password"`
}

LoginRequest struct for LoginRequest

type ResetPasswordOpts

type ResetPasswordOpts struct {
	ResetPasswordRequest optional.Interface
}

ResetPasswordOpts Optional parameters for the method 'ResetPassword'

type ResetPasswordRequest

type ResetPasswordRequest struct {
	Password string `json:"password,omitempty"`
}

ResetPasswordRequest struct for ResetPasswordRequest

type ServerConfiguration

type ServerConfiguration struct {
	Url         string
	Description string
	Variables   map[string]ServerVariable
}

ServerConfiguration stores the information about a server

type ServerVariable

type ServerVariable struct {
	Description  string
	DefaultValue string
	EnumValues   []string
}

ServerVariable stores the information about a server variable

type TokenResponse

type TokenResponse struct {
	Token string `json:"token,omitempty"`
}

TokenResponse struct for TokenResponse

type User

type User struct {
	// Unique database identifier, not modifiable.
	Id int32 `json:"id"`
	// Unique username (must be a valid DNS name)
	Username string `json:"username"`
	// Unique email address (must be `@tcd.ie`)
	Email string `json:"email"`
	// Stored internally as a bcrypt hash. If unset, login will be disabled.
	Password  *string `json:"password,omitempty"`
	FirstName string  `json:"first_name"`
	LastName  string  `json:"last_name"`
	// SSH public key
	SshKey *string `json:"ssh_key,omitempty"`
	// Indicates if the user's email address is verified. Only modifiable directly by an admin.
	Verified *bool `json:"verified,omitempty"`
	// Indicates if the user is an admin. Only modifiable by an admin.
	IsAdmin *bool `json:"is_admin,omitempty"`
	// Date and time when the user's membership was last renewed. Only modifiable by an admin.
	Renewed time.Time `json:"renewed,omitempty"`
	Meta    UserMeta  `json:"meta,omitempty"`
}

User struct for User

type UserMeta

type UserMeta struct {
	// Date and time at which the user was created
	Created time.Time `json:"created"`
	// Date and time at which the user was last updated
	Updated time.Time `json:"updated"`
}

UserMeta Metadata about the user, not modifiable.

type UsersApiService

type UsersApiService service

UsersApiService UsersApi service

func (*UsersApiService) CreateUser

func (a *UsersApiService) CreateUser(ctx _context.Context, user User) (User, *_nethttp.Response, error)

CreateUser Create a new user A verification email will automatically be sent to the user's email address. Normally this just contains the raw JWT - setting `Accept` to contain `text/html` will send an email with a link to the configured UI service and the token.

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param user User to create

@return User

func (*UsersApiService) DeleteUser

func (a *UsersApiService) DeleteUser(ctx _context.Context, username string) (User, *_nethttp.Response, error)

DeleteUser Delete a user by their username Requires at least an expired user JWT. A valid admin JWT is required to delete a user other than `self`.

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.

@return User

func (*UsersApiService) GetUser

func (a *UsersApiService) GetUser(ctx _context.Context, username string) (User, *_nethttp.Response, error)

GetUser Get a user by their username Requires at least an expired user JWT. A valid admin JWT is required to retrieve a user other than `self`.

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.

@return User

func (*UsersApiService) GetUserByID added in v1.0.8

func (a *UsersApiService) GetUserByID(ctx _context.Context, uid int32) (User, *_nethttp.Response, error)

GetUserByID Get a user by their ID Requires a valid admin JWT.

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param uid User ID

@return User

func (*UsersApiService) GetUsers

func (a *UsersApiService) GetUsers(ctx _context.Context) ([]User, *_nethttp.Response, error)

GetUsers List users

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().

@return []User

func (*UsersApiService) IssueToken

func (a *UsersApiService) IssueToken(ctx _context.Context, username string, issueTokenRequest IssueTokenRequest) (TokenResponse, *_nethttp.Response, error)

IssueToken Issue a token

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username.
  • @param issueTokenRequest

@return TokenResponse

func (*UsersApiService) Login

func (a *UsersApiService) Login(ctx _context.Context, username string, loginRequest LoginRequest) (TokenResponse, *_nethttp.Response, error)

Login Log into a user account (obtain JWT)

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username.
  • @param loginRequest

@return TokenResponse

func (*UsersApiService) Logout

func (a *UsersApiService) Logout(ctx _context.Context, username string) (*_nethttp.Response, error)

Logout Log out of a user account (invalidate existing JWT's) Requires at least an expired user JWT. A valid admin JWT is required to logout a user other than `self`.

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.

func (*UsersApiService) ResetPassword

func (a *UsersApiService) ResetPassword(ctx _context.Context, username string, localVarOptionals *ResetPasswordOpts) (*_nethttp.Response, error)

ResetPassword Reset password Making a request without a token (or request body) will generate a token and send it to the user's email address. Normally this just contains the raw JWT - setting `Accept` to contain `text/html` will send an email with a link to the configured UI service and the token. Passing the returned token to this endpoint (along with the new password) will perform the reset.

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.
  • @param optional nil or *ResetPasswordOpts - Optional Parameters:
  • @param "ResetPasswordRequest" (optional.Interface of ResetPasswordRequest) -

func (*UsersApiService) UpdateUser

func (a *UsersApiService) UpdateUser(ctx _context.Context, username string, user User) (User, *_nethttp.Response, error)

UpdateUser Update a user by their username Requires at least an expired user JWT. A valid admin JWT is required to update admin-only fields and modify a user other than `self`. A verification email will automatically be sent to the user's email address if it has been changed. Normally this just contains the raw JWT - setting `Accept` to contain `text/html` will send an email with a link to the configured UI service and the token.

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.
  • @param user Partial user containing fields to update

@return User

func (*UsersApiService) ValidateToken

func (a *UsersApiService) ValidateToken(ctx _context.Context) (*_nethttp.Response, error)

ValidateToken Validate a token

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().

func (*UsersApiService) Verify

func (a *UsersApiService) Verify(ctx _context.Context, username string) (*_nethttp.Response, error)

Verify Verify email address Making a request without a token will generate a token and send it to the user's email address. Normally this just contains the raw JWT - setting `Accept` to contain `text/html` will send an email with a link to the configured UI service and the token. Passing the returned token to this endpoint will perform the verification.

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param username User's username. Can be `self` to indicate the currently authenticated user.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL