Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apply/apply.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package apply

import "os"

type Cmd struct {
Filename string `short:"f" predictor:"file"`
Filename *os.File `short:"f" predictor:"file"`
FromFile fromFile `cmd:"" default:"1" name:"-f <file>" help:"Apply any resource from a yaml or json file."`
}
12 changes: 4 additions & 8 deletions apply/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,19 @@ func Delete() Option {
}
}

func File(ctx context.Context, client *api.Client, filename string, opts ...Option) error {
if len(filename) == 0 {
func File(ctx context.Context, client *api.Client, file *os.File, opts ...Option) error {
if file == nil {
return fmt.Errorf("missing flag -f, --filename=STRING")
}
defer file.Close()

cfg := &config{}
for _, opt := range opts {
opt(cfg)
}

f, err := os.Open(filename)
if err != nil {
return err
}

obj := &unstructured.Unstructured{}
if err := yaml.NewYAMLOrJSONDecoder(f, 4096).Decode(obj); err != nil {
if err := yaml.NewYAMLOrJSONDecoder(file, 4096).Decode(obj); err != nil {
return err
}

Expand Down
42 changes: 21 additions & 21 deletions apply/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,39 +118,39 @@ func TestFile(t *testing.T) {
if _, err := fmt.Fprintf(f, tc.file, name, "value", runtimev1.DeletionOrphan); err != nil {
t.Fatal(err)
}
// The file is written, but the pointer is at the end.
// Close it to flush content.
require.NoError(t, f.Close())

opts := []Option{}

// For delete and update tests, we first create the resource.
if tc.delete || tc.update {
fileToCreate, err := os.Open(f.Name())
require.NoError(t, err)
err = File(ctx, apiClient, fileToCreate) // This will close fileToCreate
require.NoError(t, err)
}

if tc.delete {
// we need to ensure that the resource exists before we can delete it
if err := File(ctx, apiClient, f.Name()); err != nil {
t.Fatal(err)
}
opts = append(opts, Delete())
}

if tc.update {
// we need to ensure that the resource exists before we can update
if err := File(ctx, apiClient, f.Name()); err != nil {
t.Fatal(err)
}

if err := f.Truncate(0); err != nil {
t.Fatal(err)
}

if _, err := f.Seek(0, 0); err != nil {
t.Fatal(err)
}

if _, err := fmt.Fprintf(f, tc.file, name, tc.updatedAnnotation, tc.updatedSpecValue); err != nil {
t.Fatal(err)
}
// Re-create the file to truncate it and write the updated content.
updatedFile, err := os.Create(f.Name())
require.NoError(t, err)
_, err = fmt.Fprintf(updatedFile, tc.file, name, tc.updatedAnnotation, tc.updatedSpecValue)
require.NoError(t, err)
require.NoError(t, updatedFile.Close())

opts = append(opts, UpdateOnExists())
}

if err := File(ctx, apiClient, f.Name(), opts...); err != nil {
fileToApply, err := os.Open(f.Name())
require.NoError(t, err)

if err := File(ctx, apiClient, fileToApply, opts...); err != nil {
if tc.expectedErr {
return
}
Expand Down
4 changes: 2 additions & 2 deletions auth/client_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
)

type API struct {
URL string `help:"The URL of the Nine API" default:"https://nineapis.ch" env:"NCTL_API_URL" hidden:""`
URL string `help:"URL of the Nine API." default:"https://nineapis.ch" env:"NCTL_API_URL" hidden:""`
Token string `help:"Use a static API token instead of using an OIDC login. Requires the --organization to also be set." env:"NCTL_API_TOKEN" hidden:""`
ClientID string `help:"Use an API client ID to login. Requires the --organization to also be set." env:"NCTL_API_CLIENT_ID"`
ClientSecret string `help:"Use an API client secret to login. Requires the --organization to also be set." env:"NCTL_API_CLIENT_SECRET"`
TokenURL string `help:"Override the default client token URL" hidden:"" default:"${token_url}" env:"NCTL_API_TOKEN_URL"`
TokenURL string `help:"Override the default client token URL." hidden:"" default:"${token_url}" env:"NCTL_API_TOKEN_URL"`
}

type ClientCredentialsCmd struct {
Expand Down
6 changes: 3 additions & 3 deletions auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const (

type LoginCmd struct {
API API `embed:"" prefix:"api-"`
Organization string `help:"The name of your organization to use when providing an API client ID/secret." env:"NCTL_ORGANIZATION"`
IssuerURL string `help:"Issuer URL is the OIDC issuer URL of the API." default:"${issuer_url}" hidden:""`
ClientID string `help:"Client ID is the OIDC client ID of the API." default:"${client_id}" hidden:""`
Organization string `help:"Name of your organization to use when providing an API client ID/secret." env:"NCTL_ORGANIZATION"`
IssuerURL string `help:"OIDC issuer URL of the API." default:"${issuer_url}" hidden:""`
ClientID string `help:"OIDC client ID of the API." default:"${client_id}" hidden:""`
ForceInteractiveEnvOverride bool `help:"Used for internal purposes only. Set to true to force interactive environment explicit override. Set to false to fall back to automatic interactivity detection." default:"false" hidden:""`
tk api.TokenGetter
}
Expand Down
6 changes: 3 additions & 3 deletions auth/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
)

type LogoutCmd struct {
APIURL string `help:"The URL of the Nine API" default:"https://nineapis.ch" env:"NCTL_API_URL" name:"api-url"`
IssuerURL string `help:"Issuer URL is the OIDC issuer URL of the API." default:"https://auth.nine.ch/auth/realms/pub"`
ClientID string `help:"Client ID is the OIDC client ID of the API." default:"nineapis.ch-f178254"`
APIURL string `help:"URL of the Nine API." default:"https://nineapis.ch" env:"NCTL_API_URL" name:"api-url"`
IssuerURL string `help:"OIDC issuer URL of the API." default:"https://auth.nine.ch/auth/realms/pub"`
ClientID string `help:"OIDC client ID of the API." default:"nineapis.ch-f178254"`
tk api.TokenGetter
}

Expand Down
6 changes: 3 additions & 3 deletions auth/set_org.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (

type SetOrgCmd struct {
Organization string `arg:"" help:"Name of the organization to login to." default:""`
APIURL string `help:"The URL of the Nine API" default:"https://nineapis.ch" env:"NCTL_API_URL" name:"api-url"`
IssuerURL string `help:"Issuer URL is the OIDC issuer URL of the API." default:"https://auth.nine.ch/auth/realms/pub"`
ClientID string `help:"Client ID is the OIDC client ID of the API." default:"nineapis.ch-f178254"`
APIURL string `help:"URL of the Nine API." default:"https://nineapis.ch" env:"NCTL_API_URL" name:"api-url"`
IssuerURL string `help:"OIDC issuer URL of the API." default:"https://auth.nine.ch/auth/realms/pub"`
ClientID string `help:"OIDC client ID of the API." default:"nineapis.ch-f178254"`
}

func (s *SetOrgCmd) Run(ctx context.Context, client *api.Client) error {
Expand Down
6 changes: 3 additions & 3 deletions auth/whoami.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
)

type WhoAmICmd struct {
APIURL string `help:"The URL of the Nine API" default:"https://nineapis.ch" env:"NCTL_API_URL" name:"api-url"`
IssuerURL string `help:"Issuer URL is the OIDC issuer URL of the API." default:"https://auth.nine.ch/auth/realms/pub"`
ClientID string `help:"Client ID is the OIDC client ID of the API." default:"nineapis.ch-f178254"`
APIURL string `help:"URL of the Nine API." default:"https://nineapis.ch" env:"NCTL_API_URL" name:"api-url"`
IssuerURL string `help:"OIDC issuer URL of the API." default:"https://auth.nine.ch/auth/realms/pub"`
ClientID string `help:"OIDC client ID of the API." default:"nineapis.ch-f178254"`
}

func (s *WhoAmICmd) Run(ctx context.Context, client *api.Client) error {
Expand Down
38 changes: 19 additions & 19 deletions create/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,29 @@ const logPrintTimeout = 10 * time.Second
type applicationCmd struct {
resourceCmd
Git gitConfig `embed:"" prefix:"git-"`
Size *string `help:"Size of the app (defaults to \"${app_default_size}\")." placeholder:"${app_default_size}"`
Port *int32 `help:"Port the app is listening on (defaults to ${app_default_port})." placeholder:"${app_default_port}"`
Replicas *int32 `help:"Amount of replicas of the running app (defaults to ${app_default_replicas})." placeholder:"${app_default_replicas}"`
Hosts []string `help:"Host names where the app can be accessed. If empty, the app will just be accessible on a generated host name on the deploio.app domain."`
BasicAuth *bool `help:"Enable/Disable basic authentication for the app (defaults to ${app_default_basic_auth})." placeholder:"${app_default_basic_auth}"`
Env map[string]string `help:"Environment variables which are passed to the app at runtime."`
SensitiveEnv map[string]string `help:"Sensitive environment variables which are passed to the app at runtime."`
BuildEnv map[string]string `help:"Environment variables which are passed to the app build process."`
SensitiveBuildEnv map[string]string `help:"Sensitive environment variables which are passed to the app build process."`
Size *string `help:"Size of the application (defaults to \"${app_default_size}\")." placeholder:"${app_default_size}"`
Port *int32 `help:"Port the application is listening on (defaults to ${app_default_port})." placeholder:"${app_default_port}"`
Replicas *int32 `help:"Amount of replicas of the running application (defaults to ${app_default_replicas})." placeholder:"${app_default_replicas}"`
Hosts []string `help:"Host names where the application can be accessed. If empty, the application will just be accessible on a generated host name on the deploio.app domain."`
BasicAuth *bool `help:"Enable/Disable basic authentication for the application (defaults to ${app_default_basic_auth})." placeholder:"${app_default_basic_auth}"`
Env map[string]string `help:"Environment variables which are passed to the application at runtime."`
SensitiveEnv map[string]string `help:"Sensitive environment variables which are passed to the application at runtime."`
BuildEnv map[string]string `help:"Environment variables which are passed to the application build process."`
SensitiveBuildEnv map[string]string `help:"Sensitive environment variables which are passed to the application build process."`
DeployJob deployJob `embed:"" prefix:"deploy-job-"`
WorkerJob workerJob `embed:"" prefix:"worker-job-"`
ScheduledJob scheduledJob `embed:"" prefix:"scheduled-job-"`
GitInformationServiceURL string `help:"URL of the git information service." default:"https://git-info.deplo.io" env:"GIT_INFORMATION_SERVICE_URL" hidden:""`
SkipRepoAccessCheck bool `help:"Skip the git repository access check" default:"false"`
Debug bool `help:"Enable debug messages" default:"false"`
SkipRepoAccessCheck bool `help:"Skip the git repository access check." default:"false"`
Debug bool `help:"Enable debug messages." default:"false"`
Language string `help:"${app_language_help} Possible values: ${enum}" enum:"ruby,php,python,golang,nodejs,static," default:""`
DockerfileBuild dockerfileBuild `embed:""`
}

type gitConfig struct {
URL string `required:"" help:"URL to the Git repository containing the app source. Both HTTPS and SSH formats are supported."`
SubPath string `help:"SubPath is a path in the git repo which contains the app code. If not given, the root directory of the git repo will be used."`
Revision string `default:"main" help:"Revision defines the revision of the source to deploy the app to. This can be a commit, tag or branch."`
URL string `required:"" help:"URL to the Git repository containing the application source. Both HTTPS and SSH formats are supported."`
SubPath string `help:"SubPath is a path in the git repository which contains the application code. If not given, the root directory of the git repository will be used."`
Revision string `default:"main" help:"Revision defines the revision of the source to deploy the application to. This can be a commit, tag or branch."`
Username *string `help:"Username to use when authenticating to the git repository over HTTPS." env:"GIT_USERNAME"`
Password *string `help:"Password to use when authenticating to the git repository over HTTPS. In case of GitHub or GitLab, this can also be an access token." env:"GIT_PASSWORD"`
SSHPrivateKey *string `help:"Private key in PEM format to connect to the git repository via SSH." env:"GIT_SSH_PRIVATE_KEY" xor:"SSH_KEY"`
Expand All @@ -74,9 +74,9 @@ type deployJob struct {
}

type workerJob struct {
Command string `help:"Command to execute to start the worker." placeholder:"\"bundle exec sidekiq\""`
Command string `help:"Command to execute to start the worker job." placeholder:"\"bundle exec sidekiq\""`
Name string `help:"Name of the worker job to add." placeholder:"worker-1"`
Size *string `help:"Size of the worker (defaults to \"${app_default_size}\")." placeholder:"${app_default_size}"`
Size *string `help:"Size of the worker job (defaults to \"${app_default_size}\")." placeholder:"${app_default_size}"`
}

type scheduledJob struct {
Expand All @@ -89,9 +89,9 @@ type scheduledJob struct {
}

type dockerfileBuild struct {
Enabled bool `name:"dockerfile" help:"${app_dockerfile_enable_help}" default:"false"`
Path string `name:"dockerfile-path" help:"${app_dockerfile_path_help}" default:""`
BuildContext string `name:"dockerfile-build-context" help:"${app_dockerfile_build_context_help}" default:""`
Enabled bool `name:"dockerfile" help:"${app_dockerfile_enable_help}." default:"false"`
Path string `name:"dockerfile-path" help:"${app_dockerfile_path_help}." default:""`
BuildContext string `name:"dockerfile-build-context" help:"${app_dockerfile_build_context_help}." default:""`
}

func (g gitConfig) sshPrivateKey() (*string, error) {
Expand Down
4 changes: 2 additions & 2 deletions create/bucketuser.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

type bucketUserCmd struct {
resourceCmd
Location string `placeholder:"${bucketuser_location_default}" help:"Location where the BucketUser instance is created. Available locations are: ${bucketuser_location_options}"`
Location meta.LocationName `placeholder:"${bucketuser_location_default}" help:"Where the BucketUser instance is created. Available locations are: ${bucketuser_location_options}"`
}

func (cmd *bucketUserCmd) Run(ctx context.Context, client *api.Client) error {
Expand Down Expand Up @@ -64,7 +64,7 @@ func (cmd *bucketUserCmd) newBucketUser(namespace string) *storage.BucketUser {
},
},
ForProvider: storage.BucketUserParameters{
Location: meta.LocationName(cmd.Location),
Location: cmd.Location,
},
},
}
Expand Down
Loading