@robinmordasiewicz/f5xc-auth 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +153 -0
  3. package/dist/auth/credential-manager.d.ts +177 -0
  4. package/dist/auth/credential-manager.d.ts.map +1 -0
  5. package/dist/auth/credential-manager.js +417 -0
  6. package/dist/auth/credential-manager.js.map +1 -0
  7. package/dist/auth/http-client.d.ts +86 -0
  8. package/dist/auth/http-client.d.ts.map +1 -0
  9. package/dist/auth/http-client.js +255 -0
  10. package/dist/auth/http-client.js.map +1 -0
  11. package/dist/auth/index.d.ts +6 -0
  12. package/dist/auth/index.d.ts.map +1 -0
  13. package/dist/auth/index.js +6 -0
  14. package/dist/auth/index.js.map +1 -0
  15. package/dist/config/index.d.ts +5 -0
  16. package/dist/config/index.d.ts.map +1 -0
  17. package/dist/config/index.js +5 -0
  18. package/dist/config/index.js.map +1 -0
  19. package/dist/config/paths.d.ts +36 -0
  20. package/dist/config/paths.d.ts.map +1 -0
  21. package/dist/config/paths.js +68 -0
  22. package/dist/config/paths.js.map +1 -0
  23. package/dist/index.d.ts +30 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +34 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/profile/index.d.ts +6 -0
  28. package/dist/profile/index.d.ts.map +1 -0
  29. package/dist/profile/index.js +6 -0
  30. package/dist/profile/index.js.map +1 -0
  31. package/dist/profile/manager.d.ts +74 -0
  32. package/dist/profile/manager.d.ts.map +1 -0
  33. package/dist/profile/manager.js +326 -0
  34. package/dist/profile/manager.js.map +1 -0
  35. package/dist/profile/types.d.ts +53 -0
  36. package/dist/profile/types.d.ts.map +1 -0
  37. package/dist/profile/types.js +7 -0
  38. package/dist/profile/types.js.map +1 -0
  39. package/dist/utils/errors.d.ts +66 -0
  40. package/dist/utils/errors.d.ts.map +1 -0
  41. package/dist/utils/errors.js +179 -0
  42. package/dist/utils/errors.js.map +1 -0
  43. package/dist/utils/index.d.ts +6 -0
  44. package/dist/utils/index.d.ts.map +1 -0
  45. package/dist/utils/index.js +6 -0
  46. package/dist/utils/index.js.map +1 -0
  47. package/dist/utils/logging.d.ts +75 -0
  48. package/dist/utils/logging.d.ts.map +1 -0
  49. package/dist/utils/logging.js +131 -0
  50. package/dist/utils/logging.js.map +1 -0
  51. package/package.json +54 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Robin Mordasiewicz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,153 @@
1
+ # @robinmordasiewicz/f5xc-auth
2
+
3
+ Shared authentication library for F5 Distributed Cloud MCP servers. Provides XDG-compliant profile management and credential handling.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @robinmordasiewicz/f5xc-auth
9
+ ```
10
+
11
+ ## Features
12
+
13
+ - **XDG-compliant profile storage** - Profiles stored in `~/.config/f5xc/profiles/`
14
+ - **Multiple authentication methods** - API token, P12 certificate, or cert/key pair
15
+ - **Environment variable priority** - Override profile settings with environment variables
16
+ - **URL normalization** - Handles various F5XC tenant URL formats
17
+ - **TLS configuration** - Custom CA bundles and insecure mode for staging
18
+
19
+ ## Usage
20
+
21
+ ### Basic Authentication
22
+
23
+ ```typescript
24
+ import { CredentialManager } from '@robinmordasiewicz/f5xc-auth';
25
+
26
+ const credentialManager = new CredentialManager();
27
+ await credentialManager.initialize();
28
+
29
+ if (credentialManager.isAuthenticated()) {
30
+ console.log(`Authenticated as: ${credentialManager.getTenant()}`);
31
+ console.log(`API URL: ${credentialManager.getApiUrl()}`);
32
+ console.log(`Namespace: ${credentialManager.getNamespace()}`);
33
+ }
34
+ ```
35
+
36
+ ### Profile Management
37
+
38
+ ```typescript
39
+ import { getProfileManager } from '@robinmordasiewicz/f5xc-auth';
40
+
41
+ const profileManager = getProfileManager();
42
+
43
+ // List all profiles
44
+ const profiles = await profileManager.list();
45
+
46
+ // Get active profile
47
+ const active = await profileManager.getActiveProfile();
48
+
49
+ // Save a new profile
50
+ await profileManager.save({
51
+ name: 'production',
52
+ apiUrl: 'https://mytenant.console.ves.volterra.io',
53
+ apiToken: 'my-api-token',
54
+ defaultNamespace: 'my-namespace'
55
+ });
56
+
57
+ // Switch profiles
58
+ await profileManager.setActive('production');
59
+ ```
60
+
61
+ ### HTTP Client
62
+
63
+ ```typescript
64
+ import { CredentialManager, createHttpClient } from '@robinmordasiewicz/f5xc-auth';
65
+
66
+ const credentialManager = new CredentialManager();
67
+ await credentialManager.initialize();
68
+
69
+ const httpClient = createHttpClient(credentialManager, {
70
+ timeout: 30000,
71
+ debug: true
72
+ });
73
+
74
+ if (httpClient.isAvailable()) {
75
+ const response = await httpClient.get('/web/namespaces');
76
+ console.log(response.data);
77
+ }
78
+ ```
79
+
80
+ ## Environment Variables
81
+
82
+ | Variable | Description |
83
+ |----------|-------------|
84
+ | `F5XC_API_URL` | F5 XC tenant URL |
85
+ | `F5XC_API_TOKEN` | API token for authentication |
86
+ | `F5XC_P12_BUNDLE` | Path to P12 certificate bundle |
87
+ | `F5XC_CERT` | Path to certificate file |
88
+ | `F5XC_KEY` | Path to private key file |
89
+ | `F5XC_NAMESPACE` | Default namespace |
90
+ | `F5XC_TLS_INSECURE` | Disable TLS verification (staging only) |
91
+ | `F5XC_CA_BUNDLE` | Path to custom CA bundle |
92
+
93
+ Environment variables take priority over profile settings.
94
+
95
+ ## Credential Priority
96
+
97
+ 1. **Environment variables** (highest priority)
98
+ 2. **Active profile** from `~/.config/f5xc/`
99
+ 3. **Documentation mode** (no credentials - lowest priority)
100
+
101
+ ## Profile Format
102
+
103
+ Profiles are stored as JSON files in `~/.config/f5xc/profiles/`:
104
+
105
+ ```json
106
+ {
107
+ "name": "production",
108
+ "apiUrl": "https://mytenant.console.ves.volterra.io",
109
+ "apiToken": "your-api-token",
110
+ "defaultNamespace": "my-namespace"
111
+ }
112
+ ```
113
+
114
+ ### Authentication Methods
115
+
116
+ **API Token:**
117
+ ```json
118
+ {
119
+ "name": "token-auth",
120
+ "apiUrl": "https://mytenant.console.ves.volterra.io",
121
+ "apiToken": "your-api-token"
122
+ }
123
+ ```
124
+
125
+ **P12 Certificate:**
126
+ ```json
127
+ {
128
+ "name": "p12-auth",
129
+ "apiUrl": "https://mytenant.console.ves.volterra.io",
130
+ "p12Bundle": "/path/to/certificate.p12"
131
+ }
132
+ ```
133
+
134
+ **Cert + Key:**
135
+ ```json
136
+ {
137
+ "name": "cert-auth",
138
+ "apiUrl": "https://mytenant.console.ves.volterra.io",
139
+ "cert": "/path/to/certificate.pem",
140
+ "key": "/path/to/private-key.pem"
141
+ }
142
+ ```
143
+
144
+ ## Security
145
+
146
+ - Profile files are created with `0o600` permissions (owner read/write only)
147
+ - Config directory uses `0o700` permissions
148
+ - Tokens are masked when displayed (showing only last 4 characters)
149
+ - TLS insecure mode requires explicit opt-in
150
+
151
+ ## License
152
+
153
+ MIT
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Credential Manager for F5 Distributed Cloud API
3
+ *
4
+ * Handles authentication configuration and URL normalization.
5
+ * Supports dual-mode operation:
6
+ * - Documentation mode: No credentials required
7
+ * - Execution mode: API token or P12/Certificate authentication
8
+ *
9
+ * Uses XDG-compliant profile storage at ~/.config/f5xc/
10
+ */
11
+ /**
12
+ * Authentication modes supported by the server
13
+ */
14
+ export declare enum AuthMode {
15
+ /** No authentication - documentation mode only */
16
+ NONE = "none",
17
+ /** API token authentication */
18
+ TOKEN = "token",
19
+ /** P12 certificate authentication (mTLS) */
20
+ CERTIFICATE = "certificate"
21
+ }
22
+ /**
23
+ * Environment variable names for authentication
24
+ * These take priority over profile settings
25
+ */
26
+ export declare const AUTH_ENV_VARS: {
27
+ readonly API_URL: "F5XC_API_URL";
28
+ readonly API_TOKEN: "F5XC_API_TOKEN";
29
+ readonly P12_BUNDLE: "F5XC_P12_BUNDLE";
30
+ readonly CERT: "F5XC_CERT";
31
+ readonly KEY: "F5XC_KEY";
32
+ readonly NAMESPACE: "F5XC_NAMESPACE";
33
+ readonly TLS_INSECURE: "F5XC_TLS_INSECURE";
34
+ readonly CA_BUNDLE: "F5XC_CA_BUNDLE";
35
+ };
36
+ /**
37
+ * Credential configuration for API access
38
+ */
39
+ export interface Credentials {
40
+ /** Authentication mode */
41
+ mode: AuthMode;
42
+ /** Normalized API URL */
43
+ apiUrl: string | null;
44
+ /** API token (for token auth) */
45
+ token: string | null;
46
+ /** P12 certificate buffer (for cert auth) */
47
+ p12Certificate: Buffer | null;
48
+ /** Certificate content (for mTLS) */
49
+ cert: string | null;
50
+ /** Private key content (for mTLS) */
51
+ key: string | null;
52
+ /** Default namespace */
53
+ namespace: string | null;
54
+ /** Disable TLS certificate verification (staging/development only) */
55
+ tlsInsecure: boolean;
56
+ /** Custom CA bundle for TLS verification */
57
+ caBundle: Buffer | null;
58
+ }
59
+ /**
60
+ * Normalize F5XC tenant URL to standard API endpoint format
61
+ *
62
+ * Handles various input formats:
63
+ * - tenant.volterra.us -> tenant.console.ves.volterra.io/api (production)
64
+ * - tenant.staging.volterra.us -> tenant.staging.volterra.us/api (staging - keep as-is)
65
+ * - tenant.console.ves.volterra.io -> tenant.console.ves.volterra.io/api
66
+ * - Any of the above with trailing slashes or /api suffix
67
+ *
68
+ * @param input - Raw URL from user configuration
69
+ * @returns Normalized API URL
70
+ */
71
+ export declare function normalizeApiUrl(input: string): string;
72
+ /**
73
+ * Extract tenant name from a normalized URL
74
+ *
75
+ * @param url - Normalized API URL
76
+ * @returns Tenant name or null if not parseable
77
+ */
78
+ export declare function extractTenantFromUrl(url: string): string | null;
79
+ /**
80
+ * Credential Manager
81
+ *
82
+ * Manages authentication credentials for F5 Distributed Cloud API.
83
+ * Supports credential loading with priority:
84
+ * 1. Environment variables (highest priority - overrides all)
85
+ * 2. Active profile from ~/.config/f5xc/ (XDG Base Directory compliant)
86
+ * 3. No credentials (documentation mode - lowest priority)
87
+ */
88
+ export declare class CredentialManager {
89
+ private credentials;
90
+ private activeProfileName;
91
+ private initialized;
92
+ constructor();
93
+ /**
94
+ * Initialize credentials asynchronously
95
+ * Must be called before using credentials
96
+ */
97
+ initialize(): Promise<void>;
98
+ /**
99
+ * Load credentials from environment variables
100
+ */
101
+ private loadFromEnvironment;
102
+ /**
103
+ * Load credentials from active profile
104
+ */
105
+ private loadFromProfile;
106
+ /**
107
+ * Build credentials object from profile data
108
+ */
109
+ private buildCredentials;
110
+ /**
111
+ * Load credentials with priority order:
112
+ * 1. Environment variables (highest)
113
+ * 2. Active profile from ~/.config/f5xc/
114
+ * 3. No credentials - documentation mode (lowest)
115
+ */
116
+ private loadCredentials;
117
+ /**
118
+ * Get the active profile name (if any)
119
+ * Returns null if credentials are from environment variables or no profile is active
120
+ */
121
+ getActiveProfile(): string | null;
122
+ /**
123
+ * Get the current authentication mode
124
+ */
125
+ getAuthMode(): AuthMode;
126
+ /**
127
+ * Check if the server is in authenticated mode
128
+ */
129
+ isAuthenticated(): boolean;
130
+ /**
131
+ * Get the normalized API URL
132
+ */
133
+ getApiUrl(): string | null;
134
+ /**
135
+ * Get the tenant name
136
+ */
137
+ getTenant(): string | null;
138
+ /**
139
+ * Get API token (for token authentication)
140
+ */
141
+ getToken(): string | null;
142
+ /**
143
+ * Get P12 certificate buffer (for certificate authentication)
144
+ */
145
+ getP12Certificate(): Buffer | null;
146
+ /**
147
+ * Get certificate content (for mTLS)
148
+ */
149
+ getCert(): string | null;
150
+ /**
151
+ * Get private key content (for mTLS)
152
+ */
153
+ getKey(): string | null;
154
+ /**
155
+ * Get default namespace
156
+ */
157
+ getNamespace(): string | null;
158
+ /**
159
+ * Check if TLS certificate verification is disabled
160
+ * WARNING: Only use for staging/development environments
161
+ */
162
+ getTlsInsecure(): boolean;
163
+ /**
164
+ * Get custom CA bundle for TLS verification
165
+ */
166
+ getCaBundle(): Buffer | null;
167
+ /**
168
+ * Get full credentials object
169
+ */
170
+ getCredentials(): Readonly<Credentials>;
171
+ /**
172
+ * Reload credentials from environment/profile
173
+ * Useful for testing or when credentials change
174
+ */
175
+ reload(): Promise<void>;
176
+ }
177
+ //# sourceMappingURL=credential-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential-manager.d.ts","sourceRoot":"","sources":["../../src/auth/credential-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH;;GAEG;AACH,oBAAY,QAAQ;IAClB,kDAAkD;IAClD,IAAI,SAAS;IACb,+BAA+B;IAC/B,KAAK,UAAU;IACf,4CAA4C;IAC5C,WAAW,gBAAgB;CAC5B;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa;;;;;;;;;CAUhB,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,0BAA0B;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,yBAAyB;IACzB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,iCAAi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